1

Following is the structure of the response schema. Over here there could be multiple key:value pairs under "Property.Result" and similarly under "Property.fundType".

I have to validate the response only for the structure and not for the data values. So the request is to ensure the response json is of the require structure

{
    "Property": {
        "Result": {
            "Prop1": {
                "empty": true
            },
            "Prop2": {
                "empty": true
            },
            "Prop3": {
                "empty": true
            }
        },
        "Type": {
            "additionalProp1": "string",
            "additionalProp2": "string",
            "additionalProp3": "string"
        },
        "id": "string"
    }
}

Generally the validation would be as below:

  • def Schema = {Result: '#(ResultDetails)', Type: '#(TypeDetails)', id: '#string'}
  • def ResultDetails = {Prop1: '#(PropDetails)', Prop2: '#(PropDetails)', Prop3: '#(PropDetails)'}
  • def PropDetails = {empty: '#boolean'}
  • def TypeDetails = {additionalProp1: '#string', additionalProp2: '#string', additionalProp3: '#string'}

with the above, I have list out all the possible keys in order to validate them Since the count of key:value pairs can be different on each of the elements of the response array, can we generalize the schema validation without having to list down all of the possible keys ?

Leo P
  • 33
  • 2
  • I recommend that you avoid this over-generalization, it actually makes your tests less maintainable in my opinion: https://stackoverflow.com/a/50350442/143475 – Peter Thomas Jan 15 '21 at 12:20

0 Answers0