-
Notifications
You must be signed in to change notification settings - Fork 22
feat(openapi-generator): take and parse @example tags on JSDoc #753
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
Conversation
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.
Please re-word the commit message to use feat(openapi-generator) rather than feature(openapi-generator) since the latter won't be picked up by semantic-release.
| summary?: string; | ||
| description?: string; | ||
| tags?: Record<string, string>; | ||
| tags?: Record<string, string> & { example?: unknown }; |
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.
Technically this is unsound since example is a possible key of the record type so the final type should be the intersection of string & unknown which is just string
However, the compiler does treat this in the intended manner of "example could be anything, all other properties are strings". If you want the type to be more accurate you could write Record<Exclude<string, 'example'>, string> & { example?: unknown } but it doesn't appear to make a difference in practice.
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.
Good catch! I changed it in the declaration as requested
| * | ||
| * @example { | ||
| * "test": "foo" | ||
| * } |
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.
Can we add a test for tags that come after a multi-line example?
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.
Added!
d74ee90 to
921e204
Compare
921e204 to
9da14c6
Compare
|
🎉 This PR is included in version @api-ts/openapi-generator@3.6.0 🎉 The release is available on npm package (@latest dist-tag) Your semantic-release bot 📦🚀 |
|
🎉 This PR is included in version @api-ts/express-wrapper@1.0.26 🎉 The release is available on npm package (@latest dist-tag) Your semantic-release bot 📦🚀 |
|
🎉 This PR is included in version @api-ts/superagent-wrapper@1.2.1 🎉 The release is available on npm package (@latest dist-tag) Your semantic-release bot 📦🚀 |
|
🎉 This PR is included in version @api-ts/typed-express-router@1.1.6 🎉 The release is available on npm package (@latest dist-tag) Your semantic-release bot 📦🚀 |
|
🎉 This PR is included in version @api-ts/io-ts-http@3.1.0 🎉 The release is available on npm package (@latest dist-tag) Your semantic-release bot 📦🚀 |
The OpenAPI generator module will now accept
@exampletags in the JSDoc, which will translate into OpenAPI examples.They may be used in the route definition to declare a response example, or in a schema definition to declare a schema usage example
Usage:
Schema definition
Given the following JSDoc schema definition
The resulting YAML declaration will be
Endpoint definition
Given the following endpoint definition
The resulting YAML declaration will be