From 1d169bd400a82d8ae31f4e7f13294e4c35e3a44b Mon Sep 17 00:00:00 2001 From: Oliwia Rogala Date: Wed, 13 Mar 2024 10:52:04 +0100 Subject: [PATCH] fix(spec): validation errors formatting --- src/core/plugins/spec/selectors.js | 12 +++------- .../plugins/spec/validation-errors.cy.js | 24 +++++++++++++++++++ 2 files changed, 27 insertions(+), 9 deletions(-) create mode 100644 test/e2e-cypress/e2e/features/plugins/spec/validation-errors.cy.js diff --git a/src/core/plugins/spec/selectors.js b/src/core/plugins/spec/selectors.js index eb8b07ac399..82607ac8f1f 100644 --- a/src/core/plugins/spec/selectors.js +++ b/src/core/plugins/spec/selectors.js @@ -496,16 +496,10 @@ export const validationErrors = (state, pathMethod) => { paramValues.forEach( (p) => { let errors = p.get("errors") - if ( errors && errors.count() ) { + if (errors && errors.count()) { errors - .map( e => { - if (e instanceof Map) { - return `${e.get("propKey")} : ${e.get("error")}` - } else { - return e - } - }) - .forEach( e => result.push(e)) + .map((e) => (Map.isMap(e) ? `${e.get("propKey")}: ${e.get("error")}` : e)) + .forEach((e) => result.push(e)) } }) return result diff --git a/test/e2e-cypress/e2e/features/plugins/spec/validation-errors.cy.js b/test/e2e-cypress/e2e/features/plugins/spec/validation-errors.cy.js new file mode 100644 index 00000000000..a038cd2f6c0 --- /dev/null +++ b/test/e2e-cypress/e2e/features/plugins/spec/validation-errors.cy.js @@ -0,0 +1,24 @@ +/** + * @prettier + */ + +describe("Validation errors", () => { + it("should correctly format validation errors for Map items", () => { + cy.visit("/?url=/documents/petstore.swagger.yaml") + .get("#operations-pet-addPet") + .click() + .get("button.try-out__btn") + .click() + .get("textarea.body-param__text") + .clear() + .type(`{backspace}"id": "test", "name": 1}`) + .get("button.execute") + .click() + .get("div.validation-errors.errors-wrapper") + .contains("id: Value must be an integer") + .should("exist") + .get("div.validation-errors.errors-wrapper") + .contains("name: Value must be a string") + .should("exist") + }) +})