swagger-jsdoc-sync-webpack-plugin
v1.1.0
Published
Webpack plugin updating the swagger specification based on imported files
Downloads
164
Readme
swagger-jsdoc-sync-webpack-plugin
Webpack plugin updating the swagger specification based on imported files.
Installing / Getting started
- Install
swagger-jsdoc-sync-webpack-plugin
.
yarn add --dev swagger-jsdoc-sync-webpack-plugin
- 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,
}),
],
};
- 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
'sswaggerDefinition
option - see their documentation). - [prettyJson] (boolean) - If
true
, will pretty print theswagger.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 theswagger.json
on swagger parsing error. Default behaviour is false, the bundle is not emitted either.
Tests
yarn test