1.1.0 • Published 5 years ago

swagger-jsdoc-sync-webpack-plugin v1.1.0

Weekly downloads
35
License
MIT
Repository
github
Last release
5 years ago

swagger-jsdoc-sync-webpack-plugin

Webpack plugin updating the swagger specification based on imported files.

Installing / Getting started

  1. Install swagger-jsdoc-sync-webpack-plugin.
yarn add --dev swagger-jsdoc-sync-webpack-plugin
  1. Add the plugin in webpack configuration.
const SwaggerJsdocSyncWebpackPlugin = require('swagger-jsdoc-sync-webpack-plugin');
// webpack.config.js
module.exports = {
  plugins: [
    new SwaggerJsdocSyncWebpackPlugin({
      // Swagger specification metadata.
      swagger: {
        openapi: '3.0',
        info: {
          title: 'My API',
          version: require('./package.json').version,
          description: 'What my API does.',
        },
      },

      // Print the swagger.json readably.
      prettyJson: true,
    }),
  ],
};
  1. Use JSDoc to define your swagger definion in your code using @swagger tag. Do not forget to import every file that has swagger definitions.
/**
 * @swagger
 *
 * components:
 *   schemas:
 *     MyEntity:
 *       type: object
 *       required:
 *         - id
 *         - name
 *       properties:
 *         id:
 *           type: string
 *           description: Technical unique id.
 *         name:
 *           type: string
 *           description: Entity name.
 *         description:
 *           type: string
 *           description: Entity description.
 */

The created file will be swagger.json inside the output folder.

Options

  • swagger (Object) - Swagger definition (equivalent to swagger-jsdoc's swaggerDefinition option - see their documentation).
  • prettyJson (boolean) - If true, will pretty print the swagger.json file.
  • filename='swagger.json' (string) - Swagger specification output filename (relative to compilation output folder).
  • emitWarningOnError=false (boolean) - If true, will emit the bundle but not the swagger.json on swagger parsing error. Default behaviour is false, the bundle is not emitted either.

Tests

yarn test
1.1.0

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago