mirror of https://github.com/databricks/cli.git
Addressed style and comment issues
This commit is contained in:
parent
ccefb20e4e
commit
761186680f
|
@ -1,7 +1,6 @@
|
||||||
package schema
|
package schema
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"gopkg.in/yaml.v2"
|
"gopkg.in/yaml.v2"
|
||||||
|
@ -13,11 +12,7 @@ type Docs struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func LoadDocs(path string) (*Docs, error) {
|
func LoadDocs(path string) (*Docs, error) {
|
||||||
f, err := os.Open(path)
|
bytes, err := os.ReadFile(path)
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
bytes, err := ioutil.ReadAll(f)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,23 +16,23 @@ type Schema struct {
|
||||||
// IDE. This is manually injected here using schema.Docs
|
// IDE. This is manually injected here using schema.Docs
|
||||||
Description string `json:"description,omitempty"`
|
Description string `json:"description,omitempty"`
|
||||||
|
|
||||||
// schemas for the fields of an struct. The keys are the first json tag.
|
// Schemas for the fields of an struct. The keys are the first json tag.
|
||||||
// The values are the schema for the type of the field
|
// The values are the schema for the type of the field
|
||||||
Properties map[string]*Schema `json:"properties,omitempty"`
|
Properties map[string]*Schema `json:"properties,omitempty"`
|
||||||
|
|
||||||
// the schema for all values of an array
|
// The schema for all values of an array
|
||||||
Items *Schema `json:"items,omitempty"`
|
Items *Schema `json:"items,omitempty"`
|
||||||
|
|
||||||
// the schema for any properties not mentioned in the Schema.Properties field.
|
// The schema for any properties not mentioned in the Schema.Properties field.
|
||||||
// this validates Maps in bundle configuration
|
// this validates Maps in bundle configuration
|
||||||
// OR
|
// OR
|
||||||
// a boolean type with value false. Setting false here validates that all
|
// A boolean type with value false. Setting false here validates that all
|
||||||
// properties in the yaml file have been defined in the json schema
|
// properties in the yaml file have been defined in the json schema
|
||||||
//
|
//
|
||||||
// Its type during runtime will either be *Schema or bool
|
// Its type during runtime will either be *Schema or bool
|
||||||
AdditionalProperties interface{} `json:"additionalProperties,omitempty"`
|
AdditionalProperties any `json:"additionalProperties,omitempty"`
|
||||||
|
|
||||||
// required properties for the object. Any fields missing the "omitempty"
|
// Required properties for the object. Any fields missing the "omitempty"
|
||||||
// tag will be included
|
// tag will be included
|
||||||
Required []string `json:"required,omitempty"`
|
Required []string `json:"required,omitempty"`
|
||||||
}
|
}
|
||||||
|
@ -45,20 +45,20 @@ type Schema struct {
|
||||||
// - int (all variants) -> number
|
// - int (all variants) -> number
|
||||||
// - float (all variants) -> number
|
// - float (all variants) -> number
|
||||||
// - map[string]MyStruct -> {
|
// - map[string]MyStruct -> {
|
||||||
// type: object
|
// type: object
|
||||||
// additionalProperties: {}
|
// additionalProperties: {}
|
||||||
// }
|
// }
|
||||||
// for details visit: https://json-schema.org/understanding-json-schema/reference/object.html#additional-properties
|
// for details visit: https://json-schema.org/understanding-json-schema/reference/object.html#additional-properties
|
||||||
// - []MyStruct -> {
|
// - []MyStruct -> {
|
||||||
// type: array
|
// type: array
|
||||||
// items: {}
|
// items: {}
|
||||||
// }
|
// }
|
||||||
// for details visit: https://json-schema.org/understanding-json-schema/reference/array.html#items
|
// for details visit: https://json-schema.org/understanding-json-schema/reference/array.html#items
|
||||||
// - []MyStruct -> {
|
// - []MyStruct -> {
|
||||||
// type: object
|
// type: object
|
||||||
// properties: {}
|
// properties: {}
|
||||||
// additionalProperties: false
|
// additionalProperties: false
|
||||||
// }
|
// }
|
||||||
// for details visit: https://json-schema.org/understanding-json-schema/reference/object.html#properties
|
// for details visit: https://json-schema.org/understanding-json-schema/reference/object.html#properties
|
||||||
func NewSchema(golangType reflect.Type, docs *Docs) (*Schema, error) {
|
func NewSchema(golangType reflect.Type, docs *Docs) (*Schema, error) {
|
||||||
seenTypes := map[reflect.Type]struct{}{}
|
seenTypes := map[reflect.Type]struct{}{}
|
||||||
|
@ -148,10 +148,9 @@ func safeToSchema(golangType reflect.Type, docs *Docs, debugTraceId string, seen
|
||||||
return props, nil
|
return props, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Adds the member fields of golangType to the passed slice. Needed because
|
// This function returns all member fields of the provided type.
|
||||||
// golangType can contain embedded fields (aka anonymous fields)
|
// If the type has embedded (aka anonymous) fields, this function traverses
|
||||||
|
// those in a breadth first manner
|
||||||
// The function traverses the embedded fields in a breadth first mannerå
|
|
||||||
func getStructFields(golangType reflect.Type) []reflect.StructField {
|
func getStructFields(golangType reflect.Type) []reflect.StructField {
|
||||||
fields := []reflect.StructField{}
|
fields := []reflect.StructField{}
|
||||||
bfsQueue := list.New()
|
bfsQueue := list.New()
|
||||||
|
|
Loading…
Reference in New Issue