From 1da04a43182c038ff9f4c1da87e5dd2a27025e38 Mon Sep 17 00:00:00 2001 From: shreyas-goenka <88374338+shreyas-goenka@users.noreply.github.com> Date: Wed, 10 Jul 2024 12:27:27 +0530 Subject: [PATCH] Remove schema override for variable default value (#1536) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Changes This PR: 1. Removes the custom added in https://github.com/databricks/cli/pull/1396/files for `variables.*.default`. It's no longer needed because with complex variables (https://github.com/databricks/cli/pull/1467) `default` has a type of any. 2. Retains, and extends the override on `targets.*.variables.*`. Target override values can now be complex objects, not just primitive values. ## Tests Manually Before: Only primitive types were allowed. Screenshot 2024-06-27 at 3 58 34 PM After: An empty JSON schema is generated. All YAML values are acceptable. Screenshot 2024-06-27 at 3 57 15 PM --- cmd/bundle/schema.go | 54 +++----------------------------------------- 1 file changed, 3 insertions(+), 51 deletions(-) diff --git a/cmd/bundle/schema.go b/cmd/bundle/schema.go index b0d6b3dd..813aebba 100644 --- a/cmd/bundle/schema.go +++ b/cmd/bundle/schema.go @@ -11,54 +11,6 @@ import ( "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,9 +31,9 @@ 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) + // 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 }