Skip to content

fix: give inline-enum items of a oneOf/anyOf array branch their own type name - #2653

Open
ahm3dwasim wants to merge 2 commits into
oapi-codegen:mainfrom
ahm3dwasim:fix/2640-array-enum-name-clash
Open

ahm3dwasim wants to merge 2 commits into
oapi-codegen:mainfrom
ahm3dwasim:fix/2640-array-enum-name-clash

Conversation

@ahm3dwasim

Copy link
Copy Markdown

An array branch of a oneOf/anyOf is named after its path, and the inline enum of its items was named from that same path, so both got one type name. The output either failed to compile or generation stopped with a duplicate typename (#2640).

This names the items' enum after the branch plus Item, in that position only. The marker is cleared as soon as codegen descends into the branch, so nested schemas (for example an array property inside an object branch, or object items of an array branch) keep their current names. No existing generated name changes; no fixtures change.

Tests:

  • TestUnionArrayBranchOfInlineEnum: the issue's component anyOf and request-body oneOf cases now generate distinct types (fails on main with duplicate typename).
  • TestUnionObjectBranchArrayPropertyInlineEnumName: an array property with an inline enum inside an object branch keeps the name Choice0Roles, same as main.

gofmt, go vet ./pkg/codegen and the focused tests pass.

Fixes #2640

…ype name

An array branch of a union is named after its path, and its items'
inline enum was named from that same path, so both types got one name:
the output failed to compile, or generation failed with a duplicate
typename. Name the items' enum after the branch plus "Item" in that
position only, leaving every other generated name unchanged.

Fixes oapi-codegen#2640
@ahm3dwasim
ahm3dwasim requested a review from a team as a code owner November 1, 2026 09:40
@greptile-apps

greptile-apps Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Low impact] The PR appears safe to merge; both previous findings are fixed.

Summary

Gives inline enum items their own names when they belong to an array branch of oneOf or anyOf.

  • Inline enum items in array union branches get their own type name.

Reviews (2) · Last reviewed commit: "fix: preserve explicit enum names in uni..." · Reviewed by Greptile

Comment thread pkg/codegen/schema.go Resolved
Comment thread pkg/codegen/schema.go Resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A oneOf/anyOf branch that is an array of an inline enum gets the same type name as its items

1 participant