Open deyceg opened 8 years ago
Because Swagger is based on json-schema and enjoi converts it to a Joi schema for validation. Hapi supports Joi directly whereas we need to provide middleware that calls the Joi validation in express.
Follow up question. Why is Joi being used at all if the swagger schema is based on json-schema and not Joi schema? Why not use a json schema validator to validate against a json schema?
@shattar that's the approach we've taken with express-openapi and it's worked out incredibly well.
@jsdevel but this approach is design driven, meaning all you have to do is to design the spec of your api and let this module generate a nice express server for you, judging from the readme docs, express-openapi is not, correct me if I'm wrong
express-openapi
is design driven in the sense that your directory structure mirrors your paths.
from what I've seen you have to create everything yourself, paths, files, from the example in the readme
right, so there isn't a generator for express-openapi
if that's what you mean.
@shattar at the time there were wasn't a json-schema validator faster than Joi. The other reason is hapi's native support for Joi. We are, however, in the process of updating to is-my-json-valid
or another schema validator.
The difficulty in doing validation at all is that Swagger (OpenAPI) is not true json-schema and has various oddities (such as introducing a new primitive that can't be validated by value).
@Kashio express-openapi
is basically the same concept as this module. @jsdevel wrote it to solve problems he wasn't overcoming with this module afaik.
@tlivings Are you guys still using it? I am looking for swagger schema based validator that can be customized to perform additional checks as well, enjoi looks good, but since you were in the process of updating it, have you found a better alternative ?
@mihir83in enjoi? Yes - but mostly for hapi-openapi. Swaggerize-express is in limbo but has a branch that is much updated and no longer depending on enjoi.
If you are not bound to hapi I would recommend ajv or is-my-json-valid for json schema and https://github.com/APIDevTools/swagger-parser for parsing swagger.
Probably missing something obvious, but was curious as to why you dont use joi directly in the express version but do in the hapi version!