scottie1984 / swagger-ui-express

Adds middleware to your express app to serve the Swagger UI bound to your Swagger document. This acts as living documentation for your API hosted from within your app.
MIT License
1.43k stars 228 forks source link

Your project is unusable #347

Open CharlesOnAir opened 1 year ago

CharlesOnAir commented 1 year ago

Capture d'écran 2023-06-07 101850

joaocasarin commented 1 year ago

up, I face the same error.

in my case it works while i am still coding with typescript, but after i transpile the code to javascript to a folder dist/, the swagger simply doesn't work anymore.

Pridestalkerr commented 1 year ago

Same here. It works when I bundle my project with tsup, but fails with esbuild. Can probably provide some more information if needed to debug this. I believe it's probably an issue with the bundler and not the library itself.

paras-verma commented 1 year ago

this package uses swagger-ui-dist which contains the static UI assets (CSS & JS)

it serves those assets directly from inside the node_modules using the method getAbsoluteFSPath exported by swagger-ui-dist

so you may face issues during bundling as these assets aren't explicitly imported, hence the 404 issues (@joaocasarin)

Falven commented 1 year ago

pnpm install -D swagger-ui-dist

import { copy } from 'esbuild-plugin-copy';

copy({
      assets: [
        {
          from: ['./node_modules/swagger-ui-dist/swagger-ui-bundle.js'],
          to: 'SwaggerUIBundle.js',
        },
        {
          from: ['./node_modules/swagger-ui-dist/swagger-ui-standalone-preset.js'],
          to: 'SwaggerUIStandalonePreset.js',
        },
      ],
    }),