Skip to content

Commit

Permalink
Merge pull request #22 from dadav/set_correct_type
Browse files Browse the repository at this point in the history
fix: Set type to object if properties are used
  • Loading branch information
dadav authored Mar 31, 2024
2 parents d7dd19e + 167895c commit c44420c
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions pkg/schema/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,15 +356,21 @@ func typeFromTag(tag string) ([]string, error) {
}

func FixRequiredProperties(schema *Schema) error {
requiredProperties := []string{}
for propName, propValue := range schema.Properties {
FixRequiredProperties(propValue)
if propValue.Required {
requiredProperties = append(requiredProperties, propName)
if schema.Properties != nil {
requiredProperties := []string{}
for propName, propValue := range schema.Properties {
FixRequiredProperties(propValue)
if propValue.Required {
requiredProperties = append(requiredProperties, propName)
}
}
if len(requiredProperties) > 0 {
schema.RequiredProperties = requiredProperties
}
if !slices.Contains(schema.Type, "object") {
// If .Properties is set, type must be object
schema.Type = []string{"object"}
}
}
if len(requiredProperties) > 0 {
schema.RequiredProperties = requiredProperties
}

if schema.Then != nil {
Expand Down

0 comments on commit c44420c

Please sign in to comment.