krakenjs / swaggerize-express

Design-driven apis with swagger 2.0 and express.
Other
354 stars 81 forks source link

Why enjoi? #102

Open deyceg opened 8 years ago

deyceg commented 8 years ago

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!

tlivings commented 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.

shattar commented 8 years ago

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?

jsdevel commented 8 years ago

@shattar that's the approach we've taken with express-openapi and it's worked out incredibly well.

Kashio commented 7 years ago

@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

jsdevel commented 7 years ago

express-openapi is design driven in the sense that your directory structure mirrors your paths.

Kashio commented 7 years ago

from what I've seen you have to create everything yourself, paths, files, from the example in the readme

jsdevel commented 7 years ago

right, so there isn't a generator for express-openapi if that's what you mean.

tlivings commented 7 years ago

@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.

mihir83in commented 5 years ago

@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 ?

tlivings commented 5 years ago

@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.