swaggerize-express icon indicating copy to clipboard operation
swaggerize-express copied to clipboard

Why enjoi?

Open deyceg opened this issue 9 years ago • 10 comments

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!

deyceg avatar May 11 '16 17:05 deyceg

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.

tlivings avatar May 20 '16 15:05 tlivings

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 avatar Jul 06 '16 15:07 shattar

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

jsdevel avatar Jul 06 '16 16:07 jsdevel

@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

Kashio avatar Oct 08 '16 22:10 Kashio

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

jsdevel avatar Oct 08 '16 23:10 jsdevel

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

Kashio avatar Oct 08 '16 23:10 Kashio

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

jsdevel avatar Oct 08 '16 23:10 jsdevel

@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 avatar Oct 09 '16 14:10 tlivings

@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 avatar Oct 05 '18 14:10 mihir83in

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

tlivings avatar Oct 08 '18 04:10 tlivings