Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expect_json_types does not check recursively the contents of the json response #95

Open
vjster opened this issue Apr 15, 2016 · 3 comments

Comments

@vjster
Copy link

vjster commented Apr 15, 2016

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

@sethpollack
Copy link
Collaborator

sethpollack commented Apr 15, 2016

Why are you using the array path matcher * for an object?

@vjster
Copy link
Author

vjster commented Apr 15, 2016

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

@sethpollack
Copy link
Collaborator

sethpollack commented Apr 15, 2016

  1. expect_json_types('*', name: :string)
  2. expect_json_types(name: :string, age: :int)
  3. 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants