mirror of https://github.com/databricks/cli.git
Add internal tag for bundle fields to be skipped from schema (#636)
## Changes This PR: 1. Introduces the "internal" tag to bundle configs that should not be visible to customers. 2. Annotates "metadata_service_url" as an internal field. ## Tests Unit tests.
This commit is contained in:
parent
2a58253d20
commit
6b615ccfb4
|
@ -24,7 +24,7 @@ type Workspace struct {
|
||||||
Host string `json:"host,omitempty"`
|
Host string `json:"host,omitempty"`
|
||||||
Profile string `json:"profile,omitempty"`
|
Profile string `json:"profile,omitempty"`
|
||||||
AuthType string `json:"auth_type,omitempty"`
|
AuthType string `json:"auth_type,omitempty"`
|
||||||
MetadataServiceURL string `json:"metadata_service_url,omitempty"`
|
MetadataServiceURL string `json:"metadata_service_url,omitempty" bundle:"internal"`
|
||||||
|
|
||||||
// OAuth specific attributes.
|
// OAuth specific attributes.
|
||||||
ClientID string `json:"client_id,omitempty"`
|
ClientID string `json:"client_id,omitempty"`
|
||||||
|
|
|
@ -9,6 +9,14 @@ import (
|
||||||
"github.com/databricks/cli/libs/jsonschema"
|
"github.com/databricks/cli/libs/jsonschema"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Fields tagged "readonly" should not be emitted in the schema as they are
|
||||||
|
// computed at runtime, and should not be assigned a value by the bundle author.
|
||||||
|
const readonlyTag = "readonly"
|
||||||
|
|
||||||
|
// Annotation for internal bundle fields that should not be exposed to customers.
|
||||||
|
// Fields can be tagged as "internal" to remove them from the generated schema.
|
||||||
|
const internalTag = "internal"
|
||||||
|
|
||||||
// This function translates golang types into json schema. Here is the mapping
|
// This function translates golang types into json schema. Here is the mapping
|
||||||
// between json schema types and golang types
|
// between json schema types and golang types
|
||||||
//
|
//
|
||||||
|
@ -197,7 +205,7 @@ func toSchema(golangType reflect.Type, docs *Docs, tracker *tracker) (*jsonschem
|
||||||
required := []string{}
|
required := []string{}
|
||||||
for _, child := range children {
|
for _, child := range children {
|
||||||
bundleTag := child.Tag.Get("bundle")
|
bundleTag := child.Tag.Get("bundle")
|
||||||
if bundleTag == "readonly" {
|
if bundleTag == readonlyTag || bundleTag == internalTag {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1462,3 +1462,55 @@ func TestBundleReadOnlytag(t *testing.T) {
|
||||||
t.Log("[DEBUG] expected: ", expected)
|
t.Log("[DEBUG] expected: ", expected)
|
||||||
assert.Equal(t, expected, string(jsonSchema))
|
assert.Equal(t, expected, string(jsonSchema))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestBundleInternalTag(t *testing.T) {
|
||||||
|
type Pokemon struct {
|
||||||
|
Pikachu string `json:"pikachu" bundle:"internal"`
|
||||||
|
Raichu string `json:"raichu"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Foo struct {
|
||||||
|
Pokemon *Pokemon `json:"pokemon"`
|
||||||
|
Apple int `json:"apple"`
|
||||||
|
Mango string `json:"mango" bundle:"internal"`
|
||||||
|
}
|
||||||
|
|
||||||
|
elem := Foo{}
|
||||||
|
|
||||||
|
schema, err := New(reflect.TypeOf(elem), nil)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
jsonSchema, err := json.MarshalIndent(schema, " ", " ")
|
||||||
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
expected :=
|
||||||
|
`{
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"apple": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"pokemon": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"raichu": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"additionalProperties": false,
|
||||||
|
"required": [
|
||||||
|
"raichu"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"additionalProperties": false,
|
||||||
|
"required": [
|
||||||
|
"pokemon",
|
||||||
|
"apple"
|
||||||
|
]
|
||||||
|
}`
|
||||||
|
|
||||||
|
t.Log("[DEBUG] actual: ", string(jsonSchema))
|
||||||
|
t.Log("[DEBUG] expected: ", expected)
|
||||||
|
assert.Equal(t, expected, string(jsonSchema))
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue