Skip to content

fix(openapi): describe tuple rest elements as repeated items - #8152

Merged
KATT merged 1 commit into
trpc:mainfrom
BlueX888:contrib/openapi-tuple-rest
Nov 23, 2026
Merged

KATT merged 1 commit into
trpc:mainfrom
BlueX888:contrib/openapi-tuple-rest

Conversation

@BlueX888

@BlueX888 BlueX888 commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Why

@trpc/openapi emits an exact-length schema for a tuple with a rest element ([string, ...number[]]), so valid values fail validation and generated clients send or accept the wrong shape.

What

  • Treat a trailing rest element as items instead of a fixed prefixItems entry, and drop maxItems.
  • Keep minItems at the number of required elements, so an optional element before the rest stays optional.
  • Use a permissive item schema for a leading rest element, which JSON Schema cannot express positionally.
  • Leave plain tuples unchanged.
  • Add router fixtures and a regression test covering trailing, optional+trailing, leading and plain tuples.

Links

None

Alternatives considered

  • Encoding the leading-rest last-item constraint with contains: JSON Schema cannot express item order there; a permissive item schema is the honest representation.

Testing

Regression check: packages/openapi/test/restTuple.test.ts fails on main (3 rest cases) and passes here; the full trpc-openapi suite is 217/217. Typecheck, lint and format pass.

AI model

deepseek-v4.1-flash-mb (max effort)


Run Proof
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

Summary by CodeRabbit

  • Bug Fixes

    • Improved OpenAPI schemas for tuple types with rest elements, including optional and trailing elements. Required elements that allow undefined are now correctly reflected in minimum item counts.
    • Schemas for tuples with rest elements no longer impose an exact-length maximum.
  • Tests

    • Added coverage for rest and fixed-length tuple schemas, including validation of generated OpenAPI documents.

A rest element was emitted as a fixed position with items:false and a
maxItems cap, so schemas rejected valid tuples like [string, ...number[]].
Emit it as repeated items instead, keep a leading rest permissive, and
leave tuples without rest unchanged.
@BlueX888
BlueX888 requested a review from a team as a code owner November 23, 2026 03:24
@vercel

vercel Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

7 Skipped Deployments
Project Deployment Actions Updated
examples-next-minimal-starter Skipped Skipped Nov 23, 2026 3:24am UTC
examples-todomvc Skipped Skipped Nov 23, 2026 3:24am UTC
next-prisma-starter Skipped Skipped Nov 23, 2026 3:24am UTC
next-prisma-websockets-starter Skipped Skipped Nov 23, 2026 3:24am UTC
tanstack-start-sse-chat Skipped Skipped Nov 23, 2026 3:24am UTC
trpc-next-app-dir Skipped Skipped Nov 23, 2026 3:24am UTC
www Skipped Skipped Nov 23, 2026 3:24am UTC

Request Review

@vercel
vercel Bot temporarily deployed to Preview – trpc-next-app-dir November 23, 2026 03:24 Inactive
@vercel
vercel Bot temporarily deployed to Preview – examples-next-minimal-starter November 23, 2026 03:24 Inactive
@vercel
vercel Bot temporarily deployed to Preview – examples-todomvc November 23, 2026 03:24 Inactive
@vercel
vercel Bot temporarily deployed to Preview – www November 23, 2026 03:24 Inactive
@vercel
vercel Bot temporarily deployed to Preview – next-prisma-starter November 23, 2026 03:24 Inactive
@coderabbitai

coderabbitai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

OpenAPI tuple schema generation now counts required elements for minItems and handles rest elements using prefixItems and items. Tests cover trailing, optional-before-rest, leading-rest, and fixed-length tuples.

Changes: Rest Tuple OpenAPI Schemas

Layer / File(s) Summary
Tuple schema conversion
packages/openapi/src/generate.ts
convertTupleType counts required elements for minItems. Rest tuples use items for rest and tail schemas and omit maxItems; fixed tuples retain exact length constraints.
Tuple schema test coverage
packages/openapi/test/routers/restTupleRouter.ts, packages/openapi/test/restTuple.test.ts
A router fixture and tests cover trailing-rest, optional-before-rest, leading-rest, and fixed-length tuples. The tests also check OpenAPI validation.

Estimated code review effort: 2 (Simple) | ~15 minutes

Change: Bug fix

Possibly related PRs

  • trpc/trpc#8141: Changes tuple schema generation for optional elements, including minItems and maxItems constraints.

Suggested reviewers: nick-lucas, katt

Merge Risk: Minimal · up to 0e12b

This change fixes the OpenAPI schema emitted for tuples with rest elements so valid values are no longer rejected. No actionable merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: tuple rest elements are now described as repeated items in the OpenAPI output. The raw summary confirms that convertTupleType now uses items for trailing rest elements…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: tuple rest elements are now described as repeated items in the OpenAPI output. The raw summary confirms that convertTupleType now uses items for trailing rest elements, drops maxItems in those cases, and derives minItems from required elements. The title is specific and matches the objectives. The title uses the fix(openapi) prefix, which is a conventional commit style and is acceptable.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: trpc/trpc
  • Branch: main
  • File: .coderabbit.yaml
  • Commit: 0813ceb
  • Layers: Repository YAML
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 90e91cce-c9aa-4779-8054-5e9439b5a6bc
Commits

Reviewing files that changed from the base of the PR and between 0813ceb and 0e12b6a.

Files selected for processing: 3

  • packages/openapi/src/generate.ts
  • packages/openapi/test/restTuple.test.ts
  • packages/openapi/test/routers/restTupleRouter.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@trpc-bot trpc-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The new test fails on main (the three rest cases) and passes here.

@KATT
KATT added this pull request to the merge queue Nov 23, 2026
Merged via the queue into trpc:main with commit e959386 Nov 23, 2026
35 of 36 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

This pull request has been locked because we are very unlikely to see comments on closed issues. If you think, this PR is still necessary, create a new one with the same branch. Thank you.

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Nov 24, 2026

This branch was previously deployed

5 inactive deployments
Preview – www — 0e12b6aa Deployed Nov 23, 2026 by vercel[bot]
Preview – next-prisma-starter — 0e12b6aa Deployed Nov 23, 2026 by vercel[bot]
Preview – trpc-next-app-dir — 0e12b6aa Deployed Nov 23, 2026 by vercel[bot]
Preview – examples-next-minimal-starter — 0e12b6aa Deployed Nov 23, 2026 by vercel[bot]
Preview – examples-todomvc — 0e12b6aa Deployed Nov 23, 2026 by vercel[bot]
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants