expect_json_types does not check recursively the contents of the json response
Hi, I'm observing that for any given json response, I'm unable to validate the whole schema of a json response. It is validating the schema only on the top level of the json response. It is not going recursively into all the nested objects in the json response
So if there is json response like this :-
{ "a": 1, "b": [ { "x": "abc" "y": "efg" } { "x": "cba" "y": "gfa" } ] "c": null } So now if I try this out in my testscript :-
expect_json_types('*',{a: :integer, b: :array_of_objects, x: :string, y: :string, c: :nil})
I'm getting an error saying that :-
Expected x to be of type string got NilClass instead
But if I give this :-
expect_json_types('*',{a: :integer, b: :array_of_objects, c: :nil}) Then the test passes.
I want to be able to give the whole schema as part of the validation. Even those keys in nested objects.
Either I'm doing this the wrong way or there is an issue with the schema validation. Or I dunno how to do this!... lol...
Please can you guide me on this.
Thanks in advance!
Regards, VJ
Why are you using the array path matcher * for an object?
Coz when I give the schema without the path matcher, it was always failing.
In this case, how should I have given the schema to compare the whole json object ??
It would be great info if I could understand how to give the exact schema in case my json response was :-
1.Array of hashes 2.Hash 3.String
I guess I'm going wrong with the syntax
expect_json_types('*', name: :string)expect_json_types(name: :string, age: :int)- Thats not a valid response. This is a JSON validation library.
You can browse through the tests to get a better idea: https://github.com/brooklynDev/airborne/tree/master/spec/airborne/expectations