Remove schema override for variable default value (#1536)

## 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.

<img width="436" alt="Screenshot 2024-06-27 at 3 58 34 PM"
src="https://github.com/databricks/cli/assets/88374338/de55be5c-9236-4ccc-b529-97ce7201b8e8">

After:
An empty JSON schema is generated. All YAML values are acceptable.

<img width="453" alt="Screenshot 2024-06-27 at 3 57 15 PM"
src="https://github.com/databricks/cli/assets/88374338/7534b770-563f-4efc-b9c6-0af526dcc705">
This commit is contained in:
shreyas-goenka 2024-07-10 12:27:27 +05:30 committed by GitHub
parent 25737bbb5d
commit 1da04a4318
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 3 additions and 51 deletions

View File

@ -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
}