-
-
Notifications
You must be signed in to change notification settings - Fork 211
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
feat: pass swagger-ui additional configuration #351
Conversation
The final configuration passed to the Swagger UI is composed by merging sequentially:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Commit message for 9d96c34 should be test
, not feat
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good work!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
I get stuck in your option 1 when I see this feature request. My other consideration was CSP, but updating the index.html
in npm run prepare
is a good solution without affecting CSP.
Good Approach.
Just a suggest, will you consider replacing the whole block of |
Yeah, that can do 😄 |
@giovanni-bertoncelli so we are waiting for a bit more change. |
Yes. I'll replace the <script> and the package json in the next days.. |
Ok. I've:
(Sorry for the double github account, they are both mine) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
Any chance that this will be released soon? :) |
Releasing 👍 |
Sorry, I've seen the release but downloading with |
mmm the script was updated and it seems the pre-publish did not run: Line 7 in 9d87a5f
I can release a fix this evening CEST if someone can't do it earlier |
Ok @Eomm is there any error in the package.json definition then? |
I've released v4.1.1, try that. |
Yeah, now it's fine 🤷🏻♂️ |
Porpouse
This PR allows to pass a dynamic configuration to the generated swagger UI. The option that should be used in the plugin configuration in order to accomplish that is
uiConfig
.Configuration docs: https://github.com/swagger-api/swagger-ui/blob/master/docs/usage/configuration.md
Implementation
Since there is an issue configuring
swagger-ui-dist
(that distributes only static files, see swagger-api/swagger-ui#5710) without changing the content of the static assets, the only way to configure the UI with a dynamic external configuration is by editing theindex.html
file and the script within that loads the swagger ui in the page.There were two approaches:
index.html
request on the documentation routes and distributing an altered html file that load swagger UI with the configuration merged with the one passed by the user.index.html
when the project gets prepared (npm run prepare
) in order to retrieving a remote configuration fetched through an XHR request on a designated endpoint.Since the index.html file was already edited in the prepare stage I went for the second approach. Now a new route under
GET documentation/uiConfig
gets declared and returns the final ui configuration and the script inside the index page fetches the configuration from that endpoint. Finally the page loads the swagger ui from the given configuration.Drawbacks
Since there is no way to serialize functions over HTTP and JSON there is no way to pass functions to the parameters of the
uiConfig
, so only string/object/number configuration keys will be effective. Neither the first alternative implementation allowed to do that (at least without writing the plain function in the HTML file). However I think this is a fair compromise.Related issues
Others
The
npm run test
didn't run all the test inside the foldertest/
since the regex in the command was working only at the first directory level. Now it runs all the test till the 3rd directory level.Checklist
npm run test
andnpm run benchmark
and the Code of conduct