Surface operation parameter examples in generated type JSDoc#253
Conversation
openapi-typescript builds a parameter's JSDoc from the parameter object rather than its nested schema, so operation parameter examples never reached the generated types. Hoist each parameter's schema example (also unwrapping array items) up to the parameter level so client method params carry an @example tag.
Fold the JSON Schema `examples` array into the `@example` tag that openapi-typescript emits (it only reads the singular `example` keyword), and propagate examples across $ref properties like descriptions already are. Multiple examples render as separate `@example` tags (the JSDoc convention); array/object example values are emitted as compact one-line JSON.
🦋 Changeset detectedLatest commit: 0496075 The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Coverage report
Test suite run success76 tests passing in 9 suites. Report generated by 🧪jest coverage report action from 0496075 Show full coverage report
|
Rename generate.mjs to generate.mts and add explicit types. Run it via Node's native type stripping (node generate.mts), which requires Node >=22.6 — noted in contributing.md. Output is unchanged; the published SDK and CI are unaffected.
There was a problem hiding this comment.
Pull request overview
Updates the type-generation pipeline to surface OpenAPI/JSON Schema examples as JSDoc @example tags in the generated TypeScript types, including operation parameter examples that previously didn’t appear on client method parameter types.
Changes:
- Walk the parsed OpenAPI document to fold JSON Schema
examples[]intoexampleand hoist parameter schema examples onto the parameter object before runningopenapi-typescript. - Propagate
exampleacross$refproperties similarly to how descriptions are propagated. - Post-process generated output to split multiple examples into separate
@exampleJSDoc tags, and regeneratesrc/generatedApiTypes.ts.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| generate.mjs | Adds example folding/hoisting + $ref example propagation and post-processing to split multi-example tags in generated JSDoc. |
| src/generatedApiTypes.ts | Regenerated output now includes @example tags across schemas and operation parameters. |
| .changeset/jsdoc-schema-examples.md | Patch changeset entry for schema examples appearing as JSDoc @example. |
| .changeset/jsdoc-parameter-examples.md | Patch changeset entry for parameter examples appearing as JSDoc @example. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Use tsx instead of Node native type stripping so the generator runs on Node >=18.17 (the SDK's supported range), removing the temporary contributing.md caveat.
mcnulty-fp
left a comment
There was a problem hiding this comment.
Looks like the latest version of openapi-typescript adds some support for examples. Here's a draft PR with the new JSDoc based on feat/open-api-v3.4.2: #254.
So, if openapi-typescript is upgraded the workaround for multiple examples can be removed.
However, it looks like openapi-typescript still wants the example to be on the parameter object rather than the schema object so the hoisting workaround in this PR is still useful.
openapi-typescript 7.13.0 (merged via #254) now surfaces schema examples, splits multiple examples into separate @example tags, and propagates examples across $refs natively. Drop the generator logic that duplicated this (foldExamplesIntoExample for schemas, normalizeExample, serializeExample, dedentExampleTags, and $ref example propagation), keeping only operation parameter example hoisting, which openapi-typescript still ignores.
Every parameter schema in the spec carries the singular `example` keyword (and array items do too), so the `examples[]` array fallback never fires. Regenerated output is byte-identical.
Read the JSON Schema `examples` array rather than the singular `example` keyword. The schema carries `example` only as a compat duplicate for tools that can't read `examples[]`, and it may be removed upstream; `examples[]` is the stable source. Regenerated output is byte-identical.
Hoist the whole `examples` array onto the parameter object instead of a single value. openapi-typescript renders one `@example` tag per array entry, so params with multiple examples now surface all of them (previously only the first survived). Regenerated output is byte-identical for the current schema, where every parameter has a single example.
@mcnulty-fp Ah, rookie mistake not trying to just upgrade the library first 🤦 thanks for catching that! I merged your changes to main, updated this PR to keep just the hoisting workaround for query params |
🚀 Following releases will be created using changesets from this PR:@fingerprint/node-sdk@7.4.0Minor Changes
Patch Changes
|
Surface operation parameter examples in the generated type JSDoc — the one thing
openapi-typescript7.13.0 (#254) still doesn't do natively.hoistParameterExampleslifts each parameter'sexamplesarray onto the parameter object (openapi-typescript builds a param's JSDoc there, not from its nestedschema), where it renders as one@exampletag per entry. Also convertsgenerate.mjs→generate.mts.