nfroidure / whook

Build strong and efficient REST web services.
https://slides.com/nfroidure/introducing-whook
MIT License
31 stars 6 forks source link

Mutualise compilation of OpenAPI schemas #118

Open nfroidure opened 3 years ago

nfroidure commented 3 years ago

Currently, we are doing some ugly hacks to properly handle the OpenAPI files due to some legacy in the HTTP router. Most of it is done here: https://github.com/nfroidure/whook/blob/master/packages/whook-http-router/src/libs/openAPIUtils.ts#L108-L257

It basically de-references all the $refs that the router would not handle by its own. Best would be to not have to do this and instead get the router to cleanly handle those refs.

It would make the overhaul more memory efficient (no duplication) and the first boot would be more perfomant. It would also allow to simplify the AWS Lambda / GCP Functions builds done here: https://github.com/nfroidure/whook/blob/master/packages/whook-aws-lambda/src/services/_autoload.ts#L74-L117

It will also help to avoid having to merge parameters here: https://github.com/nfroidure/whook/blob/master/packages/whook-http-router/src/libs/openAPIUtils.ts#L87-L88

The schema may not be compiled upfront (maybe check AJVs options) but those reusable components could probably:

In a more general manner, replacing the WhookRawOperation type by either : just the route operationId for the http-router or the openapi file reduced in order to be valid but scoped to the operationid openapi file for the aws lambdas/gcp functions would probably be the more wide usable and generic way to handle the parameters handling of the routes.

Technical tasks