Skip to content
This repository has been archived by the owner on Nov 8, 2024. It is now read-only.

Provides valid JSON for "body_json_example" feature #39

Merged
merged 1 commit into from
May 15, 2019

Conversation

artem-zakharchenko
Copy link
Contributor

@artem-zakharchenko artem-zakharchenko commented May 15, 2019

Fixes an invalid JSON example included in the body_json_example feature suit:

Scenario: Array member is missing in real JSON body
When real HTTP body is following:
"""
{
"object": {
"a": "bau bau",
"c": "boo boo",
"e": "mrau mrau"
},
"array": [
1
],
"string": "Foo bar",
}
"""
Then Gavel will set some error for "body"
And Request or Response is NOT valid

The feature suit expects Gavel to throw because of the missing array member in the real body. While Gavel does throw, that happens not because of the missing array member, but because an attempt to parse the given JSON example fails (since it's invalid JSON), and body media types become the following:

real: text/plain
expected: application/json

Such combination of body media types has no corresponding validator in Gavel, and thus it throws an explicit error about this:

https://github.com/apiaryio/gavel.js/blob/efe1eb093d4b4433d924995088cb616100a53373/lib/mixins/validatable-http-message.js#L311-L317

Since Gavel currently stores internal exceptions and public validation results under the same results key, the spec assumes the thrown error is the validation error, while it's a parsing error. This is a good example why apiaryio/gavel.js#163 may be a sensible improvement in the future.

@artem-zakharchenko
Copy link
Contributor Author

I've checked the other JSON examples throughout the spec and they seem to be valid.

@honzajavorek honzajavorek merged commit 9f68503 into master May 15, 2019
@honzajavorek honzajavorek deleted the invalid-json branch May 15, 2019 13:35
@ApiaryBot
Copy link
Collaborator

🎉 This PR is included in version 1.2.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging this pull request may close these issues.

3 participants