From 167895c6d75ffdf7ee99251da2249e6f05716f89 Mon Sep 17 00:00:00 2001 From: dadav <33197631+dadav@users.noreply.github.com> Date: Sun, 31 Mar 2024 20:17:26 +0200 Subject: [PATCH] fix: Set type to object if properties are used --- pkg/schema/schema.go | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/pkg/schema/schema.go b/pkg/schema/schema.go index a7516a4..87597ee 100644 --- a/pkg/schema/schema.go +++ b/pkg/schema/schema.go @@ -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 {