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:
Oliwia Rogala
2024-03-13 12:09:52 +01:00
committed by GitHub
parent 8784145185
commit 99bf8fcc19
2 changed files with 58 additions and 4 deletions

View File

@@ -14,7 +14,8 @@ import {
parameterInclusionSettingFor,
consumesOptionsFor,
taggedOperations,
isMediaTypeSchemaPropertiesEqual
isMediaTypeSchemaPropertiesEqual,
validationErrors
} from "core/plugins/spec/selectors"
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"
])
})
})