BRIKEV / express-jsdoc-swagger

Swagger OpenAPI 3.x generator
https://brikev.github.io/express-jsdoc-swagger-docs/#/
MIT License
218 stars 30 forks source link

Add `example` property to Components #270

Open ehubbell opened 3 months ago

ehubbell commented 3 months ago

In reviewing the documentation and examples, it doesn't look like there is a way to add the example property to a Component. The OpenAPI spec supports this and several UI's rely on it to decorate response blocks. Please see the attached image for reference.

Swagger Editor Example

https://editor.swagger.io/ CleanShot 2024-07-11 at 11 13 22

As a result, the only way to decorate each response is adding an example block like so:

    /**
     * POST /login
     * @summary Login user
     * @description Login to your account
     * @param {string} email.form.required - The email address on file.
     * @param {string} password.form.required - The email address on file.
     * @tags Auth
     * @return {Session} 200 - Success - application/json
     * @example request - payload example
     * {
     *      "data": {
     *          "attributes: {
     *              "email": "user@example.com",
     *              "password": "******"
     *          }
     *      }
     * }
     */

It would be nice if we could add default or example values when defining a Component like so:

/**
 * User data
 * @typedef {object} User
 * @property {integer} [id=1] - An auto-increment identifier
 * @property {string} [status=active] - The status of the user
 * @property {string} [thumbnail=https://www.filestack.com/photo.jpg] - The thumbnail for the user
 * @property {string} [name=Steve Jobs] - The name for the user
 * @property {string} [uuid=steve-jobs] - The uuid for the user
 * @property {string} [email=steve@apple.com] - The email for the user
 * @property {string} [tagline=Innovator] - The tagline for the user
 * @property {string} [description=lorem ipsum...] - The description for the user
 */