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

Can you provide an example of using the swaggerUiBundleBasePath property? #73

Open
jelche opened this issue Jan 12, 2021 · 3 comments
Open

Comments

@jelche
Copy link

jelche commented Jan 12, 2021

I need to be able to use the Swagger-UI and validation on a closed network and as such need to provide the static files. However when I follow what is in the READMe I get 404 responses. Here is how I've implemented the option:

const swaggerUiAssetPath = require("swagger-ui-dist").getAbsoluteFSPath();

const oasMw = await oas({
  file: `${__dirname}/../openapi.yaml`,
  swaggerUiBundleBasePath: swaggerUIAssetPath,
  endpoint: '/openapi.json',
  uiEndpoint: '/'
});


Is this the expected usage?

The only way I can seem to get it to work otherwise is to serve up the static files:

const serve = require('koa-static')
const swaggerUIAssetsPath = './node_modules/swagger-ui-dist'

app.use(serve(swaggerUIAssetsPath))

const oasMw = await oas({
  file: `${__dirname}/../openapi.yaml`,
  swaggerUiBundleBasePath: require(swaggerUIAssetsPath),
  endpoint: '/openapi.json',
  uiEndpoint: '/'
});

@ToucanBran
Copy link

I'm having the same issue, hopefully this will get answered at some point...

@FelipeMartinez10
Copy link

Any solution for this?

@supertong
Copy link
Collaborator

Hey folks, sorry for the late reply.
The workaround solution provided by @jelche is correct. If you check into how is it being used in the code, it's simply assigning that value to the href which would require to be an endpoint that can be served from the backend.

  <meta charset="UTF-8">
  <base href="${cfg.swaggerUiBundleBasePath}">
  <title>${cfg.title || 'Swagger UI'}</title>

let me know your ideas.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants