Skip to content

fix(openapi3): Validate named multipart schema components - #12545

Open
Timothee Guerin (timotheeguerin) wants to merge 3 commits into
microsoft:mainfrom
timotheeguerin:fix/openapi3-multipart-component-validation
Open

Timothee Guerin (timotheeguerin) wants to merge 3 commits into
microsoft:mainfrom
timotheeguerin:fix/openapi3-multipart-component-validation

Conversation

@timotheeguerin

Copy link
Copy Markdown
Member

Named multipart bodies bypass component-key validation and can silently overwrite each other or a regular schema with the same component name.

A multipart model named Upload/Form now emits Upload_Form and a matching $ref, with the existing invalid-key warning. Duplicate component keys produce an error; reusing the same multipart model remains valid.

Extracted from #12505 so these existing-behavior fixes can merge before configurable component naming. This PR adds no naming options.

@pkg-pr-new

pkg-pr-new Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

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

commit: 933d5c1

@github-actions

Copy link
Copy Markdown
Contributor

All changed packages have been documented.

  • ✅ @typespec/openapi3
Show changes

@typespec/openapi3 - fix ✏️

Validate named multipart schema component keys and report duplicate keys consistently, including with the default naming strategy.

@azure-sdk-automation

azure-sdk-automation Bot commented Nov 11, 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

No active review issues block the multipart component-key validation fix.

No open issues 🎉

What changed in this PR

This PR fixes component-key validation for named multipart schemas in the OpenAPI 3 emitter, without adding naming options.

Changes:

  • Sanitizes invalid multipart component keys before generating matching references.
  • Reports collisions with other multipart or regular schemas while allowing reuse of the same multipart model.
  • Adds regression tests and a fix changelog entry.
File Description
packages/​openapi3/​test/​multipart.test.ts Tests key sanitization, collisions, and repeated model references.
packages/​openapi3/​src/​openapi.ts Validates multipart keys and tracks names to detect schema collisions.
.chronus/​changes/​feat-openapi3-component-naming-2026-10-6-11-13-33.md Documents the multipart component-key validation fix.

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 19, 2026 14:16

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.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

2 open issues

Review effort: Lite

Comment on lines +1425 to 1441
let name =
"name" in body.type && body.type.name !== ""
? getOpenAPITypeName(program, body.type, typeNameOptions)
: undefined;
if (name !== undefined) {
name = ensureValidComponentFixedFieldKey(program, body.type, name);
if (name) {
const existing = multipartSchemaTypes.get(name);
if (existing && existing !== body.type) {
checkDuplicateTypeName(program, body.type, name, root.components!.schemas!);
}
multipartSchemaTypes.set(name, body.type);
}
}
if (name) {
root.components!.schemas![name] = schema;
}
Comment on lines 1851 to +1855
for (const declaration of declarations) {
const multipartType = multipartSchemaTypes.get(declaration.name);
if (multipartType) {
checkDuplicateTypeName(program, multipartType, declaration.name, schemas);
}

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