Skip to content

Support OpenAPI 3.1 enum-via-oneOf idiom#2

Merged
mromaszewicz merged 1 commit intooapi-codegen:mainfrom
mromaszewicz:feat/oneof-enum
Apr 15, 2026
Merged

Support OpenAPI 3.1 enum-via-oneOf idiom#2
mromaszewicz merged 1 commit intooapi-codegen:mainfrom
mromaszewicz:feat/oneof-enum

Conversation

@mromaszewicz
Copy link
Copy Markdown
Member

A scalar schema whose oneOf branches each carry const + title is the spec-native way to express a named enum with per-value documentation (OpenAPI 3.1 / JSON Schema 2020-12). Previously such schemas generated a json.RawMessage-backed union; now they produce a regular Go enum with titled constants and per-value doc comments sourced from description.

Detection is strict — every branch must carry both const and title, and the outer schema must declare a scalar type (string or integer) — so schemas that don't cleanly match fall through to the existing oneOf union generator unchanged. The behavior is default-on; generation.skip-enum-via-oneof: true restores the legacy output.

A scalar schema whose `oneOf` branches each carry `const` + `title` is
the spec-native way to express a named enum with per-value documentation
(OpenAPI 3.1 / JSON Schema 2020-12). Previously such schemas generated a
`json.RawMessage`-backed union; now they produce a regular Go enum with
titled constants and per-value doc comments sourced from `description`.

Detection is strict — every branch must carry both `const` and `title`,
and the outer schema must declare a scalar `type` (`string` or
`integer`) — so schemas that don't cleanly match fall through to the
existing oneOf union generator unchanged. The behavior is default-on;
`generation.skip-enum-via-oneof: true` restores the legacy output.
@mromaszewicz mromaszewicz merged commit 56dd39e into oapi-codegen:main Apr 15, 2026
11 checks passed
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.

1 participant