Skip to content

fix(json-schema): report invalid prefixItems arguments instead of crashing - #12330

Merged
Timothee Guerin (timotheeguerin) merged 1 commit into
microsoft:mainfrom
timotheeguerin:fix/json-schema-prefix-items
Oct 26, 2026
Merged

Timothee Guerin (timotheeguerin) merged 1 commit into
microsoft:mainfrom
timotheeguerin:fix/json-schema-prefix-items

Conversation

@timotheeguerin

Copy link
Copy Markdown
Member

@prefixItems(string[]) passes decorator argument checking but crashes the JSON Schema emitter while iterating its prefix types.

Reject non-tuple arguments at the decorator with a diagnostic pointing to the argument. Valid tuples such as @prefixItems([string, int32]) retain their existing output.

Fixes #4742

@pkg-pr-new

pkg-pr-new Bot commented Oct 21, 2026

Copy link
Copy Markdown

Open in StackBlitz

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

commit: cdd89eb

@github-actions

Copy link
Copy Markdown
Contributor

All changed packages have been documented.

  • ✅ @typespec/json-schema
Show changes

@typespec/json-schema - fix ✏️

Report a diagnostic instead of crashing when @prefixItems receives an array type rather than a tuple.

@azure-sdk-automation

azure-sdk-automation Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

You can try these changes here

🛝 Playground 🌐 Website 🛝 VSCode Extension

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.

🟢 Approval recommended

The focused guard prevents invalid state, preserves tuple handling, and includes regression coverage with no identified blocking issues.

No open issues 🎉

What changed in this PR

Fixes JSON Schema’s @prefixItems crash by rejecting non-tuple arguments while preserving valid tuple behavior.

Changes:

  • Validates arguments before storing prefix items and reports a targeted diagnostic.
  • Adds regression coverage for array arguments.
  • Includes a package changelog entry.
File Description
packages/​json-schema/​test/​arrays.test.ts Tests rejection of array arguments.
packages/​json-schema/​src/​lib.ts Defines the invalid-argument diagnostic.
packages/​json-schema/​src/​decorators.ts Guards against non-tuple arguments.
.chronus/​changes/​fix-json-schema-prefix-items-2026-10-21.md Documents the crash fix.

Review effort: Balanced

Merged via the queue into microsoft:main with commit 1913f60 Oct 26, 2026
34 checks passed
@timotheeguerin
Timothee Guerin (timotheeguerin) deleted the fix/json-schema-prefix-items branch October 26, 2026 16:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Json schema @prefixItems allow array to be passed and crash

3 participants