fix(plugin): allow Topbar plugin to read url param on load #8168
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
The
Topbar
plugin manipulates the querystring param, addingurls.primaryName
to track the selected spec. If you havequeryConfigEnabled
set to true, you can use this to link directly to a specific spec (e.g.my-swagger-ui.com/?urls.primaryName=MyChosenSpec
), and the plugin will load that named spec from your config.If you have
queryConfigEnabled
set to false - which seems like the recommended option to prevent some security issues (GHSA-qrmm-w75w-3wpx) - this functionality no longer works.In this PR, I update
componentDidMount
to check the querystring directly, with a fallback to the config. I believe this is safe since the param is the name of a configured URL, not an arbitrary URL. And this allows users who don't enable query config to still benefit from the direct linking feature.Motivation and Context
Fixes #8039
Fixes #7835
How Has This Been Tested?
I built this change locally, referenced the built files in a local project, and noted that the intended API spec is loaded.
I didn't find any existing unit tests for the Topbar or integration tests for this
?urls.primaryName
behavior.Checklist
My PR contains...
src/
is unmodified: changes to documentation, CI, metadata, etc.)package.json
)My changes...
Documentation
Automated tests