Validating JSON schema ignores the property's format

Hello everyone!

I recently discovered JSON schema by reading the Postman docs and I would like to incorporate this nifty feature in my tests. I discovered that AJV validatior is built-in in the Postman sandbox so naturally I’m using that one over tv4.
The problem I encountered is when I write the JSON Schema format for a property, the assertion passes when it should have failed.

This is the property:
“startDate”: {
“type”: “string”,
“format”: “date”
}

and in my response I get:
“startDate”: “2021-02-01”

Does the schema validation even validate by format? If not, how can this be enabled?

Screenshots:


image

JSON Schema Tool

This is the solution:

You need to paste your expected response to this tool that the kind developers of jsonschema have provided and create a JSON Schema in the right side. Paste the code from the right side in your variable (schema) and pass that variable for validating:

pm.test(“JSON Schema validation”, () => {

pm.response.to.have.jsonSchema(schema);

});

response is a variable in which we keep the response body:
let response = pm.response.json();

1 Like