Skip to content

fix(openapi3): escape the service title when converting from OpenAPI - #12092

Open
Alexandre Kohler (kwy404) wants to merge 2 commits into
microsoft:mainfrom
kwy404:fix/openapi3-escape-service-title
Open

Alexandre Kohler (kwy404) wants to merge 2 commits into
microsoft:mainfrom
kwy404:fix/openapi3-escape-service-title

Conversation

@kwy404

Copy link
Copy Markdown
Contributor

When converting an OpenAPI document to TypeSpec, generate-service-info.ts writes the @service title by wrapping info.title in raw double quotes (title: "${name}"). A title that contains a double quote, for example The "Pet" Store, breaks the string: the converter outputs @service(#{ title: "The ", Pet: " Store" }), which loses part of the title and fails to compile with invalid-argument. Titles with a line break or ${ also produce invalid TypeSpec today. The @info values emitted right below it already go through stringLiteral.

Fix: pass the title through the existing stringLiteral helper, which @info and @server already use and which #12050 applies to tag metadata. Titles without special characters produce the same output as before.

Test: service-info.test.ts converts a document titled The "Pet" Store, checks that the generated TypeSpec compiles and contains title: "The \"Pet\" Store". It fails on main with the invalid-argument diagnostic above and passes with the fix. All 409 tests in test/tsp-openapi3 pass.

Copilot AI balanced review requested due to automatic review settings October 1, 2026 16:11
@microsoft-github-policy-service microsoft-github-policy-service Bot added emitter:openapi3 Issues for @typespec/openapi3 emitter openapi3:converter Issues for @typespec/openapi3 openapi to typespec converter labels Oct 1, 2026
@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.

Copilot review overview

🟡 Changes recommended

Regression coverage is missing for newline and interpolation-like titles that the fix also addresses.

Review effort: Balanced
Findings: 1 Low severity

Open (1)
What changed in this PR

Fixes OpenAPI-to-TypeSpec conversion by safely encoding service titles.

Changes:

  • Uses stringLiteral for generated @service titles.
  • Adds regression coverage and a fix changelog entry.
File Description
generate-service-info.ts Escapes generated service titles.
service-info.test.ts Tests quoted titles.
.chronus/​changes/​fix-openapi3-escape-service-title-2026-8-26-20-50-0.md Documents the fix.

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

Comment thread packages/openapi3/test/tsp-openapi3/service-info.test.ts
Copilot AI balanced review requested due to automatic review settings October 1, 2026 16:26

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.

Copilot review overview

🟢 Approval recommended

The targeted fix uses the established escaping helper and includes meaningful regression coverage.

Review effort: Balanced
Findings: None

Resolved since last review (1)

@pkg-pr-new

pkg-pr-new Bot commented Oct 1, 2026

Copy link
Copy Markdown

Open in StackBlitz

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

commit: f21f76b

@github-actions

github-actions Bot commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

All changed packages have been documented.

  • ✅ @typespec/openapi3
Show changes

@typespec/openapi3 - fix ✏️

[converter] Escape quotes in the @service title generated from the OpenAPI info.title.

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 openapi3:converter Issues for @typespec/openapi3 openapi to typespec converter

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants