question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

loadSpec() issues, asynchronous middleware registration

See original GitHub issue

In some cases it may not ideal to have express-openapi-validator load and dereference the provided Open API spec on its own.

Would it be feasible for us to add support for a string or buffer argument in place of filePath in loadSpec() which skips the JSON scheme dereferencing and calls to fs?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
faroceanncommented, Mar 5, 2020

Yes, it’s no longer necessary – Thank you so much for your help

1reaction
faroceanncommented, Mar 4, 2020

Update: I took a look and found out why doing this synchronously would be challenging, and why you chose deasync. 😄It looks the json-schema-ref-parser dependency is strictly async.

One much better approach I found was to use await

await new OpenApiValidator({
  apiSpec: spec,
  validateRequests: true,
  validateResponses: false
}).install()

Instead of a non-awaited .installSync(). This allows my middlewares to bootstrap in the order I want.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Strange behaviour of async middlewares (maybe need docs)
Hi! Yesterday we got next error (maybe bug - I don't know). If we call next() in the async middleware, our handler run...
Read more >
Don't get burned by missing await Calls for Async Code in ...
I recently got burned in an upgraded ASP.NET Core server application where a missing `await` statement caused wildly inconsistent and ...
Read more >
Asynchronous initialization in ASP.NET Core with custom ...
Async initialization middleware. A simple way to do it involves writing a custom middleware that ensures initialization is complete before ...
Read more >
Async/Await in Express Middleware - Stack Overflow
I get that async/await allows us to deal with the async code and work with the returned values easily, but in Express middleware...
Read more >
ASP.NET Core Middleware | Microsoft Learn
Middleware is software that's assembled into an app pipeline to handle requests and responses. Each component:.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found