diff --git a/bundle/internal/docs/nodes.go b/bundle/internal/docs/nodes.go index 14426f8b8..4047a690b 100644 --- a/bundle/internal/docs/nodes.go +++ b/bundle/internal/docs/nodes.go @@ -59,7 +59,7 @@ func getNodes(s jsonschema.Schema, refs map[string]jsonschema.Schema, customFiel Type: getHumanReadableType(v.Type), } - node.Attributes = getAttributes(v.Properties, refs, k) + node.Attributes = getAttributes(v.Properties, refs, customFields, k) rootProps = append(rootProps, extractNodes(k, v.Properties, refs, customFields)...) additionalProps, ok := v.AdditionalProperties.(*jsonschema.Schema) @@ -72,13 +72,13 @@ func getNodes(s jsonschema.Schema, refs map[string]jsonschema.Schema, customFiel if len(node.Example) == 0 { node.Example = getExample(objectKeyType) } - node.ObjectKeyAttributes = getAttributes(objectKeyType.Properties, refs, k) + node.ObjectKeyAttributes = getAttributes(objectKeyType.Properties, refs, customFields, k) rootProps = append(rootProps, extractNodes(k, objectKeyType.Properties, refs, customFields)...) } if v.Items != nil { arrayItemType := resolveRefs(v.Items, refs) - node.ArrayItemAttributes = getAttributes(arrayItemType.Properties, refs, k) + node.ArrayItemAttributes = getAttributes(arrayItemType.Properties, refs, customFields, k) } isEmpty := len(node.Attributes) == 0 && len(node.ObjectKeyAttributes) == 0 && len(node.ArrayItemAttributes) == 0 @@ -112,7 +112,7 @@ func getHumanReadableType(t jsonschema.Type) string { return typesMapping[string(t)] } -func getAttributes(props map[string]*jsonschema.Schema, refs map[string]jsonschema.Schema, prefix string) []attributeNode { +func getAttributes(props map[string]*jsonschema.Schema, refs map[string]jsonschema.Schema, customFields map[string]bool, prefix string) []attributeNode { attributes := []attributeNode{} for k, v := range props { v = resolveRefs(v, refs) @@ -121,7 +121,7 @@ func getAttributes(props map[string]*jsonschema.Schema, refs map[string]jsonsche typeString = "Any" } var reference string - if isReferenceType(v, refs) { + if isReferenceType(v, refs, customFields) { reference = prefix + "." + k } attributes = append(attributes, attributeNode{ diff --git a/bundle/internal/docs/refs.go b/bundle/internal/docs/refs.go index 520a6e2c5..11651041b 100644 --- a/bundle/internal/docs/refs.go +++ b/bundle/internal/docs/refs.go @@ -7,7 +7,10 @@ import ( "github.com/databricks/cli/libs/jsonschema" ) -func isReferenceType(v *jsonschema.Schema, refs map[string]jsonschema.Schema) bool { +func isReferenceType(v *jsonschema.Schema, refs map[string]jsonschema.Schema, customFields map[string]bool) bool { + if v.Type != "object" && v.Type != "array" { + return false + } if len(v.Properties) > 0 { return true } @@ -17,15 +20,26 @@ func isReferenceType(v *jsonschema.Schema, refs map[string]jsonschema.Schema) bo return true } } - props := resolveAdditionaProperties(v, refs) - if props != nil && props.Type == "object" { - return true + props := resolveAdditionaProperties(v) + if !isInOwnFields(props, customFields) { + return false + } + if props != nil { + propsResolved := resolveRefs(props, refs) + return propsResolved.Type == "object" } return false } -func resolveAdditionaProperties(v *jsonschema.Schema, refs map[string]jsonschema.Schema) *jsonschema.Schema { +func isInOwnFields(node *jsonschema.Schema, customFields map[string]bool) bool { + if node != nil && node.Reference != nil { + return customFields[getRefType(node)] + } + return true +} + +func resolveAdditionaProperties(v *jsonschema.Schema) *jsonschema.Schema { if v.AdditionalProperties == nil { return nil } @@ -33,7 +47,7 @@ func resolveAdditionaProperties(v *jsonschema.Schema, refs map[string]jsonschema if !ok { return nil } - return resolveRefs(additionalProps, refs) + return additionalProps } func resolveRefs(s *jsonschema.Schema, schemas map[string]jsonschema.Schema) *jsonschema.Schema { @@ -44,7 +58,7 @@ func resolveRefs(s *jsonschema.Schema, schemas map[string]jsonschema.Schema) *js examples := s.Examples for node.Reference != nil { - ref := strings.TrimPrefix(*node.Reference, "#/$defs/") + ref := getRefType(node) newNode, ok := schemas[ref] if !ok { log.Printf("schema %s not found", ref) @@ -69,3 +83,10 @@ func resolveRefs(s *jsonschema.Schema, schemas map[string]jsonschema.Schema) *js return node } + +func getRefType(node *jsonschema.Schema) string { + if node.Reference == nil { + return "" + } + return strings.TrimPrefix(*node.Reference, "#/$defs/") +} diff --git a/bundle/internal/schema/annotations_openapi_overrides.yml b/bundle/internal/schema/annotations_openapi_overrides.yml index 36314b777..99ea27c62 100644 --- a/bundle/internal/schema/annotations_openapi_overrides.yml +++ b/bundle/internal/schema/annotations_openapi_overrides.yml @@ -124,6 +124,9 @@ github.com/databricks/cli/bundle/config/resources.MlflowExperiment: "description": |- PLACEHOLDER github.com/databricks/cli/bundle/config/resources.MlflowModel: + "_": + "markdown_description": |- + The model resource allows you to define [legacy models](/api/workspace/modelregistry/createmodel) in bundles. Databricks recommends you use [registered models](#registered-model) instead. "permissions": "description": |- PLACEHOLDER diff --git a/bundle/schema/jsonschema.json b/bundle/schema/jsonschema.json index 990a2f133..ec721c140 100644 --- a/bundle/schema/jsonschema.json +++ b/bundle/schema/jsonschema.json @@ -461,7 +461,8 @@ "$ref": "#/$defs/string" } }, - "additionalProperties": false + "additionalProperties": false, + "markdownDescription": "The model resource allows you to define [legacy models](https://docs.databricks.com/api/workspace/modelregistry/createmodel) in bundles. Databricks recommends you use \u003cUC\u003e [registered models](https://docs.databricks.com/dev-tools/bundles/reference.html#registered-model) instead." }, { "type": "string", @@ -941,6 +942,7 @@ }, "variable.Variable": { "type": "object", + "description": "Defines a custom variable for the bundle.", "properties": { "default": { "$ref": "#/$defs/interface" @@ -959,7 +961,8 @@ "$ref": "#/$defs/github.com/databricks/cli/bundle/config/variable.VariableType" } }, - "additionalProperties": false + "additionalProperties": false, + "markdownDescription": "Defines a custom variable for the bundle. See [variables](https://docs.databricks.com/dev-tools/bundles/settings.html#variables)." }, "variable.VariableType": { "type": "string" @@ -1088,8 +1091,7 @@ }, "lock": { "description": "The deployment lock attributes.", - "$ref": "#/$defs/github.com/databricks/cli/bundle/config.Lock", - "markdownDescription": "The deployment lock attributes. See [lock](https://docs.databricks.com/dev-tools/bundles/reference.html#lock)." + "$ref": "#/$defs/github.com/databricks/cli/bundle/config.Lock" } }, "additionalProperties": false @@ -1379,8 +1381,7 @@ "properties": { "artifacts": { "description": "The artifacts to include in the target deployment.", - "$ref": "#/$defs/map/github.com/databricks/cli/bundle/config.Artifact", - "markdownDescription": "The artifacts to include in the target deployment. See [artifact](https://docs.databricks.com/dev-tools/bundles/reference.html#artifact)" + "$ref": "#/$defs/map/github.com/databricks/cli/bundle/config.Artifact" }, "bundle": { "description": "The bundle attributes when deploying to this target.", @@ -1426,13 +1427,11 @@ }, "sync": { "description": "The local paths to sync to the target workspace when a bundle is run or deployed.", - "$ref": "#/$defs/github.com/databricks/cli/bundle/config.Sync", - "markdownDescription": "The local paths to sync to the target workspace when a bundle is run or deployed. See [sync](https://docs.databricks.com/dev-tools/bundles/reference.html#sync)." + "$ref": "#/$defs/github.com/databricks/cli/bundle/config.Sync" }, "variables": { "description": "The custom variable definitions for the target.", - "$ref": "#/$defs/map/github.com/databricks/cli/bundle/config/variable.TargetVariable", - "markdownDescription": "The custom variable definitions for the target. See [link](https://docs.databricks.com/dev-tools/bundles/variables.html)." + "$ref": "#/$defs/map/github.com/databricks/cli/bundle/config/variable.TargetVariable" }, "workspace": { "description": "The Databricks workspace for the target.",