No, Current and target are required fields so we need to use required
array.
Basically based on the backend data, some time API give response with gqv as
“gqv”: {
“current”: “1392.49”,
“target”: “1200.00”
},
and some time response like empty
“gqv”: {},
So I want to make my schema reliable in both the conditions.
Above schema will fail when there is empty response for “gqv”, correct?
And I was deep diving more into anyOf/allOf/oneOf keywords through https://cswr.github.io/JsonSchema/spec/generic_keywords/
However find difficulty to understand with example.
Example of response API:
[
{
“id”: 120000755487,
“firstName”: “Bruce”,
“lastName”: “White”,
“generation”: 0,
“lastOrderedOn”: “2020-09-03 03:08:35”
},
{
“id”: 120001439895,
“firstName”: “Cherlyn”,
“lastName”: “Jeffries”,
“generation”: 0,
“lastOrderedOn”: null
}
]
If you see in array, lastOrderedOn object values are different. In this case which generic keyword(anyof/allof/oneof) will work with schema?
I tried with below schema but no luck.
const schema = {
“type”: “array”,
“items”: {
“anyOf”: [
{
“type”: “object”,
“required”: [“id”,“firstName”,“lastName”, “avatarUrl”,“generation”, “lastOrderedOn”],
“additionalProperties”: false,
“properties”: {
“id”: { “type”: “integer”},
“firstName”: {“type”: “string”},
“lastName”: {“type”: “string”},
“avatarUrl”: {“type”: “string”},
“generation”: {“type”: “integer”},
“lastOrderedOn”: {“type”: “string”},
}
}]}}
pm.test(“Body is correct”, function () {
pm.response.to.have.jsonSchema(schema);
let jsonData = pm.response.json();
pm.response.to.have.status(200);
pm.environment.set(“clientid”, jsonData[0].id);
});
Instead of anyOf, I tried oneOf/allOf but not working.
Solution was I just changed “lastOrderedOn”: {“type”: [ “string”, “null”] }, within schema that’s it within any keyword.
So want to know exact difference on such keyword?
Sorry now ticket contains 2 queries but want to learn basics.