cleanu unused code

This commit is contained in:
Shreyas Goenka 2024-08-27 12:47:49 +02:00
parent d07192fe03
commit fcdccb359a
No known key found for this signature in database
GPG Key ID: 92A07DF49CCB0622
5 changed files with 26 additions and 130 deletions

View File

@ -52,7 +52,8 @@ func addInterpolationPatterns(_ reflect.Type, s jsonschema.Schema) jsonschema.Sc
// as well. Make sure to pull those in.
// TODO: Add unit tests for all permutations of structs, maps and slices for the FromType
// method.
// TODO: Note the minor regression of losing the bundle descriptions
// TODO: Note the minor regression of losing the bundle descriptions.
// TODO: Ensure descriptions work for target resources section.
func main() {
if len(os.Args) != 2 {

View File

@ -1,13 +1,7 @@
package bundle
import (
"encoding/json"
"reflect"
"github.com/databricks/cli/bundle/config"
"github.com/databricks/cli/bundle/schema"
"github.com/databricks/cli/cmd/root"
"github.com/databricks/cli/libs/jsonschema"
"github.com/spf13/cobra"
)
@ -19,31 +13,31 @@ func newSchemaCommand() *cobra.Command {
}
cmd.RunE = func(cmd *cobra.Command, args []string) error {
// Load embedded schema descriptions.
docs, err := schema.LoadBundleDescriptions()
if err != nil {
return err
}
// // Load embedded schema descriptions.
// docs, err := schema.LoadBundleDescriptions()
// if err != nil {
// return err
// }
// Generate the JSON schema from the bundle configuration struct in Go.
schema, err := schema.New(reflect.TypeOf(config.Root{}), docs)
if err != nil {
return err
}
// // Generate the JSON schema from the bundle configuration struct in Go.
// schema, err := schema.New(reflect.TypeOf(config.Root{}), docs)
// if err != nil {
// return err
// }
// Target variable value overrides can be primitives, maps or sequences.
// Set an empty schema for them.
err = schema.SetByPath("targets.*.variables.*", jsonschema.Schema{})
if err != nil {
return err
}
// // Target variable value overrides can be primitives, maps or sequences.
// // Set an empty schema for them.
// err = schema.SetByPath("targets.*.variables.*", jsonschema.Schema{})
// if err != nil {
// return err
// }
// Print the JSON schema to stdout.
result, err := json.MarshalIndent(schema, "", " ")
if err != nil {
return err
}
cmd.OutOrStdout().Write(result)
// // Print the JSON schema to stdout.
// result, err := json.MarshalIndent(schema, "", " ")
// if err != nil {
// return err
// }
// cmd.OutOrStdout().Write(result)
return nil
}

View File

@ -6,20 +6,12 @@ import (
"os"
"regexp"
"slices"
"strings"
"github.com/databricks/cli/internal/build"
"golang.org/x/mod/semver"
)
// defines schema for a json object
// TODO: Remove pointers from properties and AnyOf.
// TODO: Can / should we emulate dyn.V here in having a readonly model for the data
// structure? Makes it easier to reason about.
//
// Any performance issues can be addressed by storing the schema
//
// as an embedded file.
type Schema struct {
// TODO: Comments for this field
Definitions any `json:"$defs,omitempty"`
@ -38,6 +30,7 @@ type Schema struct {
// Schemas for the fields of an struct. The keys are the first json tag.
// The values are the schema for the type of the field
// TODO: Followup: Make this a map[string]Schema
Properties map[string]*Schema `json:"properties,omitempty"`
// The schema for all values of an array
@ -95,48 +88,12 @@ func (s *Schema) ParseString(v string) (any, error) {
return fromString(v, s.Type)
}
func (s *Schema) getByPath(path string) (*Schema, error) {
p := strings.Split(path, ".")
res := s
for _, node := range p {
if node == "*" {
res = res.AdditionalProperties.(*Schema)
continue
}
var ok bool
res, ok = res.Properties[node]
if !ok {
return nil, fmt.Errorf("property %q not found in schema. Query path: %s", node, path)
}
}
return res, nil
}
func (s *Schema) GetByPath(path string) (Schema, error) {
v, err := s.getByPath(path)
if err != nil {
return Schema{}, err
}
return *v, nil
}
func (s *Schema) SetByPath(path string, v Schema) error {
dst, err := s.getByPath(path)
if err != nil {
return err
}
*dst = v
return nil
}
type Type string
const (
// Default zero value of a schema. This does not correspond to a type in the
// JSON schema spec and is an internal type defined for convenience.
InvalidType Type = "invalid"
NullType Type = "null"
BooleanType Type = "boolean"
StringType Type = "string"
NumberType Type = "number"

View File

@ -4,7 +4,6 @@ import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestSchemaValidateTypeNames(t *testing.T) {
@ -340,58 +339,3 @@ func testSchema() *Schema {
}
}
func TestSchemaGetByPath(t *testing.T) {
s := testSchema()
ss, err := s.GetByPath("int_val")
require.NoError(t, err)
assert.Equal(t, Schema{
Type: IntegerType,
Default: int64(123),
}, ss)
ss, err = s.GetByPath("string_val")
require.NoError(t, err)
assert.Equal(t, Schema{
Type: StringType,
}, ss)
ss, err = s.GetByPath("object_val.bar")
require.NoError(t, err)
assert.Equal(t, Schema{
Type: StringType,
Default: "baz",
}, ss)
ss, err = s.GetByPath("object_val.*.foo")
require.NoError(t, err)
assert.Equal(t, Schema{
Type: StringType,
Default: "zab",
}, ss)
}
func TestSchemaSetByPath(t *testing.T) {
s := testSchema()
err := s.SetByPath("int_val", Schema{
Type: IntegerType,
Default: int64(456),
})
require.NoError(t, err)
assert.Equal(t, int64(456), s.Properties["int_val"].Default)
err = s.SetByPath("object_val.*.foo", Schema{
Type: StringType,
Default: "zooby",
})
require.NoError(t, err)
ns, err := s.GetByPath("object_val.*.foo")
require.NoError(t, err)
assert.Equal(t, Schema{
Type: StringType,
Default: "zooby",
}, ns)
}

View File

@ -461,7 +461,7 @@ func TestPromptIsSkippedAnyOf(t *testing.T) {
Default: "hello-world",
Extension: jsonschema.Extension{
SkipPromptIf: &jsonschema.Schema{
AnyOf: []*jsonschema.Schema{
AnyOf: []jsonschema.Schema{
{
Properties: map[string]*jsonschema.Schema{
"abc": {