Skip to content

openapi3: emit minItems/maxItems on tuple types - #12165

Open
Adam Hooper (ddadamhooper) wants to merge 1 commit into
microsoft:mainfrom
ddadamhooper:openapi3-tuple-length
Open

Adam Hooper (ddadamhooper) wants to merge 1 commit into
microsoft:mainfrom
ddadamhooper:openapi3-tuple-length

Conversation

@ddadamhooper

Copy link
Copy Markdown
Contributor

TL;DR #11893 for OpenAPI3

JSONSchema prefixItems doesn't constrain the length of an array. But tuple types do.

alias Tuple = #[string, number];

This PR changes the OpenAPI3 generator so generated JSONSchema won't accept 1-element or 3-element arrays.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
1 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI 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.

🟡 Changes recommended

Valid empty tuples lack coverage ensuring zero-valued bounds are preserved.

1 open finding
What changed in this PR

Fixes OpenAPI tuple schemas to enforce exact tuple lengths.

Changes:

  • Emits matching minItems and maxItems for tuples.
  • Updates OpenAPI 3.0–3.2 tuple expectations.
  • Adds an @typespec/openapi3 fix changelog.
File Description
packages/​openapi3/​src/​schema-emitter.ts Adds fixed lengths for OpenAPI 3.0 tuples.
packages/​openapi3/​src/​schema-emitter-3-1.ts Adds fixed lengths for OpenAPI 3.1/3.2 tuples.
packages/​openapi3/​test/​array.test.ts Updates tuple schema assertions.
.chronus/​changes/​tuple-openapi3-fixed-length-2026-8-9-13-1-9.md Records the bug fix.

🧠 Review effort: Balanced


💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +848 to +849
const size = tuple.values.length;
return { type: "array", items: {}, minItems: size, maxItems: size };
@pkg-pr-new

pkg-pr-new Bot commented Oct 13, 2026

Copy link
Copy Markdown

Open in StackBlitz

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

commit: 63ee8f3

@github-actions

Copy link
Copy Markdown
Contributor

All changed packages have been documented.

  • ✅ @typespec/openapi3
Show changes

@typespec/openapi3 - fix ✏️

Emit minItems and maxItems for tuple types so generated schemas enforce the tuple's exact length.

This branch has not been deployed

No deployments
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.

2 participants