Closed mdmower-csnw closed 2 months ago
Usage instructions could be incorporated into https://github.com/cdimascio/express-openapi-validator/tree/master/examples/5-custom-operation-resolver, but maybe the name should change to 5-operation-resolvers
with two sections: esm tips and custom resolvers? Then the link in the documentation on operation handlers would need to be updated as well. Let me know how I can help.
Make the default request handler resolver work in ESM projects by allowing a URL value for
options.operationHandlers
. If a URL is passed, then a dynamic import will be used to load handler modules. If a string is passed, thenrequire()
will be used.Existing projects should not be adversely affected by this change. The assignment of a
URL
value tooptions.operationHandlers
would be the indicator that a user wants to opt-in to this new import handling.Fixes #660 Fixes #838
Notice
Because this project uses
moduleResolution:node
intsconfig.json
, it's not possible to writeasync import(...)
directly in code. It has to be obscured so that the compiler does not replace it withrequire()
. Hence, there is a very obvious HACK! in this PR that obscuresimport()
viaFunction('x', 'return import(x)')
(it's very similar toeval('import(...)')
).This hack will probably sink this PR, but I figured I'd post it at least as a proof of concept. Ideally, the module resolution for tsconfig would be updated to
Node16
, but that brings its own issues sinceresolveJsonModule:true
would no longer work. Fix one issue, introduce another...Usage example
When defining
x-eov-operation-handler
in schemas, include the file extension on the module name. For example: