From da19e139cc14f0ab4f3679ed8c8babb8b54c3885 Mon Sep 17 00:00:00 2001 From: monalisa Date: Fri, 4 Aug 2023 14:33:37 +0200 Subject: [PATCH 1/5] Add preview tag for fields that are in development --- bundle/config/environment.go | 3 ++- bundle/config/workspace.go | 2 +- bundle/schema/schema.go | 11 +++++++- bundle/schema/schema_test.go | 52 ++++++++++++++++++++++++++++++++++++ 4 files changed, 65 insertions(+), 3 deletions(-) diff --git a/bundle/config/environment.go b/bundle/config/environment.go index 7152f791f65..456be8d7e65 100644 --- a/bundle/config/environment.go +++ b/bundle/config/environment.go @@ -12,7 +12,8 @@ type Environment struct { // Determines the mode of the environment. // For example, 'mode: development' can be used for deployments for // development purposes. - Mode Mode `json:"mode,omitempty"` + // TODO: remove the todo tag once this field is operational + Mode Mode `json:"mode,omitempty" bundle:"preview"` // Overrides the compute used for jobs and other supported assets. ComputeID string `json:"compute_id,omitempty"` diff --git a/bundle/config/workspace.go b/bundle/config/workspace.go index f278ea17971..59ab9904ac5 100644 --- a/bundle/config/workspace.go +++ b/bundle/config/workspace.go @@ -23,7 +23,7 @@ type Workspace struct { // Generic attributes. Host string `json:"host,omitempty"` Profile string `json:"profile,omitempty"` - AuthType string `json:"auth_type,omitempty"` + AuthType string `json:"auth_type,omitempty" bundle:"preview"` MetadataServiceURL string `json:"metadata_service_url,omitempty"` // OAuth specific attributes. diff --git a/bundle/schema/schema.go b/bundle/schema/schema.go index fee9b676a4c..634decbc155 100644 --- a/bundle/schema/schema.go +++ b/bundle/schema/schema.go @@ -9,6 +9,15 @@ import ( "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" + +// Fields tagged "preview" are still under active development and should not +// be shown to users in the schema. This tag is meant to be temporary and +// should be removed once the field is ready to be used widely by customers. +const previewTag = "preview" + // This function translates golang types into json schema. Here is the mapping // between json schema types and golang types // @@ -197,7 +206,7 @@ func toSchema(golangType reflect.Type, docs *Docs, tracker *tracker) (*jsonschem required := []string{} for _, child := range children { bundleTag := child.Tag.Get("bundle") - if bundleTag == "readonly" { + if bundleTag == readonlyTag || bundleTag == previewTag { continue } diff --git a/bundle/schema/schema_test.go b/bundle/schema/schema_test.go index 66baf8736a6..db34216166f 100644 --- a/bundle/schema/schema_test.go +++ b/bundle/schema/schema_test.go @@ -1462,3 +1462,55 @@ func TestBundleReadOnlytag(t *testing.T) { t.Log("[DEBUG] expected: ", expected) assert.Equal(t, expected, string(jsonSchema)) } + +func TestBundlePreviewTag(t *testing.T) { + type Pokemon struct { + Pikachu string `json:"pikachu" bundle:"preview"` + Raichu string `json:"raichu"` + } + + type Foo struct { + Pokemon *Pokemon `json:"pokemon"` + Apple int `json:"apple"` + Mango string `json:"mango" bundle:"preview"` + } + + 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)) +} From 034fda193e7050d50ac5e3458abdc26bd8fa91cb Mon Sep 17 00:00:00 2001 From: monalisa Date: Fri, 4 Aug 2023 14:35:01 +0200 Subject: [PATCH 2/5] - --- bundle/config/environment.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundle/config/environment.go b/bundle/config/environment.go index 456be8d7e65..c15f9cdd54b 100644 --- a/bundle/config/environment.go +++ b/bundle/config/environment.go @@ -12,7 +12,7 @@ type Environment struct { // Determines the mode of the environment. // For example, 'mode: development' can be used for deployments for // development purposes. - // TODO: remove the todo tag once this field is operational + // TODO: remove the "preview" tag once this field is operational Mode Mode `json:"mode,omitempty" bundle:"preview"` // Overrides the compute used for jobs and other supported assets. From 5ee9d26bbda57a6043bfa6fba3063e4fae8a67e6 Mon Sep 17 00:00:00 2001 From: monalisa Date: Fri, 4 Aug 2023 14:35:35 +0200 Subject: [PATCH 3/5] - --- bundle/config/workspace.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundle/config/workspace.go b/bundle/config/workspace.go index 59ab9904ac5..f278ea17971 100644 --- a/bundle/config/workspace.go +++ b/bundle/config/workspace.go @@ -23,7 +23,7 @@ type Workspace struct { // Generic attributes. Host string `json:"host,omitempty"` Profile string `json:"profile,omitempty"` - AuthType string `json:"auth_type,omitempty" bundle:"preview"` + AuthType string `json:"auth_type,omitempty"` MetadataServiceURL string `json:"metadata_service_url,omitempty"` // OAuth specific attributes. From e5ecec4fa17e3842f1c1ae006d4afb9ca78dd4b7 Mon Sep 17 00:00:00 2001 From: monalisa Date: Fri, 4 Aug 2023 14:42:22 +0200 Subject: [PATCH 4/5] remove preview tag from mode --- bundle/config/environment.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/bundle/config/environment.go b/bundle/config/environment.go index c15f9cdd54b..7152f791f65 100644 --- a/bundle/config/environment.go +++ b/bundle/config/environment.go @@ -12,8 +12,7 @@ type Environment struct { // Determines the mode of the environment. // For example, 'mode: development' can be used for deployments for // development purposes. - // TODO: remove the "preview" tag once this field is operational - Mode Mode `json:"mode,omitempty" bundle:"preview"` + Mode Mode `json:"mode,omitempty"` // Overrides the compute used for jobs and other supported assets. ComputeID string `json:"compute_id,omitempty"` From 8727d495fb86bca35157f22eb7a4fab33325f13c Mon Sep 17 00:00:00 2001 From: monalisa Date: Mon, 7 Aug 2023 10:18:04 +0200 Subject: [PATCH 5/5] rename preview field to internal --- bundle/config/workspace.go | 2 +- bundle/schema/schema.go | 9 ++++----- bundle/schema/schema_test.go | 6 +++--- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/bundle/config/workspace.go b/bundle/config/workspace.go index f278ea17971..bd116a9cb0d 100644 --- a/bundle/config/workspace.go +++ b/bundle/config/workspace.go @@ -24,7 +24,7 @@ type Workspace struct { Host string `json:"host,omitempty"` Profile string `json:"profile,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. ClientID string `json:"client_id,omitempty"` diff --git a/bundle/schema/schema.go b/bundle/schema/schema.go index 634decbc155..00dd271928e 100644 --- a/bundle/schema/schema.go +++ b/bundle/schema/schema.go @@ -13,10 +13,9 @@ import ( // computed at runtime, and should not be assigned a value by the bundle author. const readonlyTag = "readonly" -// Fields tagged "preview" are still under active development and should not -// be shown to users in the schema. This tag is meant to be temporary and -// should be removed once the field is ready to be used widely by customers. -const previewTag = "preview" +// 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 // between json schema types and golang types @@ -206,7 +205,7 @@ func toSchema(golangType reflect.Type, docs *Docs, tracker *tracker) (*jsonschem required := []string{} for _, child := range children { bundleTag := child.Tag.Get("bundle") - if bundleTag == readonlyTag || bundleTag == previewTag { + if bundleTag == readonlyTag || bundleTag == internalTag { continue } diff --git a/bundle/schema/schema_test.go b/bundle/schema/schema_test.go index db34216166f..d44a2082ac9 100644 --- a/bundle/schema/schema_test.go +++ b/bundle/schema/schema_test.go @@ -1463,16 +1463,16 @@ func TestBundleReadOnlytag(t *testing.T) { assert.Equal(t, expected, string(jsonSchema)) } -func TestBundlePreviewTag(t *testing.T) { +func TestBundleInternalTag(t *testing.T) { type Pokemon struct { - Pikachu string `json:"pikachu" bundle:"preview"` + 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:"preview"` + Mango string `json:"mango" bundle:"internal"` } elem := Foo{}