mirror of https://github.com/databricks/cli.git
fix: Invalid refrences
This commit is contained in:
parent
ee5db187c0
commit
0bd7b524db
|
@ -59,7 +59,7 @@ func getNodes(s jsonschema.Schema, refs map[string]jsonschema.Schema, customFiel
|
||||||
Type: getHumanReadableType(v.Type),
|
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)...)
|
rootProps = append(rootProps, extractNodes(k, v.Properties, refs, customFields)...)
|
||||||
|
|
||||||
additionalProps, ok := v.AdditionalProperties.(*jsonschema.Schema)
|
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 {
|
if len(node.Example) == 0 {
|
||||||
node.Example = getExample(objectKeyType)
|
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)...)
|
rootProps = append(rootProps, extractNodes(k, objectKeyType.Properties, refs, customFields)...)
|
||||||
}
|
}
|
||||||
|
|
||||||
if v.Items != nil {
|
if v.Items != nil {
|
||||||
arrayItemType := resolveRefs(v.Items, refs)
|
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
|
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)]
|
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{}
|
attributes := []attributeNode{}
|
||||||
for k, v := range props {
|
for k, v := range props {
|
||||||
v = resolveRefs(v, refs)
|
v = resolveRefs(v, refs)
|
||||||
|
@ -121,7 +121,7 @@ func getAttributes(props map[string]*jsonschema.Schema, refs map[string]jsonsche
|
||||||
typeString = "Any"
|
typeString = "Any"
|
||||||
}
|
}
|
||||||
var reference string
|
var reference string
|
||||||
if isReferenceType(v, refs) {
|
if isReferenceType(v, refs, customFields) {
|
||||||
reference = prefix + "." + k
|
reference = prefix + "." + k
|
||||||
}
|
}
|
||||||
attributes = append(attributes, attributeNode{
|
attributes = append(attributes, attributeNode{
|
||||||
|
|
|
@ -7,7 +7,10 @@ import (
|
||||||
"github.com/databricks/cli/libs/jsonschema"
|
"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 {
|
if len(v.Properties) > 0 {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -17,15 +20,26 @@ func isReferenceType(v *jsonschema.Schema, refs map[string]jsonschema.Schema) bo
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
props := resolveAdditionaProperties(v, refs)
|
props := resolveAdditionaProperties(v)
|
||||||
if props != nil && props.Type == "object" {
|
if !isInOwnFields(props, customFields) {
|
||||||
return true
|
return false
|
||||||
|
}
|
||||||
|
if props != nil {
|
||||||
|
propsResolved := resolveRefs(props, refs)
|
||||||
|
return propsResolved.Type == "object"
|
||||||
}
|
}
|
||||||
|
|
||||||
return false
|
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 {
|
if v.AdditionalProperties == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -33,7 +47,7 @@ func resolveAdditionaProperties(v *jsonschema.Schema, refs map[string]jsonschema
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return resolveRefs(additionalProps, refs)
|
return additionalProps
|
||||||
}
|
}
|
||||||
|
|
||||||
func resolveRefs(s *jsonschema.Schema, schemas map[string]jsonschema.Schema) *jsonschema.Schema {
|
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
|
examples := s.Examples
|
||||||
|
|
||||||
for node.Reference != nil {
|
for node.Reference != nil {
|
||||||
ref := strings.TrimPrefix(*node.Reference, "#/$defs/")
|
ref := getRefType(node)
|
||||||
newNode, ok := schemas[ref]
|
newNode, ok := schemas[ref]
|
||||||
if !ok {
|
if !ok {
|
||||||
log.Printf("schema %s not found", ref)
|
log.Printf("schema %s not found", ref)
|
||||||
|
@ -69,3 +83,10 @@ func resolveRefs(s *jsonschema.Schema, schemas map[string]jsonschema.Schema) *js
|
||||||
|
|
||||||
return node
|
return node
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getRefType(node *jsonschema.Schema) string {
|
||||||
|
if node.Reference == nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return strings.TrimPrefix(*node.Reference, "#/$defs/")
|
||||||
|
}
|
||||||
|
|
|
@ -124,6 +124,9 @@ github.com/databricks/cli/bundle/config/resources.MlflowExperiment:
|
||||||
"description": |-
|
"description": |-
|
||||||
PLACEHOLDER
|
PLACEHOLDER
|
||||||
github.com/databricks/cli/bundle/config/resources.MlflowModel:
|
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 <UC> [registered models](#registered-model) instead.
|
||||||
"permissions":
|
"permissions":
|
||||||
"description": |-
|
"description": |-
|
||||||
PLACEHOLDER
|
PLACEHOLDER
|
||||||
|
|
|
@ -461,7 +461,8 @@
|
||||||
"$ref": "#/$defs/string"
|
"$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",
|
"type": "string",
|
||||||
|
@ -941,6 +942,7 @@
|
||||||
},
|
},
|
||||||
"variable.Variable": {
|
"variable.Variable": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
|
"description": "Defines a custom variable for the bundle.",
|
||||||
"properties": {
|
"properties": {
|
||||||
"default": {
|
"default": {
|
||||||
"$ref": "#/$defs/interface"
|
"$ref": "#/$defs/interface"
|
||||||
|
@ -959,7 +961,8 @@
|
||||||
"$ref": "#/$defs/github.com/databricks/cli/bundle/config/variable.VariableType"
|
"$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": {
|
"variable.VariableType": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
|
@ -1088,8 +1091,7 @@
|
||||||
},
|
},
|
||||||
"lock": {
|
"lock": {
|
||||||
"description": "The deployment lock attributes.",
|
"description": "The deployment lock attributes.",
|
||||||
"$ref": "#/$defs/github.com/databricks/cli/bundle/config.Lock",
|
"$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)."
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"additionalProperties": false
|
"additionalProperties": false
|
||||||
|
@ -1379,8 +1381,7 @@
|
||||||
"properties": {
|
"properties": {
|
||||||
"artifacts": {
|
"artifacts": {
|
||||||
"description": "The artifacts to include in the target deployment.",
|
"description": "The artifacts to include in the target deployment.",
|
||||||
"$ref": "#/$defs/map/github.com/databricks/cli/bundle/config.Artifact",
|
"$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)"
|
|
||||||
},
|
},
|
||||||
"bundle": {
|
"bundle": {
|
||||||
"description": "The bundle attributes when deploying to this target.",
|
"description": "The bundle attributes when deploying to this target.",
|
||||||
|
@ -1426,13 +1427,11 @@
|
||||||
},
|
},
|
||||||
"sync": {
|
"sync": {
|
||||||
"description": "The local paths to sync to the target workspace when a bundle is run or deployed.",
|
"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",
|
"$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)."
|
|
||||||
},
|
},
|
||||||
"variables": {
|
"variables": {
|
||||||
"description": "The custom variable definitions for the target.",
|
"description": "The custom variable definitions for the target.",
|
||||||
"$ref": "#/$defs/map/github.com/databricks/cli/bundle/config/variable.TargetVariable",
|
"$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)."
|
|
||||||
},
|
},
|
||||||
"workspace": {
|
"workspace": {
|
||||||
"description": "The Databricks workspace for the target.",
|
"description": "The Databricks workspace for the target.",
|
||||||
|
|
Loading…
Reference in New Issue