-
Notifications
You must be signed in to change notification settings - Fork 0
Add HTTP API docs markdown emitter with literal type support #2
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
…documentation Co-authored-by: johanste <15110018+johanste@users.noreply.github.com>
Co-authored-by: johanste <15110018+johanste@users.noreply.github.com>
Co-authored-by: johanste <15110018+johanste@users.noreply.github.com>
…ter type resolution and example generation Co-authored-by: johanste <15110018+johanste@users.noreply.github.com>
| * - Escapes pipe characters so they don't break column boundaries | ||
| */ | ||
| function escapeForTable(value: string): string { | ||
| return value.replace(/\r?\n/g, "<br>").replace(/\|/g, "\\|"); |
Check failure
Code scanning / CodeQL
Incomplete string escaping or encoding High
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI about 15 hours ago
In general, to correctly escape strings for a markdown table cell, you must escape all characters that have special meaning in that context, including the backslash itself. If you escape | but not \, then any existing backslashes can change how following characters are interpreted (e.g. \| could become a literal | again), so the escaping is incomplete.
The best targeted fix is to extend escapeForTable so that it first escapes all backslashes by doubling them, then applies the existing transformations: converting newlines to <br> and escaping | as \|. The order matters: we must escape \ before introducing any new backslashes (like the ones used to escape |), so we don’t re‑escape them or alter the intended sequences. Concretely, in packages/http-api-docs/src/emitter.ts, update escapeForTable at line 401 to:
- First replace all
\with\\using a global regex. - Then replace newlines with
<br>. - Then escape
|with\|.
No new imports or helpers are required; this is a simple change to the existing one‑liner.
-
Copy modified line R397 -
Copy modified line R402
| @@ -394,11 +394,12 @@ | ||
| } | ||
|
|
||
| /** Escape content for use inside a markdown table cell. | ||
| * - Escapes backslashes so they are rendered literally | ||
| * - Replaces newlines with `<br>` to keep the row on one line | ||
| * - Escapes pipe characters so they don't break column boundaries | ||
| */ | ||
| function escapeForTable(value: string): string { | ||
| return value.replace(/\r?\n/g, "<br>").replace(/\|/g, "\\|"); | ||
| return value.replace(/\\/g, "\\\\").replace(/\r?\n/g, "<br>").replace(/\|/g, "\\|"); | ||
| } | ||
|
|
||
| /** Return an extra description for types that lose information when shown as |
New
@typespec/http-api-docsemitter that generates markdown reference documentation for HTTP-based TypeSpec services, including synthetic JSON request/response examples.Emitter (
packages/http-api-docs)HttpService/HttpOperationvia@typespec/http, emits structured markdown with service metadata, operation signatures, parameter tables, request/response body examples, and property documentation{service-name}interpolation in output filenameType resolution and example generation
Handles all TypeSpec type kinds including literal types (
"String","Number","Boolean"), which are distinct from their scalar counterparts:Build integration
tsconfig.ws.jsonproject references for watch/incremental buildspnpm build:all(workspace glob) andpnpm test(vitest project glob)Test coverage
19 tests covering service titles, HTTP verbs, path/query parameters, request/response bodies, nested models, arrays, enums, optional properties, date/boolean scalars, multi-operation APIs,
@docpropagation, and string/numeric/boolean literal types.💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.