Open API 3.0 schema support in PostmanTiny validator

Hi: I am trying to validate the json response against the postman tiny validator but the assertion always returns true no matter what the json response is. I am not sure is it an issue with the tiny validator 4, but if some one has some pointers will really appreciate it. Please find the json response and the schema below

//json response
{
“id”: 1,
“category”: {
“id”: 2,
“name”: “Cats”
},
“name”: “Cat 1”,
“photoUrls”: [
“url1”,
“url2”
],
“tags”: [
{
“id”: 1,
“name”: “tag1”
},
{
“id”: 2,
“name”: “tag2”
}
],
“status”: “available”
}

//scheam object
var schema = {
“properties”: {
“Order”: {
“type”: “object”,
“properties”: {
“id”: {
“type”: “integer”,
“format”: “int64”
},
“petId”: {
“type”: “integer”,
“format”: “int64”
},
“quantity”: {
“type”: “integer”,
“format”: “int32”
},
“shipDate”: {
“type”: “string”,
“format”: “date-time”
},
“status”: {
“type”: “string”,
“description”: “Order Status”,
“enum”: [
“placed”,
“approved”,
“delivered”
]
},
“complete”: {
“type”: “boolean”,
“default”: false
}
},
“xml”: {
“name”: “Order”
}
},
“Category”: {
“type”: “object”,
“properties”: {
“id”: {
“type”: “integer”,
“format”: “int64”
},
“name”: {
“type”: “string”
}
},
“xml”: {
“name”: “Category”
}
},
“User”: {
“type”: “object”,
“properties”: {
“id”: {
“type”: “integer”,
“format”: “int64”
},
“username”: {
“type”: “string”
},
“firstName”: {
“type”: “string”
},
“lastName”: {
“type”: “string”
},
“email”: {
“type”: “string”
},
“password”: {
“type”: “string”
},
“phone”: {
“type”: “string”
},
“userStatus”: {
“type”: “integer”,
“description”: “User Status”,
“format”: “int32”
}
},
“xml”: {
“name”: “User”
}
},
“Tag”: {
“type”: “object”,
“properties”: {
“id”: {
“type”: “integer”,
“format”: “int64”
},
“name”: {
“type”: “string”
}
},
“xml”: {
“name”: “Tag”
}
},
“Pet”: {
“required”: [
“name”,
“photoUrls”
],
“type”: “object”,
“properties”: {
“id”: {
“type”: “integer”,
“format”: “int64”
},
“category”: {
“$ref”: “#/components/schemas/Category”
},
“name”: {
“type”: “string”,
“example”: “doggie”
},
“photoUrls”: {
“type”: “array”,
“xml”: {
“name”: “photoUrl”,
“wrapped”: true
},
“items”: {
“type”: “string”
}
},
“tags”: {
“type”: “array”,
“xml”: {
“name”: “tag”,
“wrapped”: true
},
“items”: {
“$ref”: “#/components/schemas/Tag”
}
},
“status”: {
“type”: “string”,
“description”: “pet status in the store”,
“enum”: [
“available”,
“pending”,
“sold”
]
}
},
“xml”: {
“name”: “Pet”
}
},
“ApiResponse”: {
“type”: “object”,
“properties”: {
“code”: {
“type”: “integer”,
“format”: “int32”
},
“type”: {
“type”: “string”
},
“message”: {
“type”: “string”
}
}
}

}

};

pm.test(‘Schema is valid’, function() {
pm.expect(tv4.validate(jsonData, schema, true)).to.be.true;

});

Hi,

I was wanting to do something similar recently, ended up getting it to work with Ajv validation instead, this topic might be helpful to you:

@dannydainton has a more concise example here of Ajv validation if that’s all you’ll need:

I ended up ditching Schema validation and testing it a different way as the API I’m testing has become really complicated and the schema way was just a bit too advanced for me to do for now.

Good luck, hope this helps! :slightly_smiling_face:

1 Like

Hi: Liam thanks for the reply, I also ended up using Ajv, as recommended by the postman https://learning.getpostman.com/docs/postman/scripts/postman_sandbox/, because tv4 json is deprecated in latest postman releases. Having said that it doesn’t solve my problem, and I guess the reason is both ajv and tiny validator 4 follows the json http://json-schema.org/, but open API 3.0 uses an extended subset of the json schema, please see the link https://swagger.io/docs/specification/data-models/keywords/. I am not an expert of Json schema but it looks to me none of the validators are fully compatible with Open API 3.0 schema.