Skip to content

fix(oas3): scope callbacks expansion state by callback name#10887

Open
yogeshwaran-c wants to merge 1 commit into
swagger-api:masterfrom
yogeshwaran-c:fix/callbacks-duplicate-url-key-5536
Open

fix(oas3): scope callbacks expansion state by callback name#10887
yogeshwaran-c wants to merge 1 commit into
swagger-api:masterfrom
yogeshwaran-c:fix/callbacks-duplicate-url-key-5536

Conversation

@yogeshwaran-c
Copy link
Copy Markdown

Description

When an OAS3 operation declares multiple callbacks that share the same URL template path item (e.g. both myEvent and otherEvent containing '{$request.body#/callbackUrl}': post:), the rendered UI fails to let the user expand one callback box independently. Clicking the expand control on one callback toggles both, and the two callback operation blocks render with the same DOM id.

Root cause

OperationContainer.mapStateToProps derives the layout isShownKey as ["operations", tag, operationId]. For callbacks rendered by src/core/plugins/oas3/components/callbacks.jsx, every nested OperationContainer was passed tag="callbacks". When two callbacks have the same path and method, swagger-client's opId helper (in the absence of an explicit operationId) produces the same string from path + method, so both containers share the exact same isShownKey. Toggling one flips the single Redux flag, expanding both, and the DOM id derived from that key (in operation.jsx) also collides.

Fix

Pass a per-callback tag — `callbacks-${callbackName}` — so each callback block gets a unique isShownKey and unique DOM id, while still being clearly namespaced under callbacks.

Motivation and Context

Fixes #5536

How Has This Been Tested?

  • Unit: test/unit/core/plugins/oas3/callbacks.jsx
    • Verifies one OperationContainer is rendered per callback path-item operation.
    • Verifies the tag prop is `callbacks-${callbackName}` and unique across colliding URLs.
    • The new tag-uniqueness assertion fails against master (received [\"callbacks\", \"callbacks\"]) and passes with the fix.
  • E2E: test/e2e-cypress/e2e/bugs/5536.cy.js with fixture test/e2e-cypress/static/documents/bugs/5536.yaml (the exact spec from the issue, with an explicit operationId on the parent only).
    • Asserts both #operations-callbacks-myEvent-... and #operations-callbacks-otherEvent-... DOM ids exist.
    • Expands only myEvent and asserts myEvent becomes .is-open while otherEvent does not.
    • Verified failing on master (DOM ids collide; the expected unique ids are missing) and passing with the fix.

Checklist

  • Bug fix (non-breaking change which fixes an issue)
  • Tests added (unit + e2e)
  • No documentation update needed
  • All linters pass

Two callbacks declaring the same URL template path item (e.g. both
`myEvent` and `otherEvent` containing
`'{$request.body#/callbackUrl}': post:`) shared the same layout
isShownKey `["operations", "callbacks", operationId]`, because the
generated operationId is identical (path + method). Toggling expansion
on one callback flipped the shared key and expanded both blocks.

The DOM id derived from this key also collided, producing duplicate
ids in the rendered page.

Fix: pass a per-callback tag (`callbacks-<callbackName>`) so each
callback gets its own isShownKey and DOM id.

Fixes swagger-api#5536
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.

With multiple callbacks defined on the same URL, you can not expand one callback box

1 participant