From 0144dad03d5302d7f6b3c4fa3b88344e5725078a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Gorej?= Date: Mon, 18 Sep 2023 09:26:12 +0200 Subject: [PATCH] fix(callbacks): display all defined callbacks (#9223) Refs #9222 --- .../plugins/oas3/spec-extensions/selectors.js | 33 ++++++++------- .../e2e/features/oas3-callbacks.cy.js | 19 +++++++++ .../documents/features/oas3-callbacks.yaml | 41 +++++++++++++++++++ 3 files changed, 79 insertions(+), 14 deletions(-) create mode 100644 test/e2e-cypress/e2e/features/oas3-callbacks.cy.js create mode 100644 test/e2e-cypress/static/documents/features/oas3-callbacks.yaml diff --git a/src/core/plugins/oas3/spec-extensions/selectors.js b/src/core/plugins/oas3/spec-extensions/selectors.js index 67c6b2f39b6..30b6d160082 100644 --- a/src/core/plugins/oas3/spec-extensions/selectors.js +++ b/src/core/plugins/oas3/spec-extensions/selectors.js @@ -58,22 +58,27 @@ export const callbacksOperations = onlyOAS3( .reduce((allOperations, callback, callbackName) => { if (!Map.isMap(callback)) return allOperations - return callback.reduce((callbackOperations, pathItem, expression) => { - if (!Map.isMap(pathItem)) return callbackOperations + const callbackOperations = callback.reduce( + (callbackOps, pathItem, expression) => { + if (!Map.isMap(pathItem)) return callbackOps - const pathItemOperations = pathItem - .entrySeq() - .filter(([key]) => validOperationMethods.includes(key)) - .map(([method, operation]) => ({ - operation: Map({ operation }), - method, - path: expression, - callbackName, - specPath: specPath.concat([callbackName, expression, method]), - })) + const pathItemOperations = pathItem + .entrySeq() + .filter(([key]) => validOperationMethods.includes(key)) + .map(([method, operation]) => ({ + operation: Map({ operation }), + method, + path: expression, + callbackName, + specPath: specPath.concat([callbackName, expression, method]), + })) - return callbackOperations.concat(pathItemOperations) - }, List()) + return callbackOps.concat(pathItemOperations) + }, + List() + ) + + return allOperations.concat(callbackOperations) }, List()) .groupBy((operationDTO) => operationDTO.callbackName) .map((operations) => operations.toArray()) diff --git a/test/e2e-cypress/e2e/features/oas3-callbacks.cy.js b/test/e2e-cypress/e2e/features/oas3-callbacks.cy.js new file mode 100644 index 00000000000..26d92e7fb20 --- /dev/null +++ b/test/e2e-cypress/e2e/features/oas3-callbacks.cy.js @@ -0,0 +1,19 @@ +/** + * Related to // https://github.com/swagger-api/swagger-ui/issues/9222. + */ + +describe("OpenAPI 3.0 Callbacks", () => { + it("should render all defined callbacks", () => { + cy.visit( + "/?url=/documents/features/oas3-callbacks.yaml" + ) + .get("#operations-Device-register") + .click() + .get(".opblock-section-header .tab-item.false") + .click() + .get("#operations-callbacks-callbackOne") + .should("be.visible") + .get("#operations-callbacks-callbackTwo") + .should("be.visible") + }) +}) diff --git a/test/e2e-cypress/static/documents/features/oas3-callbacks.yaml b/test/e2e-cypress/static/documents/features/oas3-callbacks.yaml new file mode 100644 index 00000000000..14671ca7c51 --- /dev/null +++ b/test/e2e-cypress/static/documents/features/oas3-callbacks.yaml @@ -0,0 +1,41 @@ +openapi: 3.0.0 +servers: [] +info: + version: "1.0.0" + title: home-iot-api + description: The API +paths: + /devices: + get: + callbacks: + callbackOne: + 'callbackOne': + get: + operationId: callbackOne + responses: + '200': + $ref: '#/components/schemas/ApiResponse' + callbackTwo: + 'callbackTwo': + get: + operationId: callbackTwo + responses: + '200': + $ref: '#/components/schemas/ApiResponse' + tags: + - Device + operationId: register + responses: + '200': + description: successfully registered device +components: + schemas: + ApiResponse: + type: object + properties: + code: + type: integer + format: int32 + message: + type: string + example: everything is ok