From f4e732ce93ff8a9d69c294479cf14e19150cc0e0 Mon Sep 17 00:00:00 2001 From: Nathan Perriolat Date: Fri, 11 Oct 2024 09:56:51 +0200 Subject: [PATCH] use generic x-enum-varnames for enums --- schema/schema.go | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/schema/schema.go b/schema/schema.go index 0af3419..3087590 100644 --- a/schema/schema.go +++ b/schema/schema.go @@ -200,17 +200,15 @@ func (s *Schema) generateSchemaFor(ctx context.Context, doc *openapi3.T, t refle if isEnum, enum := callbacksObject.EnumResolver(t); isEnum { _, found := doc.Components.Schemas[fullName] if !found { + enumDescriptions := []any{} for _, enumEntry := range enum { - schema.Value.OneOf = append(schema.Value.OneOf, &openapi3.SchemaRef{ - Value: &openapi3.Schema{ - Title: fmt.Sprint(enumEntry.Title), - Extensions: map[string]any{ - "const": enumEntry.Value, - }, - Type: "const", - Format: schema.Value.Format, - }, - }) + schema.Value.Enum = append(schema.Value.Enum, enumEntry.Value) + enumDescriptions = append(enumDescriptions, enumEntry.Title) + } + if len(enumDescriptions) > 0 { + schema.Value.Extensions = map[string]any{ + "x-enum-varnames": enumDescriptions, + } } doc.Components.Schemas[fullName] = &openapi3.SchemaRef{ Value: schema.Value,