Skip to content

Commit

Permalink
fix: Set type to object if properties are used
Browse files Browse the repository at this point in the history
  • Loading branch information
dadav committed Mar 31, 2024
1 parent d7dd19e commit 167895c
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 167895c

Please sign in to comment.