Skip to content

Commit

Permalink
Merge pull request #42 from dadav/fix_multiple_array_type_parsing
Browse files Browse the repository at this point in the history
fix: Should consider all possible types
  • Loading branch information
dadav authored Aug 17, 2024
2 parents 82590e8 + 0850a91 commit fec762c
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions pkg/schema/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -629,22 +629,28 @@ func castNodeValueByType(rawValue string, fieldType StringOrArrayOfString) any {
return rawValue
}

// Consider the first type only for now
switch fieldType[0] {
case "boolean":
return rawValue == "true"
case "integer":
v, err := strconv.Atoi(rawValue)
if err != nil {
log.Fatalf("Error while converting %s to integer: %v", rawValue, err)
}
return v
case "number":
v, err := strconv.ParseFloat(rawValue, 64)
if err != nil {
log.Fatalf("Error while converting %s to float: %v", rawValue, err)
// rawValue must be one of fielTypes
for _, t := range fieldType {
switch t {
case "boolean":
switch rawValue {
case "true":
return true
case "false":
return false
}
case "integer":
v, err := strconv.Atoi(rawValue)
if err == nil {
return v
}
case "number":
v, err := strconv.ParseFloat(rawValue, 64)
if err == nil {
return v
}
}
return v
}

return rawValue
}

0 comments on commit fec762c

Please sign in to comment.