krakenjs / swaggerize-routes

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

Use result after validation #28

Closed davidcl64 closed 9 years ago

davidcl64 commented 9 years ago

In some cases, passing additional options to the validator causes the incoming data to be changed.

For example, adding the enjoi settings:

allowUnknown: true
stripUnknown: true

Will cause any incoming, unknown properties to be removed from the object that is being validated.

This change ensures those results are used rather than the original, pre-validated object.

tlivings commented 9 years ago

I am not sure that this behavior of Joi should bleed through to generic behavior of validation for swagger.

We do it to coerce primitives on path parameters, but that's as a convenience for type. It doesn't remove properties.

davidcl64 commented 9 years ago

Fair enough - I had an internal debate with myself about this as well :).

In my case, using the Joi internals was the only way I could begin using this library and maintain backwards compatibility with an existing API.

In this case, though, replacing the body with the validated version using the default settings (ie: without me diving into the internals of joi) would end up with a body that was identical to the original wouldn't it?

tlivings commented 9 years ago

:+1:

tlivings commented 9 years ago

This already landed - not sure why the PR wasn't automatically closed.