-
Notifications
You must be signed in to change notification settings - Fork 370
JSON parseable verification #435
Comments
swagger-tools doesn't parse JSON, except when retrieving remote references, and all of its APIs take already created/parsed objects. As for when JSON parsing does occur, I'm not sure how we could attempt to validate JSON that didn't pass parsing. Do you have an example that can reproduce this? |
Here is a malformed JSON that will pass swagger-tools validation even though it can't be parsed:
Note the extra comma after the parameter |
So, here is the problem. We're using a YAML parser to parse the inputs, whether JSON or YAML. The reason for this is the YAML parser we use is capable of parsing both JSON and YAML. It seems that the JSON above is invalid if using I'm not sure if this is a bug or a feature but I'll see if |
It looks like I've brought this up in the past: nodeca/js-yaml#262 It seems that the only way to solve this is to have a fall-through mode where instead of using the YAML parser for everything, I try the JSON parser first and then fall through to the YAML parser. Or...we leave it as-is. |
According to If there is no other option, I think |
I tried using it, As for this JSON not working, how do you mean? Can you give me a real error you're encountering? |
Thanks for checking out the The error case we have is when trying to load an invalid json file in a swagger instance. Perhaps that has something to do with the fact that the json file is on another domain... |
Swagger instance? You mean That alone is reason enough to fix this I guess. The reason I took this route is because there is no 100% guaranteed way to check if an input is JSON or YAML and extension matching is not a guarantee. I will update |
Right, I meant |
I'll get it out ASAP but if it's a show stopper, just fix your JSON. ;) That requires no changes elsewhere. Now that I've got the bug in |
It seems that swagger-tools validate will not check if the JSON is valid before checking if it matches the expected schema (or that there is an error when handling this check).
As a result, errors like trailing commas are not seen, but trigger an error later on when trying to parse the JSON.
Would it be possible to add this check as a pre-requisite before any other verification ?
The text was updated successfully, but these errors were encountered: