mirror of https://github.com/databricks/cli.git
Add readonly bundle tag for internal fields (#302)
This PR adds a bundle: "readonly" struct tag to the json schema generator. This allows us to skip generating json schema for internal readonly fields Tested using unit test
This commit is contained in:
parent
ddbb17b0d9
commit
8de7d32ed1
|
@ -12,9 +12,9 @@ type NotebookArtifact struct {
|
|||
Path string `json:"path"`
|
||||
|
||||
// Language is detected during build step.
|
||||
Language workspace.Language `json:"language,omitempty"`
|
||||
Language workspace.Language `json:"language,omitempty" bundle:"readonly"`
|
||||
|
||||
// Paths are synthesized during build step.
|
||||
LocalPath string `json:"local_path,omitempty"`
|
||||
RemotePath string `json:"remote_path,omitempty"`
|
||||
LocalPath string `json:"local_path,omitempty" bundle:"readonly"`
|
||||
RemotePath string `json:"remote_path,omitempty" bundle:"readonly"`
|
||||
}
|
||||
|
|
|
@ -16,12 +16,12 @@ type Bundle struct {
|
|||
// DefaultWarehouse string `json:"default_warehouse,omitempty"`
|
||||
|
||||
// Environment is set by the mutator that selects the environment.
|
||||
Environment string `json:"environment,omitempty"`
|
||||
Environment string `json:"environment,omitempty" bundle:"readonly"`
|
||||
|
||||
// Terraform holds configuration related to Terraform.
|
||||
// For example, where to find the binary, which version to use, etc.
|
||||
Terraform *Terraform `json:"terraform,omitempty"`
|
||||
Terraform *Terraform `json:"terraform,omitempty" bundle:"readonly"`
|
||||
|
||||
// Lock configures locking behavior on deployment.
|
||||
Lock Lock `json:"lock"`
|
||||
Lock Lock `json:"lock" bundle:"readonly"`
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ package resources
|
|||
import "github.com/databricks/databricks-sdk-go/service/jobs"
|
||||
|
||||
type Job struct {
|
||||
ID string `json:"id,omitempty"`
|
||||
ID string `json:"id,omitempty" bundle:"readonly"`
|
||||
Permissions []Permission `json:"permissions,omitempty"`
|
||||
|
||||
*jobs.JobSettings
|
||||
|
|
|
@ -3,7 +3,7 @@ package resources
|
|||
import "github.com/databricks/databricks-sdk-go/service/pipelines"
|
||||
|
||||
type Pipeline struct {
|
||||
ID string `json:"id,omitempty"`
|
||||
ID string `json:"id,omitempty" bundle:"readonly"`
|
||||
Permissions []Permission `json:"permissions,omitempty"`
|
||||
|
||||
*pipelines.PipelineSpec
|
||||
|
|
|
@ -50,7 +50,7 @@ type Workspace struct {
|
|||
|
||||
// CurrentUser holds the current user.
|
||||
// This is set after configuration initialization.
|
||||
CurrentUser *scim.User `json:"current_user,omitempty"`
|
||||
CurrentUser *scim.User `json:"current_user,omitempty" bundle:"readonly"`
|
||||
|
||||
// Remote base path for deployment state, for artifacts, as synchronization target.
|
||||
// This defaults to "~/.bundle/${bundle.name}/${bundle.environment}" where "~" expands to
|
||||
|
|
|
@ -9,17 +9,8 @@
|
|||
"notebook": {
|
||||
"description": "",
|
||||
"properties": {
|
||||
"language": {
|
||||
"description": ""
|
||||
},
|
||||
"local_path": {
|
||||
"description": ""
|
||||
},
|
||||
"path": {
|
||||
"description": ""
|
||||
},
|
||||
"remote_path": {
|
||||
"description": ""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -29,30 +20,8 @@
|
|||
"bundle": {
|
||||
"description": "Bundle contains details about this bundle, such as its name,\nversion of the spec (TODO), default cluster, default warehouse, etc.\n",
|
||||
"properties": {
|
||||
"environment": {
|
||||
"description": "Environment is set by the mutator that selects the environment."
|
||||
},
|
||||
"lock": {
|
||||
"description": "",
|
||||
"properties": {
|
||||
"enabled": {
|
||||
"description": ""
|
||||
},
|
||||
"force": {
|
||||
"description": ""
|
||||
}
|
||||
}
|
||||
},
|
||||
"name": {
|
||||
"description": ""
|
||||
},
|
||||
"terraform": {
|
||||
"description": "",
|
||||
"properties": {
|
||||
"exec_path": {
|
||||
"description": ""
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -69,17 +38,8 @@
|
|||
"notebook": {
|
||||
"description": "",
|
||||
"properties": {
|
||||
"language": {
|
||||
"description": ""
|
||||
},
|
||||
"local_path": {
|
||||
"description": ""
|
||||
},
|
||||
"path": {
|
||||
"description": ""
|
||||
},
|
||||
"remote_path": {
|
||||
"description": ""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -89,30 +49,8 @@
|
|||
"bundle": {
|
||||
"description": "Bundle contains details about this bundle, such as its name,\nversion of the spec (TODO), default cluster, default warehouse, etc.\n",
|
||||
"properties": {
|
||||
"environment": {
|
||||
"description": "Environment is set by the mutator that selects the environment."
|
||||
},
|
||||
"lock": {
|
||||
"description": "",
|
||||
"properties": {
|
||||
"enabled": {
|
||||
"description": ""
|
||||
},
|
||||
"force": {
|
||||
"description": ""
|
||||
}
|
||||
}
|
||||
},
|
||||
"name": {
|
||||
"description": ""
|
||||
},
|
||||
"terraform": {
|
||||
"description": "",
|
||||
"properties": {
|
||||
"exec_path": {
|
||||
"description": ""
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -252,9 +190,6 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"id": {
|
||||
"description": ""
|
||||
},
|
||||
"job_clusters": {
|
||||
"description": "A list of job cluster specifications that can be shared and reused by tasks of this job. Libraries cannot be declared in a shared job cluster. You must declare dependent libraries in task settings.",
|
||||
"items": {
|
||||
|
@ -1581,129 +1516,6 @@
|
|||
"azure_workspace_resource_id": {
|
||||
"description": ""
|
||||
},
|
||||
"current_user": {
|
||||
"description": "",
|
||||
"properties": {
|
||||
"active": {
|
||||
"description": ""
|
||||
},
|
||||
"displayName": {
|
||||
"description": ""
|
||||
},
|
||||
"emails": {
|
||||
"description": "",
|
||||
"items": {
|
||||
"description": "",
|
||||
"properties": {
|
||||
"$ref": {
|
||||
"description": ""
|
||||
},
|
||||
"display": {
|
||||
"description": ""
|
||||
},
|
||||
"primary": {
|
||||
"description": ""
|
||||
},
|
||||
"type": {
|
||||
"description": ""
|
||||
},
|
||||
"value": {
|
||||
"description": ""
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"entitlements": {
|
||||
"description": "",
|
||||
"items": {
|
||||
"description": "",
|
||||
"properties": {
|
||||
"$ref": {
|
||||
"description": ""
|
||||
},
|
||||
"display": {
|
||||
"description": ""
|
||||
},
|
||||
"primary": {
|
||||
"description": ""
|
||||
},
|
||||
"type": {
|
||||
"description": ""
|
||||
},
|
||||
"value": {
|
||||
"description": ""
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"externalId": {
|
||||
"description": ""
|
||||
},
|
||||
"groups": {
|
||||
"description": "",
|
||||
"items": {
|
||||
"description": "",
|
||||
"properties": {
|
||||
"$ref": {
|
||||
"description": ""
|
||||
},
|
||||
"display": {
|
||||
"description": ""
|
||||
},
|
||||
"primary": {
|
||||
"description": ""
|
||||
},
|
||||
"type": {
|
||||
"description": ""
|
||||
},
|
||||
"value": {
|
||||
"description": ""
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"id": {
|
||||
"description": ""
|
||||
},
|
||||
"name": {
|
||||
"description": "",
|
||||
"properties": {
|
||||
"familyName": {
|
||||
"description": ""
|
||||
},
|
||||
"givenName": {
|
||||
"description": ""
|
||||
}
|
||||
}
|
||||
},
|
||||
"roles": {
|
||||
"description": "",
|
||||
"items": {
|
||||
"description": "",
|
||||
"properties": {
|
||||
"$ref": {
|
||||
"description": ""
|
||||
},
|
||||
"display": {
|
||||
"description": ""
|
||||
},
|
||||
"primary": {
|
||||
"description": ""
|
||||
},
|
||||
"type": {
|
||||
"description": ""
|
||||
},
|
||||
"value": {
|
||||
"description": ""
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"userName": {
|
||||
"description": ""
|
||||
}
|
||||
}
|
||||
},
|
||||
"file_path": {
|
||||
"description": "",
|
||||
"properties": {
|
||||
|
@ -1882,9 +1694,6 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"id": {
|
||||
"description": ""
|
||||
},
|
||||
"job_clusters": {
|
||||
"description": "A list of job cluster specifications that can be shared and reused by tasks of this job. Libraries cannot be declared in a shared job cluster. You must declare dependent libraries in task settings.",
|
||||
"items": {
|
||||
|
@ -3211,129 +3020,6 @@
|
|||
"azure_workspace_resource_id": {
|
||||
"description": ""
|
||||
},
|
||||
"current_user": {
|
||||
"description": "",
|
||||
"properties": {
|
||||
"active": {
|
||||
"description": ""
|
||||
},
|
||||
"displayName": {
|
||||
"description": ""
|
||||
},
|
||||
"emails": {
|
||||
"description": "",
|
||||
"items": {
|
||||
"description": "",
|
||||
"properties": {
|
||||
"$ref": {
|
||||
"description": ""
|
||||
},
|
||||
"display": {
|
||||
"description": ""
|
||||
},
|
||||
"primary": {
|
||||
"description": ""
|
||||
},
|
||||
"type": {
|
||||
"description": ""
|
||||
},
|
||||
"value": {
|
||||
"description": ""
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"entitlements": {
|
||||
"description": "",
|
||||
"items": {
|
||||
"description": "",
|
||||
"properties": {
|
||||
"$ref": {
|
||||
"description": ""
|
||||
},
|
||||
"display": {
|
||||
"description": ""
|
||||
},
|
||||
"primary": {
|
||||
"description": ""
|
||||
},
|
||||
"type": {
|
||||
"description": ""
|
||||
},
|
||||
"value": {
|
||||
"description": ""
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"externalId": {
|
||||
"description": ""
|
||||
},
|
||||
"groups": {
|
||||
"description": "",
|
||||
"items": {
|
||||
"description": "",
|
||||
"properties": {
|
||||
"$ref": {
|
||||
"description": ""
|
||||
},
|
||||
"display": {
|
||||
"description": ""
|
||||
},
|
||||
"primary": {
|
||||
"description": ""
|
||||
},
|
||||
"type": {
|
||||
"description": ""
|
||||
},
|
||||
"value": {
|
||||
"description": ""
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"id": {
|
||||
"description": ""
|
||||
},
|
||||
"name": {
|
||||
"description": "",
|
||||
"properties": {
|
||||
"familyName": {
|
||||
"description": ""
|
||||
},
|
||||
"givenName": {
|
||||
"description": ""
|
||||
}
|
||||
}
|
||||
},
|
||||
"roles": {
|
||||
"description": "",
|
||||
"items": {
|
||||
"description": "",
|
||||
"properties": {
|
||||
"$ref": {
|
||||
"description": ""
|
||||
},
|
||||
"display": {
|
||||
"description": ""
|
||||
},
|
||||
"primary": {
|
||||
"description": ""
|
||||
},
|
||||
"type": {
|
||||
"description": ""
|
||||
},
|
||||
"value": {
|
||||
"description": ""
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"userName": {
|
||||
"description": ""
|
||||
}
|
||||
}
|
||||
},
|
||||
"file_path": {
|
||||
"description": "",
|
||||
"properties": {
|
||||
|
@ -3371,4 +3057,4 @@
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -238,6 +238,11 @@ func toSchema(golangType reflect.Type, docs *Docs, tracker *tracker) (*Schema, e
|
|||
properties := map[string]*Schema{}
|
||||
required := []string{}
|
||||
for _, child := range children {
|
||||
bundleTag := child.Tag.Get("bundle")
|
||||
if bundleTag == "readonly" {
|
||||
continue
|
||||
}
|
||||
|
||||
// get child json tags
|
||||
childJsonTag := strings.Split(child.Tag.Get("json"), ",")
|
||||
childName := childJsonTag[0]
|
||||
|
|
|
@ -1410,3 +1410,55 @@ func TestInterfaceGeneratesEmptySchema(t *testing.T) {
|
|||
t.Log("[DEBUG] expected: ", expected)
|
||||
assert.Equal(t, expected, string(jsonSchema))
|
||||
}
|
||||
|
||||
func TestBundleReadOnlytag(t *testing.T) {
|
||||
type Pokemon struct {
|
||||
Pikachu string `json:"pikachu" bundle:"readonly"`
|
||||
Raichu string `json:"raichu"`
|
||||
}
|
||||
|
||||
type Foo struct {
|
||||
Pokemon *Pokemon `json:"pokemon"`
|
||||
Apple int `json:"apple"`
|
||||
Mango string `json:"mango" bundle:"readonly"`
|
||||
}
|
||||
|
||||
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