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 {
|
||||
case jsonschema.ArrayType, jsonschema.ObjectType:
|
||||
// arrays and objects can have complex variable values specified.
|
||||
|
|
|
@ -13,6 +13,8 @@ variables:
|
|||
simplevar:
|
||||
default: true
|
||||
description: "simplevar description"
|
||||
schedule_status:
|
||||
default: "PAUSED"
|
||||
|
||||
complexvar:
|
||||
default:
|
||||
|
@ -42,6 +44,8 @@ resources:
|
|||
dependencies:
|
||||
- python=3.7
|
||||
client: "myclient"
|
||||
trigger:
|
||||
pause_status: ${var.schedule_status}
|
||||
tags:
|
||||
foo: bar
|
||||
bar: baz
|
||||
|
|
|
@ -59,8 +59,8 @@ func TestJsonSchema(t *testing.T) {
|
|||
}
|
||||
|
||||
providers := walk(s.Definitions, "github.com", "databricks", "databricks-sdk-go", "service", "jobs.GitProvider")
|
||||
assert.Contains(t, providers.Enum, "gitHub")
|
||||
assert.Contains(t, providers.Enum, "bitbucketCloud")
|
||||
assert.Contains(t, providers.Enum, "gitHubEnterprise")
|
||||
assert.Contains(t, providers.Enum, "bitbucketServer")
|
||||
assert.Contains(t, providers.OneOf[0].Enum, "gitHub")
|
||||
assert.Contains(t, providers.OneOf[0].Enum, "bitbucketCloud")
|
||||
assert.Contains(t, providers.OneOf[0].Enum, "gitHubEnterprise")
|
||||
assert.Contains(t, providers.OneOf[0].Enum, "bitbucketServer")
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue