-
Notifications
You must be signed in to change notification settings - Fork 325
fix(openapi3): use escaped string literals in object values to prevent triple-quote syntax errors #9236
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…t triple-quote issues Co-authored-by: baywet <[email protected]>
Co-authored-by: baywet <[email protected]>
Co-authored-by: baywet <[email protected]>
commit: |
| * Render a TypeSpec string literal for use in object literal values. | ||
| * Always uses escaped single-line format to avoid issues with nested triple-quotes. | ||
| */ | ||
| export function escapedStringLiteral(value: string): string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is the difference with the function above?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this method accounts for backslashes, additional "blankspace characters" (t, r).
Even though copilot made this change, I didn't "nudge" it to change the function above because I was worried that it would have a larger impact than anticipated. Happy to refactor.
Another thing we'd need to fix for is the presence of triple double quotes """ in the string literal (in the original method)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just pushed changes to the main method, let me know if you need me to change anything else.
Signed-off-by: Vincent Biret <[email protected]>
Signed-off-by: Vincent Biret <[email protected]>
|
All changed packages have been documented.
Show changes
|
Extension properties containing multi-line strings (e.g., JSON examples with embedded triple-quotes) were converted using TypeSpec's triple-quoted string format, causing syntax errors when the content itself contained
""".Changes
escapedStringLiteral()function incommon.tsthat always uses single-line format with proper escaping of newlines, quotes, backslashes, and template literal syntaxnormalizeObjectValueToTSValueExpression()indecorators.tsto use escaped literals for all string values in object literals instead of auto-selecting triple-quoted formatExample
Given an OpenAPI extension with JSON content containing Python docstrings:
Before: Invalid syntax with nested triple-quotes
After: Valid escaped string literal
example: "{\n \"source\": \"\"\"\ndef grade():\n \"\"\"Returns 1.0\"\"\"\n return 1.0\n\"\"\",\n}\n"Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
telemetry.astro.build/usr/local/bin/node node /home/REDACTED/work/typespec/typespec/website/node_modules/.bin/../astro/astro.js build sh nts/�� ebsite/src/content/docs/docs/emitters/openapi3/reference node /.bin/sh -p . ents/reference node js lmstxt --output-dir ../../websit--output-dir node(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.