Skip to content

Commit

Permalink
explain: Display field information not definition information for fie…
Browse files Browse the repository at this point in the history
…ld output

Signed-off-by: Chance Zibolski <[email protected]>
  • Loading branch information
chancez committed Sep 4, 2024
1 parent 62218d7 commit 5a07201
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions cmd/explain.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@ Examples:
return fmt.Errorf("invalid type: %s", ty)
}

props := typeSchema.Properties
fieldSchema := typeSchema
var fieldName string
var fieldDescription string
var fieldType string
if len(fields) != 0 {
// Lookup the field the user specified
for _, field := range fields {
Expand All @@ -60,25 +61,28 @@ Examples:
}

foundField = true
fieldSchema = pair.Value
fieldName = pair.Key
for {
// Resolve refs if they exist
for fieldSchema.Ref != "" {
fieldSchema = pair.Value
fieldDescription = fieldSchema.Description
fieldType = schemaTypeString(fieldSchema)

// Now lookup the definition for this field if needed.
// Resolve refs if they exist
for fieldSchema.Ref != "" || fieldSchema.Items != nil {
if fieldSchema.Ref != "" {
var err error
fieldName, fieldSchema, err = getDefinition(fieldSchema.Ref)
_, fieldSchema, err = getDefinition(fieldSchema.Ref)
if err != nil {
return err
}
}
// If it's a list then lookup the inner type of the list

// If it's a list then lookup the inner type of the list is what we
// need to lookup the fields.
if fieldSchema.Items != nil {
fieldSchema = fieldSchema.Items
} else {
break
}
}
props = fieldSchema.Properties
break
}
if !foundField {
Expand Down Expand Up @@ -111,12 +115,12 @@ Examples:
}

if fieldSchema != nil && fieldSchema != typeSchema {
ty := schemaTypeString(fieldSchema)
log("FIELD: %s <%s>", fieldName, ty)
logDescription(fieldSchema.Description)
log("FIELD: %s <%s>", fieldName, fieldType)
logDescription(fieldDescription)
log("")
}

props := fieldSchema.Properties
if props.Len() != 0 {
log("FIELDS:")
for pair := props.Oldest(); pair != nil; pair = pair.Next() {
Expand Down

0 comments on commit 5a07201

Please sign in to comment.