Skip to content

feat(openapi): support enum and union status in detailed responses - #2187

Merged
dinwwwh merged 4 commits into
mainfrom
claude/modest-hawking-ptvhrr
Oct 6, 2026
Merged

dinwwwh merged 4 commits into
mainfrom
claude/modest-hawking-ptvhrr

Conversation

@dinwwwh

@dinwwwh dinwwwh commented Oct 6, 2026 •

Copy link
Copy Markdown
Member

Summary

Extends the OpenAPI generator to support multiple status codes in detailed output responses. Previously, only a single literal status (const) was allowed. Now supports enum (how Effect, arktype, and valibot emit picklists) and unions of literals (anyOf), enabling a single response definition to document multiple success status codes with shared headers and body schemas.

Changes

  • Enhanced status schema parsing: Added extractDetailedStatuses() function to extract all valid status codes from const, enum, or anyOf union schemas
  • Multi-status response generation: Modified extractDetailedResponseParts() to iterate over all extracted statuses and create separate OpenAPI response entries for each, inheriting the same headers and body schema
  • Improved validation: Updated error messages and validation logic to accept literal integers below 400 in any of the supported formats

Implementation Details

  • The flattenJsonUnionSchema() helper is reused to normalize both direct enum/const schemas and anyOf unions
  • Each status code in the union gets its own response entry in the OpenAPI spec with the same description (from the union or member), headers, and body
  • Validation ensures all values are integers below 400 and rejects empty enums or unions
  • Test coverage includes single-value enums, multi-value enums, and complex unions with mixed const and enum members

https://claude.ai/code/session_01K42euCFhMfYXSaxkobuBdz

claude added 3 commits October 6, 2026 02:11
EffectSchemaToJsonSchemaConverter emits `Schema.Literal(201)` as
`{ type: 'number', enum: [201] }` rather than `{ const: 201 }`, so
`outputStructure: 'detailed'` with an Effect literal status made
OpenAPIGenerator.generate() throw 'invalid "status" field'. Treat a
single-value `enum` the same as `const` when reading the status.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01K42euCFhMfYXSaxkobuBdz
…ed output status

A detailed output `status` may now be any union of literal statuses: a
multi-value `enum` (zod `z.literal([200, 201])`, valibot `picklist`,
arktype `'200 | 201'`, Effect `Schema.Literals`) or an `anyOf` of
`const`/`enum` schemas (zod/valibot unions of literals). The member's
headers and body are documented under each status, and a description on
an individual union member applies only to its own statuses.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01K42euCFhMfYXSaxkobuBdz
Fold the single-value enum, multi-value enum, and literal union cases into
one `it.each` table, rename the stale "not a const integer" case, and cover
an empty status union.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01K42euCFhMfYXSaxkobuBdz
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
orpc 1449575 Commit Preview URL

Branch Preview URL
Oct 06 2026, 03:47 AM

@pkg-pr-new

pkg-pr-new Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
More templates

@orpc/ai-sdk

npm i https://pkg.pr.new/@orpc/ai-sdk@2187

@orpc/arktype

npm i https://pkg.pr.new/@orpc/arktype@2187

@orpc/bun

npm i https://pkg.pr.new/@orpc/bun@2187

@orpc/client

npm i https://pkg.pr.new/@orpc/client@2187

@orpc/cloudflare

npm i https://pkg.pr.new/@orpc/cloudflare@2187

@orpc/contract

npm i https://pkg.pr.new/@orpc/contract@2187

@orpc/experimental-effect

npm i https://pkg.pr.new/@orpc/experimental-effect@2187

@orpc/evlog

npm i https://pkg.pr.new/@orpc/evlog@2187

@orpc/hibernation

npm i https://pkg.pr.new/@orpc/hibernation@2187

@orpc/json-schema

npm i https://pkg.pr.new/@orpc/json-schema@2187

@orpc/experimental-lock

npm i https://pkg.pr.new/@orpc/experimental-lock@2187

@orpc/experimental-msw

npm i https://pkg.pr.new/@orpc/experimental-msw@2187

@orpc/nest

npm i https://pkg.pr.new/@orpc/nest@2187

@orpc/next

npm i https://pkg.pr.new/@orpc/next@2187

@orpc/node

npm i https://pkg.pr.new/@orpc/node@2187

@orpc/openapi

npm i https://pkg.pr.new/@orpc/openapi@2187

@orpc/opentelemetry

npm i https://pkg.pr.new/@orpc/opentelemetry@2187

@orpc/pinia-colada

npm i https://pkg.pr.new/@orpc/pinia-colada@2187

@orpc/pino

npm i https://pkg.pr.new/@orpc/pino@2187

@orpc/publisher

npm i https://pkg.pr.new/@orpc/publisher@2187

@orpc/ratelimit

npm i https://pkg.pr.new/@orpc/ratelimit@2187

@orpc/server

npm i https://pkg.pr.new/@orpc/server@2187

@orpc/shared

npm i https://pkg.pr.new/@orpc/shared@2187

@orpc/swr

npm i https://pkg.pr.new/@orpc/swr@2187

@orpc/tanstack-query

npm i https://pkg.pr.new/@orpc/tanstack-query@2187

@orpc/trpc

npm i https://pkg.pr.new/@orpc/trpc@2187

@orpc/valibot

npm i https://pkg.pr.new/@orpc/valibot@2187

@orpc/zod

npm i https://pkg.pr.new/@orpc/zod@2187

commit: 1449575

@codecov

codecov Bot commented Oct 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes — reviewed the full 3-file diff at 129d8eb, covering multi-status detailed output support end-to-end.

  • Multi-status extraction (packages/openapi/src/openapi-generator-operation.ts): new extractDetailedStatuses normalizes const, enum, and anyOf/oneOf unions through flattenJsonUnionSchema and rejects non-integer values, values >= 400, and empty unions/enums; extractDetailedResponseParts now emits one response per extracted status, sharing the member's headers/body and applying the flattened member description per status.
  • Tests (packages/openapi/src/openapi-generator-operation.test.ts): table-driven success cases (single-value enum, multi-value enum, mixed const/enum union with parent-description merging) assert full operation.responses deep-equality, plus rejection rows for out-of-range enums, empty enum/union, and non-literal/non-integer members.
  • Docs (apps/content/docs/openapi/input-and-output-mapping.mdx): documents literal/union status and the z.literal([200, 201]) shorthand.

I independently verified the load-bearing claims: zod, Effect, arktype, and valibot emit the enum/const/anyOf shapes the new parser accepts; z.literal([200, 201]) validates at runtime so the docs example is correct; the full @orpc/openapi suite (489 tests) passes; and type:check / eslint are clean.

Pullfrog  | View workflow run | Using deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

@codspeed

codspeed Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 30 untouched benchmarks


Comparing claude/modest-hawking-ptvhrr (1449575) with main (86c31c3)

Open in CodSpeed

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01K42euCFhMfYXSaxkobuBdz
@dinwwwh
dinwwwh merged commit ee02653 into main Oct 6, 2026
12 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.

2 participants