Skip to content

Commit

Permalink
use generic x-enum-varnames for enums
Browse files Browse the repository at this point in the history
  • Loading branch information
Misfits09 authored and schmurfy committed Oct 14, 2024
1 parent 77e1d46 commit f4e732c
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions schema/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit f4e732c

Please sign in to comment.