Surnet / swagger-jsdoc

Generates swagger/openapi specification based on jsDoc comments and YAML files.
MIT License
1.66k stars 224 forks source link

Globbing a directory that looks like a file causes crash. #388

Closed Lomilar closed 4 months ago

Lomilar commented 6 months ago

Describe the bug Globbing a directory in the apis causes a crash in the swagger module.

To Reproduce

swaggerJsdoc({
    apis: ['./src/**/*.js'],
})

When the above code is used and comes across a node_modules that includes asn1.js (https://www.npmjs.com/package/asn1.js), a crash occurs.

Error: EISDIR: illegal operation on a directory, read
  at Object.readFileUtf8 (node:internal/fs/sync:25:18)
  at Object.readFileSync (node:fs:441:19)
  at extractAnnotations (/app/node_modules/swagger-jsdoc/src/utils.js:54:26)
  at build (/app/node_modules/swagger-jsdoc/src/specification.js:200:9)

To repro, create a directory called src/foo/asn1.js in the above path and run the above swagger method.

Expected behavior No crash, presumably through detecting whether something is not a directory before opening it.

Screenshots See error.

Desktop (please complete the following information): In node:20 docker container.

Additional context None.

stale[bot] commented 4 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

ralphstodomingo commented 4 months ago

Just had this occur to me - swagger-jsdoc worked locally but then upon building with esbuild, the server crashes silently, took some time debugging only to find the same thing @Lomilar found.