Skip to content

Commit

Permalink
Fix bug where keyNode is nill
Browse files Browse the repository at this point in the history
If `KeyNode` is `nil`, read from comments anyway.
Closes #28

Signed-off-by: Aleksandar Stojanov <[email protected]>
  • Loading branch information
losisin committed Dec 25, 2023
1 parent 356b6da commit 78fed75
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions pkg/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,13 @@ func getSchemaURL(draft int) (string, error) {
}

func getComment(keyNode *yaml.Node, valNode *yaml.Node) string {
if len(valNode.Value) > 0 {
if valNode.LineComment != "" {
return valNode.LineComment
}
return keyNode.LineComment
if keyNode != nil {
return keyNode.LineComment
}
return ""
}

func processList(comment string, stringsOnly bool) []interface{} {
Expand Down Expand Up @@ -102,8 +105,6 @@ func processComment(schema *Schema, comment string) (isRequired bool) {
value := strings.TrimSpace(keyValue[1])

switch key {
case "type":
schema.Type = processList(value, true)
case "enum":
schema.Enum = processList(value, false)
case "multipleOf":
Expand Down Expand Up @@ -154,6 +155,8 @@ func processComment(schema *Schema, comment string) (isRequired bool) {
if strings.TrimSpace(value) == "true" {
isRequired = strings.TrimSpace(value) == "true"
}
case "type":
schema.Type = processList(value, true)
}
}
}
Expand Down

0 comments on commit 78fed75

Please sign in to comment.