tv4
tv4 copied to clipboard
tv4.validate does not validate properly when using 'const' schema property
tv4.validate does not tell the difference when using 'const' schema property
const jsonData = {
"id": 1160134,
"lastUpdatedBy": "API_TEST"
}
const schema = {
"required": [
"id",
"lastUpdatedBy",
],
"properties": {
"id": {
"type": "integer"
},
"lastUpdatedBy": {
"type": "string",
**"const": "API_TEST3"**
}
}
}
tv4.validate(jsonData, schema);
App information
Postman v7.19.1 OS: Windows 10
I know it is not the solution, but for short term answer you can use enum
with just one value:
const jsonData = {
"id": 1160134,
"lastUpdatedBy": "API_TEST"
}
const schema = {
"required": [
"id",
"lastUpdatedBy",
],
"properties": {
"id": {
"type": "integer"
},
"lastUpdatedBy": {
"type": "string",
"enum": ["API_TEST3"]
}
}
}
tv4.validate(jsonData, schema);