fastify / fastify-swagger-ui

Serve Swagger-UI for Fastify
MIT License
125 stars 38 forks source link

Allow the swagger-ui url to be customised further #117

Closed knolleary closed 3 days ago

knolleary commented 6 months ago

Prerequisites

🚀 Feature Proposal

@fastify/swagger-ui provides the routePrefix option that allows you to modify the default route prefix of /documentation. For example: /api-docs. This allows some level of customisation.

However, when you browse to the routePrefix, the plugin is hardcoded to redirect you to /api-docs/static/index.html.

I would like the swagger ui to be served from /api-docs/ without that redirection.

Is there a specific reason or limitation with the swagger-ui that requires this redirection? There may be some subtle aspects on how swagger-ui expects to load its own static assets that make this hard than it sounds.

I don't have a specific proposal at this stage for how this behaviour would be enabled in the configuration - most likely a boolean flag to disable the redirect... although what that gets called is open to suggestion.

Motivation

My main motivation here is trying to keep our application's URls consistent and tidy.

We don't use index.html in the path for any of our routes - I'd prefer the swagger-ui follows what we have elsewhere.

Example

No response

mcollina commented 6 months ago

Thanks for reporting! Would you like to send a Pull Request to address this issue? Remember to add unit tests.

jdhollander commented 2 months ago

Thanks for reporting! Would you like to send a Pull Request to address this issue? Remember to add unit tests.

I've made a pull request #144 that implements this feature. I'd be grateful to those in this thread to see what they think.