Skip to content

Commit

Permalink
fix(spec): validation errors formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
glowcloud committed Mar 13, 2024
1 parent 720196c commit 1d169bd
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
12 changes: 3 additions & 9 deletions src/core/plugins/spec/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 24 additions & 0 deletions test/e2e-cypress/e2e/features/plugins/spec/validation-errors.cy.js
Original file line number Diff line number Diff line change
@@ -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")
})
})

0 comments on commit 1d169bd

Please sign in to comment.