fix(spec): clear scheme state when loading a new spec url#10862
Open
yogeshwaran-c wants to merge 1 commit into
Open
fix(spec): clear scheme state when loading a new spec url#10862yogeshwaran-c wants to merge 1 commit into
yogeshwaran-c wants to merge 1 commit into
Conversation
When a user loaded a new spec URL via the TopBar (or by calling specActions.updateUrl), the previously selected scheme — stored under state.scheme._defaultScheme by the Schemes component while the prior spec was active — was retained. The operationScheme selector falls back to that value when the freshly loaded spec does not declare schemes, so "Try it out" silently issued requests under https for HTTP-only specs and vice versa, even though the displayed URL was correct. Reset the scheme branch on UPDATE_URL whenever the URL actually changes. This keeps existing behavior for repeated dispatches with the same URL (config refreshes, programmatic re-issues) and lets the new spec compute its scheme from the spec's own schemes list, the Schemes component's first option, or the URL fallback. Closes swagger-api#5225
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
When a user loads a different spec URL via the TopBar (or programmatically through
specActions.updateUrl), the scheme state retained from the previously loaded spec leaked into the freshly loaded spec.The
Schemescomponent (rendered for OAS2 specs that declare aschemesarray) writes the chosen value tostate.scheme._defaultScheme. When the next spec does not declare anyschemes, the Schemes component does not render, so it never overwrites_defaultScheme.operationSchemethen picks up the stale value:The displayed "Computed URL" stayed correct, but Try-it-out silently issued requests under the previous spec's scheme (e.g.,
httpsagainst an HTTP-only API), which is exactly the symptom from #5225.This PR resets the
schemebranch onUPDATE_URLwhenever the URL actually changes, so each spec computes its scheme from its ownschemeslist (or from the URL fallback) rather than inheriting state from the previous one. When the URL payload is the same, state is left untouched so config refreshes and programmatic re-issues with the same URL keep their current scheme selection.Motivation and Context
Closes #5225
How Has This Been Tested?
npm run test:unit -- --testPathPattern="spec/reducer"— green, including three new cases forspec_update_url:test/e2e-cypress/e2e/bugs/5225.cy.js) that loads a spec withschemes: [https], switches to a spec withoutschemesviaspecActions.updateUrl+specActions.download, and asserts that the generated curl ishttp://...(i.e. the previoushttpsdoes not leak). The full Cypress suite was not runnable locally because sibling agent processes were holding the e2e ports; the file lints clean and follows the existingtest/e2e-cypress/e2e/bugs/*.cy.jspatterns.Screenshots (if appropriate):
N/A — purely a state-management fix; no UI changes.
Checklist
My PR contains...
My changes...
Documentation
Automated tests