Skip to content

[openapi3] add enum-mode option for annotated enums in 3.1+#10893

Closed
timotheeguerin wants to merge 1 commit into
microsoft:mainfrom
timotheeguerin:main-sxs-20260604-133319-claude-claude-opus-4-7-high
Closed

[openapi3] add enum-mode option for annotated enums in 3.1+#10893
timotheeguerin wants to merge 1 commit into
microsoft:mainfrom
timotheeguerin:main-sxs-20260604-133319-claude-claude-opus-4-7-high

Conversation

@timotheeguerin
Copy link
Copy Markdown
Member

Summary

Fixes #5721

Adds an opt-in enum-mode emitter option to @typespec/openapi3. When set to "annotated", enums are rendered using the OpenAPI 3.1 annotated enumerations pattern — a oneOf of single-const subschemas with per-member title/description pulled from @summary/@doc:

PetType:
  oneOf:
    - type: string
      const: dog
      description: A four-legged friend
    - type: string
      const: cat

The default "enum" preserves today's flat enum: [...] output. The option is silently ignored for OpenAPI 3.0 since const annotated enums are a 3.1 construct. 3.2 inherits the 3.1 emitter and so picks the behavior up automatically.

Test plan

  • pnpm -F @typespec/openapi3 build — clean
  • pnpm -F @typespec/openapi3 test — 2532 tests pass, including 5 new cases:
    • String enum with @docdescription on each subschema
    • Numeric enum with @summarytitle on each subschema
    • Unannotated members → bare {type, const} subschemas
    • Enum-level @doc still applied to the wrapping schema
    • OpenAPI 3.0 + enum-mode: annotated → option ignored (regression guard)

🤖 Generated with Claude Code

Adds opt-in `enum-mode: annotated` emitter option that renders enums
as `oneOf` of `const` subschemas with per-member `title`/`description`
sourced from `@summary`/`@doc`, matching OpenAPI 3.1's annotated
enumerations pattern. Default `enum` preserves existing flat output.
Ignored for OpenAPI 3.0.

Fixes microsoft#5721

Co-Authored-By: Claude Opus 4 <noreply@anthropic.com>
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Jun 4, 2026

Open in StackBlitz

npm i https://pkg.pr.new/@typespec/openapi3@10893

commit: 06a2b76

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 4, 2026

All changed packages have been documented.

  • @typespec/openapi3
Show changes

@typespec/openapi3 - feature ✏️

Add enum-mode emitter option for OpenAPI 3.1+. When set to "annotated", enums are emitted using the annotated enumerations pattern (oneOf of single-const subschemas with title/description from @summary/@doc on each member). The default "enum" preserves the existing flat enum: [...] output. The option has no effect on OpenAPI 3.0.,> ,> yaml,> options:,> "@typespec/openapi3":,> enum-mode: annotated,> openapi-versions: ["3.1.0"],>

@azure-sdk-automation
Copy link
Copy Markdown

You can try these changes here

🛝 Playground 🌐 Website 🛝 VSCode Extension

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

emitter:openapi3 Issues for @typespec/openapi3 emitter

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OpenAPI 3.1 - emit annotated enums

1 participant