mirror of https://github.com/databricks/cli.git
Allow using variables in enum fields (#2199)
## Changes It is possible to pass variable to enum fields but json-schema doesn't accept it. This PR adds `oneOf` for enum types that includes `${var-*}` pattern ## Tests Manually checked in VSCode
This commit is contained in:
parent
fde30ff1ab
commit
c224be5c1f
|
@ -40,6 +40,19 @@ func addInterpolationPatterns(typ reflect.Type, s jsonschema.Schema) jsonschema.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Allows using variables in enum fields
|
||||||
|
if s.Type == jsonschema.StringType && s.Enum != nil {
|
||||||
|
return jsonschema.Schema{
|
||||||
|
OneOf: []jsonschema.Schema{
|
||||||
|
s,
|
||||||
|
{
|
||||||
|
Type: jsonschema.StringType,
|
||||||
|
Pattern: interpolationPattern("var"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
switch s.Type {
|
switch s.Type {
|
||||||
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.
|
||||||
|
|
|
@ -13,6 +13,8 @@ variables:
|
||||||
simplevar:
|
simplevar:
|
||||||
default: true
|
default: true
|
||||||
description: "simplevar description"
|
description: "simplevar description"
|
||||||
|
schedule_status:
|
||||||
|
default: "PAUSED"
|
||||||
|
|
||||||
complexvar:
|
complexvar:
|
||||||
default:
|
default:
|
||||||
|
@ -42,6 +44,8 @@ resources:
|
||||||
dependencies:
|
dependencies:
|
||||||
- python=3.7
|
- python=3.7
|
||||||
client: "myclient"
|
client: "myclient"
|
||||||
|
trigger:
|
||||||
|
pause_status: ${var.schedule_status}
|
||||||
tags:
|
tags:
|
||||||
foo: bar
|
foo: bar
|
||||||
bar: baz
|
bar: baz
|
||||||
|
|
|
@ -59,8 +59,8 @@ func TestJsonSchema(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
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.OneOf[0].Enum, "gitHub")
|
||||||
assert.Contains(t, providers.Enum, "bitbucketCloud")
|
assert.Contains(t, providers.OneOf[0].Enum, "bitbucketCloud")
|
||||||
assert.Contains(t, providers.Enum, "gitHubEnterprise")
|
assert.Contains(t, providers.OneOf[0].Enum, "gitHubEnterprise")
|
||||||
assert.Contains(t, providers.Enum, "bitbucketServer")
|
assert.Contains(t, providers.OneOf[0].Enum, "bitbucketServer")
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue