diff --git a/libs/jsonschema/extension.go b/libs/jsonschema/extension.go index ffb77bd834..9127a0d61b 100644 --- a/libs/jsonschema/extension.go +++ b/libs/jsonschema/extension.go @@ -26,4 +26,8 @@ type Extension struct { // If the CLI version is less than this value, then validation for this // schema will fail. MinDatabricksCliVersion string `json:"min_databricks_cli_version,omitempty"` + + // Version of the schema. This is used to determine if the schema is + // compatible with the current CLI version. + Version *int `json:"version,omitempty"` } diff --git a/libs/template/config.go b/libs/template/config.go index 51283e035f..508e773678 100644 --- a/libs/template/config.go +++ b/libs/template/config.go @@ -9,6 +9,9 @@ import ( "golang.org/x/exp/maps" ) +// The latest template schema version supported by the CLI +const latestSchemaVersion = 1 + type config struct { ctx context.Context values map[string]any @@ -49,6 +52,9 @@ func validateSchema(schema *jsonschema.Schema) error { return fmt.Errorf("property type %s is not supported by bundle templates", v.Type) } } + if schema.Version != nil && *schema.Version > latestSchemaVersion { + return fmt.Errorf("template schema version %d is not supported by this version of the CLI. Please upgrade your CLI to the latest version", *schema.Version) + } return nil } diff --git a/libs/template/config_test.go b/libs/template/config_test.go index 69e7054fec..d76952dc84 100644 --- a/libs/template/config_test.go +++ b/libs/template/config_test.go @@ -2,6 +2,7 @@ package template import ( "context" + "fmt" "testing" "github.com/databricks/cli/cmd/root" @@ -150,6 +151,40 @@ func TestTemplateValidateSchema(t *testing.T) { assert.EqualError(t, err, "property type array is not supported by bundle templates") } +func TestTemplateValidateSchemaVersion(t *testing.T) { + version := latestSchemaVersion + schema := jsonschema.Schema{ + Extension: jsonschema.Extension{ + Version: &version, + }, + } + assert.NoError(t, validateSchema(&schema)) + + version = latestSchemaVersion + 1 + schema = jsonschema.Schema{ + Extension: jsonschema.Extension{ + Version: &version, + }, + } + assert.EqualError(t, validateSchema(&schema), fmt.Sprintf("template schema version %d is not supported by this version of the CLI. Please upgrade your CLI to the latest version", version)) + + version = 5000 + schema = jsonschema.Schema{ + Extension: jsonschema.Extension{ + Version: &version, + }, + } + assert.EqualError(t, validateSchema(&schema), "template schema version 5000 is not supported by this version of the CLI. Please upgrade your CLI to the latest version") + + version = 0 + schema = jsonschema.Schema{ + Extension: jsonschema.Extension{ + Version: &version, + }, + } + assert.NoError(t, validateSchema(&schema)) +} + func TestTemplateEnumValidation(t *testing.T) { schema := jsonschema.Schema{ Properties: map[string]*jsonschema.Schema{