apiaryio / gavel.js

Validator of HTTP messages (JavaScript implementation)
MIT License
97 stars 22 forks source link

Gavel doesn't support $ref in schemas #25

Closed ecordell closed 7 years ago

ecordell commented 11 years ago

Gavel uses Amanda for validating payloads against a JSON Schema. Unfortunately Amanda doesn't support $ref in schemas, and doesn't look like it will be added any time soon (see this issue from two years ago).

This is a feature I would like to have in Gavel. It seems to me that the options are:

Almad commented 11 years ago

@ecordell Do you have any experience with the other implementations?

@Baggz is actually with us at @apiaryio, but I do think we might migrate away from Amanda, but we've yet to done our research homework. Feedback on this would be appreciated.

ecordell commented 11 years ago

I saw that @apiaryio had a fork of Amanda, but didn't realize @Baggz was there as well.

I have no experience with the other implementations, but a couple of them looked like they supported more of the schema spec (and some support draf4 features, thought it's not yet been published afaik).

It's worth noting that none of them have plans to support other schema languages, so far as I can tell, so if that's the end goal it may make sense to just get Amanda to support the full spec rather than jumping ship.

Of the projects I listed, [jsonschema]() supports most of the spec (all of draft3 and some of draft4) and is actively developed (last commit was a few days ago). Z-Schema supports all of draft4 and looks actively developed. JSV looks like a good project and supports all of draft three, but looks unmaintained as of July.

But I haven't tried using any of these so I'd be wary to suggest anything based simply on what it says in the Readmes!

cjha commented 10 years ago

Are there any plans to address this? Z-Schema and https://github.com/natesilva/jayschema seem like decent alternatives for draft4 support.

Almad commented 10 years ago

@cjha Yes, however it is a bit deeper in queue, because we do have a diff viewer that is fairly dependent on gavel's output...and that is fairly dependent on Amanda's.

Are you guys willing to give it a shot?

joaosa commented 8 years ago

@Almad any updates on this? :)

Almad commented 8 years ago

@honzajavorek It's yours now :P

honzajavorek commented 8 years ago

@joaosa I think Gavel should be able to currently validate both draft v3 (by Amanda?) and draft v4 (by tv4?), but to be honest, I have currently very little insight on what actually happens under the hood and would have to check.

Amanda has last commit 2 years ago and no new development should be expected there. Not sure what are @Baggz's plans with it.

As I said, I'd have to check, but

My bet is that the second list item is true (again, this is not verified, it's from the top of my head). So if that's really true and you want to help us to get faster to a solution, you may want to contribute a failing test. Would that work for you?

joaosa commented 8 years ago

@honzajavorek Thank you for the prompt response :)

I think I managed to produce two failing tests and added the corresponding schemas:

If needed, I can also place the tests in a more appropriate location within the test suite. Also, wondering if the second test makes sense.

Hope it helps!

honzajavorek commented 8 years ago

@joaosa Thanks! This is great. Both tests make sense to me.

joaosa commented 8 years ago

@honzajavorek Any updates? :)

honzajavorek commented 8 years ago

@joaosa I'm sorry, not yet. Some priority stuff stepped in.

joaosa commented 7 years ago

@honzajavorek checking in again. I could potentially look into this myself :)

honzajavorek commented 7 years ago

@joaosa Thanks for pinging and thanks for the effort! I'd be glad to advise you in case you want to work on this 👍 I got back to your tests and I have several comments:

When there are all necessary tests (failing tests, because the feature isn't there yet), we can start to implement the feature and make the tests green. Then let's make a Pull Request and strive for releasing the feature.

Gavel uses tv4 to validate Draft4 schemas and according to its README, it should support $ref without any problems. It would be up to you to find out why this doesn't work in case of Gavel.js. Maybe just playing with tv4 settings or upgrading to the latest version will add the feature.

Good luck! Please get back here if you make any progress or if you get stuck, I'll try to help (and be more responsive). I hope what I wrote will help you to proceed.

Note: Since Gavel.js uses Semantic Release, please read this section and make sure your commits are formatted accordingly. Only in that case the automatic releasing will work when your PR gets accepted and merged. Thanks!

joaosa commented 7 years ago

@honzajavorek Thank you for the feedback :)

I have some updates on this:

Finally, I squashed some of my old commits and hopefully followed the Semantic Release principles. I submitted a PR. Let me know if this is looking okay :)

As for the external file refs, those would be especially useful in my use-case. I could work around this if there's a way to use local schema refs to a global definitions object inside an apib file.

honzajavorek commented 7 years ago

@joaosa Great! 👍 🎉 💕

Everything looks really great. Thank you!


Regarding external file refs, I think it's okay to support it in Gavel, but we really need to test that it will interpret only valid JSON Schema files, not files like /etc/passwd (would disclose sensitive data), /dev/zero (can eat all memory), etc. People run Dredd on their CIs, we need to prevent any vulnerabilities. Would you mind adding tests for this?

If you're not sure about it, I can help with the test cases.

joaosa commented 7 years ago

@honzajavorek thank you! Glad to have contributed :)

Thanks for describing the test scenarios. I'll look into it next!

honzajavorek commented 7 years ago

@joaosa I merged the first PR meanwhile. Thanks again! Let me know if you get any far with the additional test cases.

honzajavorek commented 7 years ago

Closing this in favor of https://github.com/apiaryio/gavel.js/issues/89. Thanks @joaosa! 🎉