mirror of https://github.com/databricks/cli.git
comments and typo correction
This commit is contained in:
parent
276ba00067
commit
ae201f1bd3
|
@ -48,7 +48,6 @@ type Root struct {
|
||||||
|
|
||||||
func Load(path string) (*Root, error) {
|
func Load(path string) (*Root, error) {
|
||||||
var r Root
|
var r Root
|
||||||
|
|
||||||
stat, err := os.Stat(path)
|
stat, err := os.Stat(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
@ -33,7 +33,7 @@ type Item struct {
|
||||||
func NewSchema(golangType reflect.Type) (*Schema, error) {
|
func NewSchema(golangType reflect.Type) (*Schema, error) {
|
||||||
seenTypes := map[reflect.Type]struct{}{}
|
seenTypes := map[reflect.Type]struct{}{}
|
||||||
debugTrace := list.New()
|
debugTrace := list.New()
|
||||||
rootProp, err := toProperity(golangType, seenTypes, debugTrace)
|
rootProp, err := toProperty(golangType, seenTypes, debugTrace)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errWithTrace(err.Error(), debugTrace)
|
return nil, errWithTrace(err.Error(), debugTrace)
|
||||||
}
|
}
|
||||||
|
@ -98,8 +98,8 @@ func errWithTrace(prefix string, trace *list.List) error {
|
||||||
|
|
||||||
// TODO: add tests for the error cases, forcefully triggering them
|
// TODO: add tests for the error cases, forcefully triggering them
|
||||||
|
|
||||||
// checks and errors out for cycles
|
// A wrapper over toProperty function with checks for an cycles to avoid being
|
||||||
// wraps the error with context
|
// stuck in an loop when traversing the config struct
|
||||||
func safeToProperty(golangType reflect.Type, seenTypes map[reflect.Type]struct{}, debugTrace *list.List) (*Property, error) {
|
func safeToProperty(golangType reflect.Type, seenTypes map[reflect.Type]struct{}, debugTrace *list.List) (*Property, error) {
|
||||||
// detect cycles. Fail if a cycle is detected
|
// detect cycles. Fail if a cycle is detected
|
||||||
// TODO: Add references here for cycles
|
// TODO: Add references here for cycles
|
||||||
|
@ -111,7 +111,7 @@ func safeToProperty(golangType reflect.Type, seenTypes map[reflect.Type]struct{}
|
||||||
}
|
}
|
||||||
// add current child field to history
|
// add current child field to history
|
||||||
seenTypes[golangType] = struct{}{}
|
seenTypes[golangType] = struct{}{}
|
||||||
props, err := toProperity(golangType, seenTypes, debugTrace)
|
props, err := toProperty(golangType, seenTypes, debugTrace)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -123,6 +123,14 @@ func safeToProperty(golangType reflect.Type, seenTypes map[reflect.Type]struct{}
|
||||||
// member fields of a struct
|
// member fields of a struct
|
||||||
// simple Tree based traversal will take place because embbedded fields cannot
|
// simple Tree based traversal will take place because embbedded fields cannot
|
||||||
// form a cycle
|
// form a cycle
|
||||||
|
|
||||||
|
// Adds the member fields of golangType to the passed slice. Needed because
|
||||||
|
// golangType can contain embedded fields (aka anonymous)
|
||||||
|
//
|
||||||
|
// The function traverses the embedded fields in a breadth first manner
|
||||||
|
//
|
||||||
|
// params:
|
||||||
|
// fields: slice to which member fields of golangType will be added to
|
||||||
func addStructFields(fields []reflect.StructField, golangType reflect.Type) []reflect.StructField {
|
func addStructFields(fields []reflect.StructField, golangType reflect.Type) []reflect.StructField {
|
||||||
bfsQueue := list.New()
|
bfsQueue := list.New()
|
||||||
|
|
||||||
|
@ -154,12 +162,17 @@ func addStructFields(fields []reflect.StructField, golangType reflect.Type) []re
|
||||||
|
|
||||||
// TODO: add ignore for -
|
// TODO: add ignore for -
|
||||||
|
|
||||||
// TODO: add doc string explaining numHistoryOccurances
|
// params:
|
||||||
func toProperity(golangType reflect.Type, seenTypes map[reflect.Type]struct{}, debugTrace *list.List) (*Property, error) {
|
// golangType: golang type for which json schema properties to generate
|
||||||
|
// seenTypes : set of golang types already seen in path during recursion.
|
||||||
|
// Used to identify cycles.
|
||||||
|
// debugTrace: linked list of golang types encounted. In case of errors this
|
||||||
|
// helps log where the error originated from
|
||||||
|
func toProperty(golangType reflect.Type, seenTypes map[reflect.Type]struct{}, debugTrace *list.List) (*Property, error) {
|
||||||
// *Struct and Struct generate identical json schemas
|
// *Struct and Struct generate identical json schemas
|
||||||
// TODO: add test case for pointer
|
// TODO: add test case for pointer
|
||||||
if golangType.Kind() == reflect.Pointer {
|
if golangType.Kind() == reflect.Pointer {
|
||||||
return toProperity(golangType.Elem(), seenTypes, debugTrace)
|
return toProperty(golangType.Elem(), seenTypes, debugTrace)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: add test case for interfaces
|
// TODO: add test case for interfaces
|
||||||
|
|
Loading…
Reference in New Issue