krakenjs / swaggerize-routes

Swagger document driven route builder.
Other
58 stars 57 forks source link

Use enjoi for input validation. #11

Closed tlivings closed 10 years ago

tlivings commented 10 years ago

Rather than tv4, use enjoi for input validation.

Likely API schema validation will need to remain the same due to the broken Swagger 2.0 schema.

jorgemsrs commented 10 years ago

Hello @tlivings.

I'm considering swagger spec and this implementation for my company data aggregation layer. While reading the code I wondered (read master branch) about the decision to use enjoi instead of tv4. I prefer tv4 mainly because it's seems more performant (http://cosmicrealms.com/blog/2014/02/07/benchmark-of-node-dot-js-json-validation-modules-part-2/).

Could you share the rationale behind this issue?

tlivings commented 10 years ago

Hi, sure.

The link you reference has questionable benchmarks. When I ran my own benchmarks, which you can run by calling npm run bench in swagaerize-builder, joi validation is actually much faster. I suspect the benchmark run in that link was done without pre-building the joi schema, which I do.

In addition, I found I had better validation results with enjoi, since I resolved $ref up front.

Finally, since I also wrote a swaggerize-hapi module, hapi handles the input validation automatically if you provide it a joi schema, which was a really nice fit.

Hope this helps answer your question.

tlivings commented 10 years ago

Closing this since it's already done in 2.0.0.