mirror of https://github.com/databricks/cli.git
feat: Use OneOf in interpolation patterns
This commit is contained in:
parent
d3b30f73ec
commit
43c4b581d4
|
@ -44,7 +44,8 @@ func addInterpolationPatterns(typ reflect.Type, s jsonschema.Schema) jsonschema.
|
||||||
case jsonschema.ArrayType, jsonschema.ObjectType:
|
case jsonschema.ArrayType, jsonschema.ObjectType:
|
||||||
// arrays and objects can have complex variable values specified.
|
// arrays and objects can have complex variable values specified.
|
||||||
return jsonschema.Schema{
|
return jsonschema.Schema{
|
||||||
AnyOf: []jsonschema.Schema{
|
// OneOf is used because we don't expect more than 1 match and schema-based auto-complete works better with OneOf
|
||||||
|
OneOf: []jsonschema.Schema{
|
||||||
s,
|
s,
|
||||||
{
|
{
|
||||||
Type: jsonschema.StringType,
|
Type: jsonschema.StringType,
|
||||||
|
@ -55,7 +56,7 @@ func addInterpolationPatterns(typ reflect.Type, s jsonschema.Schema) jsonschema.
|
||||||
// primitives can have variable values, or references like ${bundle.xyz}
|
// primitives can have variable values, or references like ${bundle.xyz}
|
||||||
// or ${workspace.xyz}
|
// or ${workspace.xyz}
|
||||||
return jsonschema.Schema{
|
return jsonschema.Schema{
|
||||||
AnyOf: []jsonschema.Schema{
|
OneOf: []jsonschema.Schema{
|
||||||
s,
|
s,
|
||||||
{Type: jsonschema.StringType, Pattern: interpolationPattern("resources")},
|
{Type: jsonschema.StringType, Pattern: interpolationPattern("resources")},
|
||||||
{Type: jsonschema.StringType, Pattern: interpolationPattern("bundle")},
|
{Type: jsonschema.StringType, Pattern: interpolationPattern("bundle")},
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
targets:
|
||||||
|
production:
|
||||||
|
variables:
|
||||||
|
myvar:
|
||||||
|
default: true
|
|
@ -41,32 +41,32 @@ func TestJsonSchema(t *testing.T) {
|
||||||
resourceJob := walk(s.Definitions, "github.com", "databricks", "cli", "bundle", "config", "resources.Job")
|
resourceJob := walk(s.Definitions, "github.com", "databricks", "cli", "bundle", "config", "resources.Job")
|
||||||
fields := []string{"name", "continuous", "tasks", "trigger"}
|
fields := []string{"name", "continuous", "tasks", "trigger"}
|
||||||
for _, field := range fields {
|
for _, field := range fields {
|
||||||
assert.NotEmpty(t, resourceJob.AnyOf[0].Properties[field].Description)
|
assert.NotEmpty(t, resourceJob.OneOf[0].Properties[field].Description)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Assert descriptions were also loaded for a job task definition.
|
// Assert descriptions were also loaded for a job task definition.
|
||||||
jobTask := walk(s.Definitions, "github.com", "databricks", "databricks-sdk-go", "service", "jobs.Task")
|
jobTask := walk(s.Definitions, "github.com", "databricks", "databricks-sdk-go", "service", "jobs.Task")
|
||||||
fields = []string{"notebook_task", "spark_jar_task", "spark_python_task", "spark_submit_task", "description", "depends_on", "environment_key", "for_each_task", "existing_cluster_id"}
|
fields = []string{"notebook_task", "spark_jar_task", "spark_python_task", "spark_submit_task", "description", "depends_on", "environment_key", "for_each_task", "existing_cluster_id"}
|
||||||
for _, field := range fields {
|
for _, field := range fields {
|
||||||
assert.NotEmpty(t, jobTask.AnyOf[0].Properties[field].Description)
|
assert.NotEmpty(t, jobTask.OneOf[0].Properties[field].Description)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Assert descriptions are loaded for pipelines
|
// Assert descriptions are loaded for pipelines
|
||||||
pipeline := walk(s.Definitions, "github.com", "databricks", "cli", "bundle", "config", "resources.Pipeline")
|
pipeline := walk(s.Definitions, "github.com", "databricks", "cli", "bundle", "config", "resources.Pipeline")
|
||||||
fields = []string{"name", "catalog", "clusters", "channel", "continuous", "development"}
|
fields = []string{"name", "catalog", "clusters", "channel", "continuous", "development"}
|
||||||
for _, field := range fields {
|
for _, field := range fields {
|
||||||
assert.NotEmpty(t, pipeline.AnyOf[0].Properties[field].Description)
|
assert.NotEmpty(t, pipeline.OneOf[0].Properties[field].Description)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Assert enum values are loaded
|
// Assert enum values are loaded
|
||||||
schedule := walk(s.Definitions, "github.com", "databricks", "databricks-sdk-go", "service", "pipelines.RestartWindow")
|
schedule := walk(s.Definitions, "github.com", "databricks", "databricks-sdk-go", "service", "pipelines.RestartWindow")
|
||||||
assert.Contains(t, schedule.AnyOf[0].Properties["days_of_week"].Enum, "MONDAY")
|
assert.Contains(t, schedule.OneOf[0].Properties["days_of_week"].Enum, "MONDAY")
|
||||||
assert.Contains(t, schedule.AnyOf[0].Properties["days_of_week"].Enum, "TUESDAY")
|
assert.Contains(t, schedule.OneOf[0].Properties["days_of_week"].Enum, "TUESDAY")
|
||||||
assert.Contains(t, schedule.AnyOf[0].Properties["days_of_week"].Enum, "WEDNESDAY")
|
assert.Contains(t, schedule.OneOf[0].Properties["days_of_week"].Enum, "WEDNESDAY")
|
||||||
assert.Contains(t, schedule.AnyOf[0].Properties["days_of_week"].Enum, "THURSDAY")
|
assert.Contains(t, schedule.OneOf[0].Properties["days_of_week"].Enum, "THURSDAY")
|
||||||
assert.Contains(t, schedule.AnyOf[0].Properties["days_of_week"].Enum, "FRIDAY")
|
assert.Contains(t, schedule.OneOf[0].Properties["days_of_week"].Enum, "FRIDAY")
|
||||||
assert.Contains(t, schedule.AnyOf[0].Properties["days_of_week"].Enum, "SATURDAY")
|
assert.Contains(t, schedule.OneOf[0].Properties["days_of_week"].Enum, "SATURDAY")
|
||||||
assert.Contains(t, schedule.AnyOf[0].Properties["days_of_week"].Enum, "SUNDAY")
|
assert.Contains(t, schedule.OneOf[0].Properties["days_of_week"].Enum, "SUNDAY")
|
||||||
|
|
||||||
providers := walk(s.Definitions, "github.com", "databricks", "databricks-sdk-go", "service", "jobs.GitProvider")
|
providers := walk(s.Definitions, "github.com", "databricks", "databricks-sdk-go", "service", "jobs.GitProvider")
|
||||||
assert.Contains(t, providers.Enum, "gitHub")
|
assert.Contains(t, providers.Enum, "gitHub")
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -70,6 +70,9 @@ type Schema struct {
|
||||||
// Schema that must match any of the schemas in the array
|
// Schema that must match any of the schemas in the array
|
||||||
AnyOf []Schema `json:"anyOf,omitempty"`
|
AnyOf []Schema `json:"anyOf,omitempty"`
|
||||||
|
|
||||||
|
// Schema that must match one of the schemas in the array
|
||||||
|
OneOf []Schema `json:"oneOf,omitempty"`
|
||||||
|
|
||||||
// Title of the object, rendered as inline documentation in the IDE.
|
// Title of the object, rendered as inline documentation in the IDE.
|
||||||
// https://json-schema.org/understanding-json-schema/reference/annotations
|
// https://json-schema.org/understanding-json-schema/reference/annotations
|
||||||
Title string `json:"title,omitempty"`
|
Title string `json:"title,omitempty"`
|
||||||
|
|
Loading…
Reference in New Issue