cdimascio / express-openapi-validator

🦋 Auto-validates api requests, responses, and securities using ExpressJS and an OpenAPI 3.x specification
MIT License
920 stars 211 forks source link

Bring back V3 asynchronous API, or provide a trully synchronous API #852

Open leandrogoe opened 1 year ago

leandrogoe commented 1 year ago

Is your feature request related to a problem? Please describe. I was really excited to find this package and tried it in a few projects. We wanted to use it as a tool that would run as part of our unit tests, ensuring that all covered paths were compliant with open api specs. Unfortunately, after a while, I realized the asynchronous nature of the middleware load, which makes the test runs completely unreliable as some tests may run before the middleware has finished initializing.

Describe the solution you'd like I feel that currently, we give the package users the impression that everything is synchronous when in fact it is not. This design is misleading and can lead to very hard-to-debug issues. I think we should either go back to the old v3 api, or provider a truly synchronous API that loads everything upfront.

By the way, I cannot use v3 because of other issues, that were fixed on latest versions, so that is not an option for us.

Describe alternatives you've considered Either bring back V3 API or make the spec load REALLY synchronous.

Additional context I was also facing some strange issues during jest tests, which may be tied to the way the specs are load. I still can not fully track them, but I know they are related to this package:

oundingcipherhealthcom-business_layer-1  | Debugger listening on ws://0.0.0.0:9233/255262af-f65c-4dac-a876-9a57d9331cd9
roundingcipherhealthcom-business_layer-1  | For help, see: https://nodejs.org/en/docs/inspector
roundingcipherhealthcom-business_layer-1  | PASS test/services/scriptCompletionCalculator.test.ts
roundingcipherhealthcom-business_layer-1  | TypeError: Cannot read properties of undefined (reading 'enter')
roundingcipherhealthcom-business_layer-1  |     at AsyncHook.before (node:domain:97:20)
roundingcipherhealthcom-business_layer-1  |     at emitHook (node:internal/async_hooks:235:38)
roundingcipherhealthcom-business_layer-1  |     at emitBeforeScript (node:internal/async_hooks:512:5)
roundingcipherhealthcom-business_layer-1  |     at promiseBeforeHook (node:internal/async_hooks:341:3)
roundingcipherhealthcom-business_layer-1  | TypeError: Cannot read properties of undefined (reading 'enter')
roundingcipherhealthcom-business_layer-1  |     at AsyncHook.before (node:domain:97:20)
roundingcipherhealthcom-business_layer-1  |     at emitHook (node:internal/async_hooks:235:38)
roundingcipherhealthcom-business_layer-1  |     at emitBeforeScript (node:internal/async_hooks:512:5)
roundingcipherhealthcom-business_layer-1  |     at promiseBeforeHook (node:internal/async_hooks:341:3)