Skip to content

fix(openapi3): emit uniqueItems on operation parameter schemas#10656

Merged
timotheeguerin merged 1 commit into
microsoft:mainfrom
dschmidt:fix/openapi3-uniqueitems-parameter-propagation
May 13, 2026
Merged

fix(openapi3): emit uniqueItems on operation parameter schemas#10656
timotheeguerin merged 1 commit into
microsoft:mainfrom
dschmidt:fix/openapi3-uniqueitems-parameter-propagation

Conversation

@dschmidt
Copy link
Copy Markdown

@dschmidt dschmidt commented May 12, 2026

@JsonSchema.uniqueItems is currently a no-op when applied to query, path or header parameters in @typespec/openapi3. The body schema-emitter applies it via applyConstraint(jsonSchemaModule.getUniqueItems, ...) in schema-emitter.ts, but parameter schemas go through applyIntrinsicDecorators in openapi.ts, which never consulted the optional jsonSchemaModule. Arrays declared inline on operation parameters therefore lost the constraint between source TypeSpec and the emitted OpenAPI.

op listUsers(
  @query
  @JsonSchema.uniqueItems
  `$select`?: ("id" | "displayName")[],
): User[];

Before this PR the emitted schema for $select was { type: array, items: { ... } }. After, it is { type: array, uniqueItems: true, items: { ... } } — which matters in practice because the openapi-generator typescript-axios template renders that as Set<EnumX> instead of Array<EnumX>.

The same patch also tightens the useStateMap generic for uniqueItems in @typespec/json-schema from the implicit unknown to boolean, matching every other state-backed decorator in the compiler so the openapi3 emitter can consume getUniqueItems without a cast.

@dschmidt
Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 12, 2026

Open in StackBlitz

npm i https://pkg.pr.new/@typespec/json-schema@10656
npm i https://pkg.pr.new/@typespec/openapi3@10656

commit: c8a9565

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 12, 2026

All changed packages have been documented.

  • @typespec/json-schema
  • @typespec/openapi3
Show changes

@typespec/openapi3 - fix ✏️

Propagate @JsonSchema.uniqueItems to query, path and header parameter schemas. The decorator was only applied to body model property schemas; for HTTP parameter schemas (which go through applyIntrinsicDecorators) it was silently dropped, so arrays declared on operation parameters never emitted uniqueItems: true even when the decorator was present.,> ,> tsp,> op listUsers(,> @query,> @JsonSchema.uniqueItems,> $select?: ("id" | "displayName")[],,> ): User[];,>

@typespec/json-schema - internal ✏️

Add the explicit <Type, boolean> generic to the useStateMap call backing @uniqueItems, matching the convention used by every other state-backed decorator in the compiler. This makes getUniqueItems return boolean | undefined rather than unknown | undefined and lets downstream emitters consume the value without a cast.

`@JsonSchema.uniqueItems` on a query / path / header parameter was
silently dropped: the body schema-emitter applies it via
`applyConstraint(jsonSchemaModule.getUniqueItems, ...)`, but the
parameter schema path goes through `applyIntrinsicDecorators` in
`openapi.ts` which never consulted the optional `jsonSchemaModule`.
As a result `uniqueItems: true` only ever showed up on body model
properties, and arrays declared inline on parameters lost the
constraint between the source TypeSpec and the emitted OpenAPI.

This also tightens the `useStateMap` generic in `@typespec/json-schema`
to `<Type, boolean>`, matching the convention used by every other
state-backed decorator in the compiler so callers (including the
openapi3 emitter) can consume the value without a cast.
@dschmidt dschmidt force-pushed the fix/openapi3-uniqueitems-parameter-propagation branch from c21dc30 to c8a9565 Compare May 13, 2026 10:54
Copy link
Copy Markdown
Member

@timotheeguerin timotheeguerin left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution

@timotheeguerin timotheeguerin enabled auto-merge May 13, 2026 14:42
@timotheeguerin timotheeguerin added this pull request to the merge queue May 13, 2026
Merged via the queue into microsoft:main with commit 6f7bc59 May 13, 2026
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

emitter:json-schema emitter:openapi3 Issues for @typespec/openapi3 emitter

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants