Skip to content

fix(spec): clear scheme state when loading a new spec url#10862

Open
yogeshwaran-c wants to merge 1 commit into
swagger-api:masterfrom
yogeshwaran-c:fix/clear-scheme-state-on-url-change
Open

fix(spec): clear scheme state when loading a new spec url#10862
yogeshwaran-c wants to merge 1 commit into
swagger-api:masterfrom
yogeshwaran-c:fix/clear-scheme-state-on-url-change

Conversation

@yogeshwaran-c
Copy link
Copy Markdown

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 Schemes component (rendered for OAS2 specs that declare a schemes array) writes the chosen value to state.scheme._defaultScheme. When the next spec does not declare any schemes, the Schemes component does not render, so it never overwrites _defaultScheme. operationScheme then picks up the stale value:

return state.getIn(["scheme", path, method])
  || state.getIn(["scheme", "_defaultScheme"])
  || urlScheme || ""

The displayed "Computed URL" stayed correct, but Try-it-out silently issued requests under the previous spec's scheme (e.g., https against an HTTP-only API), which is exactly the symptom from #5225.

This PR resets the scheme branch on UPDATE_URL whenever the URL actually changes, so each spec computes its scheme from its own schemes list (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 for spec_update_url:
    • sets the url payload as a string (regression)
    • clears retained scheme state when the url changes
    • keeps scheme state when the url payload does not change
  • Added a Cypress e2e regression test (test/e2e-cypress/e2e/bugs/5225.cy.js) that loads a spec with schemes: [https], switches to a spec without schemes via specActions.updateUrl + specActions.download, and asserts that the generated curl is http://... (i.e. the previous https does 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 existing test/e2e-cypress/e2e/bugs/*.cy.js patterns.

Screenshots (if appropriate):

N/A — purely a state-management fix; no UI changes.

Checklist

My PR contains...

  • Bug fixes (non-breaking change which fixes an issue)
  • No code changes
  • Dependency changes
  • Improvements
  • Features

My changes...

  • are not breaking changes.
  • are breaking changes to a public API.
  • are breaking changes to a private API.
  • are breaking changes to a developer API.

Documentation

  • My changes do not require a change to the project documentation.

Automated tests

  • My changes can and should be tested by unit and/or integration tests.
  • I have added tests to cover my changes.
  • I have taken care to cover edge cases in my tests (URL unchanged vs changed).
  • All new and existing tests passed.

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Loading new URL does not reset schemes value if schemes unset

1 participant