Skip to content
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

webpack documentation #321

Open
airedwin opened this issue Jul 14, 2022 · 3 comments
Open

webpack documentation #321

airedwin opened this issue Jul 14, 2022 · 3 comments
Labels
pinned Issues that will not be automatically closed

Comments

@airedwin
Copy link

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

@daniloab daniloab added the pinned Issues that will not be automatically closed label Jul 18, 2022
@daniloab
Copy link
Collaborator

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.

@airedwin
Copy link
Author

airedwin commented Jul 18, 2022

@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

@YUEJINYUAN
Copy link

YUEJINYUAN commented May 6, 2023

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;
},
},
}),
],
},

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pinned Issues that will not be automatically closed
Projects
None yet
Development

No branches or pull requests

3 participants