From 93f46bc19eba408e28269f76b1f80231a1610ab5 Mon Sep 17 00:00:00 2001 From: Shreyas Goenka Date: Thu, 27 Jun 2024 15:54:08 +0200 Subject: [PATCH 1/2] Remove schema override for variable default value --- cmd/bundle/schema.go | 56 -------------------------------------------- 1 file changed, 56 deletions(-) diff --git a/cmd/bundle/schema.go b/cmd/bundle/schema.go index b0d6b3dd52..0f27142bd5 100644 --- a/cmd/bundle/schema.go +++ b/cmd/bundle/schema.go @@ -7,58 +7,9 @@ import ( "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" ) -func overrideVariables(s *jsonschema.Schema) error { - // Override schema for default values to allow for multiple primitive types. - // These are normalized to strings when converted to the typed representation. - err := s.SetByPath("variables.*.default", jsonschema.Schema{ - AnyOf: []*jsonschema.Schema{ - { - Type: jsonschema.StringType, - }, - { - Type: jsonschema.BooleanType, - }, - { - Type: jsonschema.NumberType, - }, - { - Type: jsonschema.IntegerType, - }, - }, - }) - if err != nil { - return err - } - - // Override schema for variables in targets to allow just specifying the value - // along side overriding the variable definition if needed. - ns, err := s.GetByPath("variables.*") - if err != nil { - return err - } - return s.SetByPath("targets.*.variables.*", jsonschema.Schema{ - AnyOf: []*jsonschema.Schema{ - { - Type: jsonschema.StringType, - }, - { - Type: jsonschema.BooleanType, - }, - { - Type: jsonschema.NumberType, - }, - { - Type: jsonschema.IntegerType, - }, - &ns, - }, - }) -} - func newSchemaCommand() *cobra.Command { cmd := &cobra.Command{ Use: "schema", @@ -79,13 +30,6 @@ func newSchemaCommand() *cobra.Command { return err } - // Override schema for variables to take into account normalization of default - // variable values and variable overrides in a target. - err = overrideVariables(schema) - if err != nil { - return err - } - // Print the JSON schema to stdout. result, err := json.MarshalIndent(schema, "", " ") if err != nil { From e638f17e028b86c6b5ca188da46966a650ffeb35 Mon Sep 17 00:00:00 2001 From: Shreyas Goenka Date: Fri, 5 Jul 2024 10:56:36 +0200 Subject: [PATCH 2/2] handle variable overrids --- cmd/bundle/schema.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/cmd/bundle/schema.go b/cmd/bundle/schema.go index 0f27142bd5..813aebbae3 100644 --- a/cmd/bundle/schema.go +++ b/cmd/bundle/schema.go @@ -7,6 +7,7 @@ import ( "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" ) @@ -30,6 +31,13 @@ func newSchemaCommand() *cobra.Command { 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 {