I used jsonschema to convert a response body into a schema to test against.
let Ajv = require('ajv'),
ajv = new Ajv({logger: console}),
schema = {
"$schema": "http://json-schema.org/draft-07/schema",
"$id": "http://example.com/example.json",
"type": "object",
"title": "The root schema",
"description": "The root schema comprises the entire JSON document.",
"default": {},
"examples": [
{
"data": {
"statusItem": [
{
"ID": 12,
"cost": 0,
"discountType": 0,
"discountValue": 0,
"flags": 0,
"flags3": 0,
"flags4": 0,
"flags5": 0,
"futureBreakID": 0,
"group": 1,
"highlightColor": 65535,
"inActive": 0,
"miscItemID": 0,
"name": "Surface",
"notificationID": 0,
"overrideRejectMins": false,
"POReturnReasonID": 0,
"priority": 0,
"rejectStatusMins": 5,
"seqNum1": 0,
"seqNum2": 0,
"userOrGroupID": 0
}
]
}
}
],
"required": [
"data"
],
"properties": {
"data": {
"$id": "#/properties/data",
"type": "object",
"title": "The data schema",
"description": "An explanation about the purpose of this instance.",
"default": {},
"examples": [
{
"statusItem": [
{
"ID": 12,
"cost": 0,
"discountType": 0,
"discountValue": 0,
"flags": 0,
"flags3": 0,
"flags4": 0,
"flags5": 0,
"futureBreakID": 0,
"group": 1,
"highlightColor": 65535,
"inActive": 0,
"miscItemID": 0,
"name": "Surface",
"notificationID": 0,
"overrideRejectMins": false,
"POReturnReasonID": 0,
"priority": 0,
"rejectStatusMins": 5,
"seqNum1": 0,
"seqNum2": 0,
"userOrGroupID": 0
}
]
}
],
"required": [
"statusItem"
],
"properties": {
"statusItem": {
"$id": "#/properties/data/properties/statusItem",
"type": "array",
"title": "The statusItem schema",
"description": "An explanation about the purpose of this instance.",
"default": [],
"examples": [
[
{
"ID": 12,
"cost": 0,
"discountType": 0,
"discountValue": 0,
"flags": 0,
"flags3": 0,
"flags4": 0,
"flags5": 0,
"futureBreakID": 0,
"group": 1,
"highlightColor": 65535,
"inActive": 0,
"miscItemID": 0,
"name": "Surface",
"notificationID": 0,
"overrideRejectMins": false,
"POReturnReasonID": 0,
"priority": 0,
"rejectStatusMins": 5,
"seqNum1": 0,
"seqNum2": 0,
"userOrGroupID": 0
}
]
],
"additionalItems": true,
"items": {
"$id": "#/properties/data/properties/statusItem/items",
"anyOf": [
{
"$id": "#/properties/data/properties/statusItem/items/anyOf/0",
"type": "object",
"title": "The first anyOf schema",
"description": "An explanation about the purpose of this instance.",
"default": {},
"examples": [
{
"ID": 12,
"cost": 0,
"discountType": 0,
"discountValue": 0,
"flags": 0,
"flags3": 0,
"flags4": 0,
"flags5": 0,
"futureBreakID": 0,
"group": 1,
"highlightColor": 65535,
"inActive": 0,
"miscItemID": 0,
"name": "Surface",
"notificationID": 0,
"overrideRejectMins": false,
"POReturnReasonID": 0,
"priority": 0,
"rejectStatusMins": 5,
"seqNum1": 0,
"seqNum2": 0,
"userOrGroupID": 0
}
],
"required": [
"ID",
"cost",
"discountType",
"discountValue",
"flags",
"flags3",
"flags4",
"flags5",
"futureBreakID",
"group",
"highlightColor",
"inActive",
"miscItemID",
"name",
"notificationID",
"overrideRejectMins",
"POReturnReasonID",
"priority",
"rejectStatusMins",
"seqNum1",
"seqNum2",
"userOrGroupID"
],
"properties": {
"ID": {
"$id": "#/properties/data/properties/statusItem/items/anyOf/0/properties/ID",
"type": "integer",
"title": "The ID schema",
"description": "An explanation about the purpose of this instance.",
"default": 0,
"examples": [
12
]
},
"cost": {
"$id": "#/properties/data/properties/statusItem/items/anyOf/0/properties/cost",
"type": "integer",
"title": "The cost schema",
"description": "An explanation about the purpose of this instance.",
"default": 0,
"examples": [
0
]
},
"discountType": {
"$id": "#/properties/data/properties/statusItem/items/anyOf/0/properties/discountType",
"type": "integer",
"title": "The discountType schema",
"description": "An explanation about the purpose of this instance.",
"default": 0,
"examples": [
0
]
},
"discountValue": {
"$id": "#/properties/data/properties/statusItem/items/anyOf/0/properties/discountValue",
"type": "integer",
"title": "The discountValue schema",
"description": "An explanation about the purpose of this instance.",
"default": 0,
"examples": [
0
]
},
"flags": {
"$id": "#/properties/data/properties/statusItem/items/anyOf/0/properties/flags",
"type": "integer",
"title": "The flags schema",
"description": "An explanation about the purpose of this instance.",
"default": 0,
"examples": [
0
]
},
"flags3": {
"$id": "#/properties/data/properties/statusItem/items/anyOf/0/properties/flags3",
"type": "integer",
"title": "The flags3 schema",
"description": "An explanation about the purpose of this instance.",
"default": 0,
"examples": [
0
]
},
"flags4": {
"$id": "#/properties/data/properties/statusItem/items/anyOf/0/properties/flags4",
"type": "integer",
"title": "The flags4 schema",
"description": "An explanation about the purpose of this instance.",
"default": 0,
"examples": [
0
]
},
"flags5": {
"$id": "#/properties/data/properties/statusItem/items/anyOf/0/properties/flags5",
"type": "integer",
"title": "The flags5 schema",
"description": "An explanation about the purpose of this instance.",
"default": 0,
"examples": [
0
]
},
"futureBreakID": {
"$id": "#/properties/data/properties/statusItem/items/anyOf/0/properties/futureBreakID",
"type": "integer",
"title": "The futureBreakID schema",
"description": "An explanation about the purpose of this instance.",
"default": 0,
"examples": [
0
]
},
"group": {
"$id": "#/properties/data/properties/statusItem/items/anyOf/0/properties/group",
"type": "integer",
"title": "The group schema",
"description": "An explanation about the purpose of this instance.",
"default": 0,
"examples": [
1
]
},
"highlightColor": {
"$id": "#/properties/data/properties/statusItem/items/anyOf/0/properties/highlightColor",
"type": "integer",
"title": "The highlightColor schema",
"description": "An explanation about the purpose of this instance.",
"default": 0,
"examples": [
65535
]
},
"inActive": {
"$id": "#/properties/data/properties/statusItem/items/anyOf/0/properties/inActive",
"type": "integer",
"title": "The inActive schema",
"description": "An explanation about the purpose of this instance.",
"default": 0,
"examples": [
0
]
},
"miscItemID": {
"$id": "#/properties/data/properties/statusItem/items/anyOf/0/properties/miscItemID",
"type": "integer",
"title": "The miscItemID schema",
"description": "An explanation about the purpose of this instance.",
"default": 0,
"examples": [
0
]
},
"name": {
"$id": "#/properties/data/properties/statusItem/items/anyOf/0/properties/name",
"type": "string",
"title": "The name schema",
"description": "An explanation about the purpose of this instance.",
"default": "",
"examples": [
"Surface"
]
},
"notificationID": {
"$id": "#/properties/data/properties/statusItem/items/anyOf/0/properties/notificationID",
"type": "integer",
"title": "The notificationID schema",
"description": "An explanation about the purpose of this instance.",
"default": 0,
"examples": [
0
]
},
"overrideRejectMins": {
"$id": "#/properties/data/properties/statusItem/items/anyOf/0/properties/overrideRejectMins",
"type": "boolean",
"title": "The overrideRejectMins schema",
"description": "An explanation about the purpose of this instance.",
"default": false,
"examples": [
false
]
},
"POReturnReasonID": {
"$id": "#/properties/data/properties/statusItem/items/anyOf/0/properties/POReturnReasonID",
"type": "integer",
"title": "The POReturnReasonID schema",
"description": "An explanation about the purpose of this instance.",
"default": 0,
"examples": [
0
]
},
"priority": {
"$id": "#/properties/data/properties/statusItem/items/anyOf/0/properties/priority",
"type": "integer",
"title": "The priority schema",
"description": "An explanation about the purpose of this instance.",
"default": 0,
"examples": [
0
]
},
"rejectStatusMins": {
"$id": "#/properties/data/properties/statusItem/items/anyOf/0/properties/rejectStatusMins",
"type": "integer",
"title": "The rejectStatusMins schema",
"description": "An explanation about the purpose of this instance.",
"default": 0,
"examples": [
5
]
},
"seqNum1": {
"$id": "#/properties/data/properties/statusItem/items/anyOf/0/properties/seqNum1",
"type": "integer",
"title": "The seqNum1 schema",
"description": "An explanation about the purpose of this instance.",
"default": 0,
"examples": [
0
]
},
"seqNum2": {
"$id": "#/properties/data/properties/statusItem/items/anyOf/0/properties/seqNum2",
"type": "integer",
"title": "The seqNum2 schema",
"description": "An explanation about the purpose of this instance.",
"default": 0,
"examples": [
0
]
},
"userOrGroupID": {
"$id": "#/properties/data/properties/statusItem/items/anyOf/0/properties/userOrGroupID",
"type": "integer",
"title": "The userOrGroupID schema",
"description": "An explanation about the purpose of this instance.",
"default": 0,
"examples": [
0
]
}
},
"additionalProperties": true
}
]
}
}
},
"additionalProperties": true
}
},
"additionalProperties": true
}
Next, I used the following test:
pm.test('Schema is valid', function() {
var error = pm.response.json()['errors'];
pm.expect(ajv.validate(schema, {errors: error})).to.be.true;
});
It failed with this very sad error:
Schema is valid | AssertionError: expected false to be true
This error doesn’t provide nearly enough information to troubleshoot.
Should I be using different parameters for the function?
BTW, I got this method from
postman, ajv