From ec328d3d06781136e29786fa9e7a29403a4c77d0 Mon Sep 17 00:00:00 2001 From: Shreyas Goenka Date: Thu, 5 Sep 2024 13:37:45 +0200 Subject: [PATCH] Address comments --- bundle/generated/jsonschema.json | 87 ++++++++++++++------------------ bundle/internal/schema/main.go | 28 ++++++---- 2 files changed, 55 insertions(+), 60 deletions(-) diff --git a/bundle/generated/jsonschema.json b/bundle/generated/jsonschema.json index a0173bb26f..3f1fa2efc8 100644 --- a/bundle/generated/jsonschema.json +++ b/bundle/generated/jsonschema.json @@ -634,6 +634,29 @@ } ] }, + "variable.TargetVariable": { + "anyOf": [ + { + "type": "object", + "properties": { + "default": { + "$ref": "#/$defs/interface" + }, + "description": { + "$ref": "#/$defs/string" + }, + "lookup": { + "$ref": "#/$defs/github.com/databricks/cli/bundle/config/variable.Lookup" + }, + "type": { + "$ref": "#/$defs/github.com/databricks/cli/bundle/config/variable.VariableType" + } + }, + "additionalProperties": false + }, + {} + ] + }, "variable.Variable": { "type": "object", "properties": { @@ -987,7 +1010,7 @@ "$ref": "#/$defs/github.com/databricks/cli/bundle/config.Sync" }, "variables": { - "$ref": "#/$defs/map/github.com/databricks/cli/bundle/config.TargetVariable" + "$ref": "#/$defs/map/github.com/databricks/cli/bundle/config/variable.TargetVariable" }, "workspace": { "$ref": "#/$defs/github.com/databricks/cli/bundle/config.Workspace" @@ -1001,40 +1024,6 @@ } ] }, - "config.TargetVariable": { - "anyOf": [ - { - "type": "object", - "properties": { - "default": { - "$ref": "#/$defs/interface" - }, - "description": { - "$ref": "#/$defs/string" - }, - "lookup": { - "$ref": "#/$defs/github.com/databricks/cli/bundle/config/variable.Lookup" - }, - "type": { - "$ref": "#/$defs/github.com/databricks/cli/bundle/config/variable.VariableType" - } - }, - "additionalProperties": false - }, - { - "type": "string" - }, - { - "type": "boolean" - }, - { - "type": "integer" - }, - { - "type": "number" - } - ] - }, "config.Workspace": { "anyOf": [ { @@ -5004,6 +4993,20 @@ } ] }, + "variable.TargetVariable": { + "anyOf": [ + { + "type": "object", + "additionalProperties": { + "$ref": "#/$defs/github.com/databricks/cli/bundle/config/variable.TargetVariable" + } + }, + { + "type": "string", + "pattern": "\\$\\{(var(\\.[a-zA-Z]+([-_]?[a-zA-Z0-9]+)*(\\[[0-9]+\\])*)*(\\[[0-9]+\\])*)\\}" + } + ] + }, "variable.Variable": { "anyOf": [ { @@ -5060,20 +5063,6 @@ "pattern": "\\$\\{(var(\\.[a-zA-Z]+([-_]?[a-zA-Z0-9]+)*(\\[[0-9]+\\])*)*(\\[[0-9]+\\])*)\\}" } ] - }, - "config.TargetVariable": { - "anyOf": [ - { - "type": "object", - "additionalProperties": { - "$ref": "#/$defs/github.com/databricks/cli/bundle/config.TargetVariable" - } - }, - { - "type": "string", - "pattern": "\\$\\{(var(\\.[a-zA-Z]+([-_]?[a-zA-Z0-9]+)*(\\[[0-9]+\\])*)*(\\[[0-9]+\\])*)\\}" - } - ] } } } diff --git a/bundle/internal/schema/main.go b/bundle/internal/schema/main.go index 46c9a87c46..62dc628006 100644 --- a/bundle/internal/schema/main.go +++ b/bundle/internal/schema/main.go @@ -22,14 +22,17 @@ func addInterpolationPatterns(typ reflect.Type, s jsonschema.Schema) jsonschema. } // The variables block in a target override allows for directly specifying - // the value if it is a primitive type. + // the value of the variable. if typ == reflect.TypeOf(variable.TargetVariable{}) { return jsonschema.Schema{ - AnyOf: []jsonschema.Schema{s, - {Type: jsonschema.StringType}, - {Type: jsonschema.BooleanType}, - {Type: jsonschema.IntegerType}, - {Type: jsonschema.NumberType}, + AnyOf: []jsonschema.Schema{ + // We keep the original schema so that autocomplete suggestions + // continue to work. + s, + // All values are valid for a variable value, be it primitive types + // like string/bool or complex ones like objects/arrays. Thus we override + // the schema to allow all valid JSON values. + {}, }, } } @@ -38,16 +41,19 @@ func addInterpolationPatterns(typ reflect.Type, s jsonschema.Schema) jsonschema. case jsonschema.ArrayType, jsonschema.ObjectType: // arrays and objects can have complex variable values specified. return jsonschema.Schema{ - AnyOf: []jsonschema.Schema{s, { - Type: jsonschema.StringType, - Pattern: interpolationPattern("var"), - }}, + AnyOf: []jsonschema.Schema{ + s, + { + Type: jsonschema.StringType, + Pattern: interpolationPattern("var"), + }}, } case jsonschema.IntegerType, jsonschema.NumberType, jsonschema.BooleanType: // primitives can have variable values, or references like ${bundle.xyz} // or ${workspace.xyz} return jsonschema.Schema{ - AnyOf: []jsonschema.Schema{s, + AnyOf: []jsonschema.Schema{ + s, {Type: jsonschema.StringType, Pattern: interpolationPattern("resources")}, {Type: jsonschema.StringType, Pattern: interpolationPattern("bundle")}, {Type: jsonschema.StringType, Pattern: interpolationPattern("workspace")},