fix(spec): validation errors formatting (#9687)
Co-authored-by: Enrico Bottacin <enrico.bottacin@gmail.com> Co-authored-by: Vladimír Gorej <vladimir.gorej@gmail.com>
This commit is contained in:
@@ -496,11 +496,12 @@ export const validationErrors = (state, pathMethod) => {
|
|||||||
|
|
||||||
paramValues.forEach( (p) => {
|
paramValues.forEach( (p) => {
|
||||||
let errors = p.get("errors")
|
let errors = p.get("errors")
|
||||||
if ( errors && errors.count() ) {
|
if (errors && errors.count()) {
|
||||||
errors.forEach( e => result.push(e))
|
errors
|
||||||
|
.map((e) => (Map.isMap(e) ? `${e.get("propKey")}: ${e.get("error")}` : e))
|
||||||
|
.forEach((e) => result.push(e))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,8 @@ import {
|
|||||||
parameterInclusionSettingFor,
|
parameterInclusionSettingFor,
|
||||||
consumesOptionsFor,
|
consumesOptionsFor,
|
||||||
taggedOperations,
|
taggedOperations,
|
||||||
isMediaTypeSchemaPropertiesEqual
|
isMediaTypeSchemaPropertiesEqual,
|
||||||
|
validationErrors
|
||||||
} from "core/plugins/spec/selectors"
|
} from "core/plugins/spec/selectors"
|
||||||
|
|
||||||
import Petstore from "./assets/petstore.json"
|
import Petstore from "./assets/petstore.json"
|
||||||
@@ -1380,3 +1381,55 @@ describe("isMediaTypeSchemaPropertiesEqual", () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
describe("validationErrors", function() {
|
||||||
|
const state = fromJS({
|
||||||
|
meta: {
|
||||||
|
paths: {
|
||||||
|
"/": {
|
||||||
|
get: {
|
||||||
|
parameters: {
|
||||||
|
id: {
|
||||||
|
errors: [
|
||||||
|
"Value must be an integer"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
post: {
|
||||||
|
parameters: {
|
||||||
|
body: {
|
||||||
|
errors: [
|
||||||
|
{
|
||||||
|
error: "Value must be an integer",
|
||||||
|
propKey: "id"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
error: "Value must be a string",
|
||||||
|
propKey: "name"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should return validation errors without formatting them", function () {
|
||||||
|
const result = validationErrors(state, ["/", "get"])
|
||||||
|
|
||||||
|
expect(result).toEqual([
|
||||||
|
"Value must be an integer"
|
||||||
|
])
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should return formatted validation errors", function () {
|
||||||
|
const result = validationErrors(state, ["/", "post"])
|
||||||
|
|
||||||
|
expect(result).toEqual([
|
||||||
|
"id: Value must be an integer",
|
||||||
|
"name: Value must be a string"
|
||||||
|
])
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user