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.42k stars 225 forks source link

Add the ability to override the htmlTemplate #229

Closed KenEucker closed 2 years ago

KenEucker commented 3 years ago

I am currently working through CSP on a site and have run into a problem with my swagger-ui page and not being able to edit the template. To overcome the limitations of CSP, I have implemented nonces for all inline resources. To address this on my swagger-ui-express page, I would need a mechanism for adding the nonce to the script and style tags.

Is there any way that I can do accomplish this, currently?

scottie1984 commented 3 years ago

Currently you can add custom CSS https://www.npmjs.com/package/swagger-ui-express#custom-css-styles and custom JS https://www.npmjs.com/package/swagger-ui-express#custom-js

Any beyond that currently is not possible. Happy to accept a PR for anything extra.

KenEucker commented 3 years ago

@scottie1984 unfortunately, it's the inline styles on the HTML template that cause the errors. This doesn't actually block the functionality from the javascript of swagger-ui, like I had originally thought, so this is only impacting a few styles and fonts.

I will look into creating a PR in the coming month and follow the same rubric you have set up for the custom CSS and JS, and name it to follow. Thanks for contributing to FOSS!