swagger-jsdoc icon indicating copy to clipboard operation
swagger-jsdoc copied to clipboard

webpack documentation

Open airedwin opened this issue 1 year ago • 3 comments

Is your feature request related to a problem? Please describe. Is there an examples on how to get this working with webpack? I'm always getting the "No Operations Defined in Spec!" when I build with webpack. I think it is due to the path I specify options.apis isn't correct for webpack?

Describe the solution you'd like An example using webpack

Describe alternatives you've considered None

Additional context None

airedwin avatar Jul 14 '22 22:07 airedwin

Hi @airedwin can you share how are configuring the swagger-jsdoc with webpack?

This error is commonly related with some mismatch on configuration specs and paths.

daniloab avatar Jul 18 '22 13:07 daniloab

@daniloab I got it working by having two configs, for local dev (no webpack build) I use the swagger-jsdoc object or whatever and for production (webpack bundling) i use a swagger.json that I generate at build time script with swagger-jsdoc cli ("swagger": "node ./node_modules/swagger-jsdoc/bin/swagger-jsdoc.js -d ./swagger/definition.cjs ./routes/routes.js -o swagger.json" so i do npm run swagger then npm run build for example

it would be nice if i didn't have to do that my directory set up is ./api/src/webpack.config.js and my routes are in ./api/src/routes/routes.js in the options i'm using apis: ['./api/src/routes/routes.js'] which works when starting npm from the root "serve-api": "node ./api/src/server.js" "start": "concurrently --kill-others \"npm run serve-api-dev\" \"npm run serve\"" but does not work when webpack is built, i'm assuming because my routes.js and the comments don't exist after webpack bundles

airedwin avatar Jul 18 '22 14:07 airedwin

keep same path with index.js => swaggerOptions.api, and you can find path in swagger

webpack.config.js:

optimization: { // minimize: true, minimizer: [ new TerserPlugin({ extractComments: { // keep same path with index.js => swaggerOptions.api condition: /^**!|@swagger/i, filename: (fileData) => { // The "fileData" argument contains object with "filename", "basename", "query" and "hash" return ./controller/swaggerComments.js; }, }, }), ], },

YUEJINYUAN avatar May 06 '23 09:05 YUEJINYUAN