tv4 icon indicating copy to clipboard operation
tv4 copied to clipboard

tv4.validate does not validate properly when using 'const' schema property

Open catherine-greene opened this issue 4 years ago • 1 comments

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

catherine-greene avatar Feb 26 '20 17:02 catherine-greene

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);

iheidari avatar May 05 '21 18:05 iheidari