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.

x-express-openapi-additional-middleware when not using JS APIDoc?

See original GitHub issue

Is it possible to inject middleware that fires on all routes without using a JavaScript APIDoc?

I want to validate & load data based on the route provided (after req.params are initialized but before any services) while keeping the APIDoc in JSON or YAML for documentation generation.

As a work-around I’m keeping the API Doc separate then adding x-express-openapi-additional-middleware:

const fs = require('fs');
const path = require('path');
const validate = require('../middleware/validate');

let apiDoc = JSON.parse(fs.readFileSync(path.resolve(__dirname, './api-doc.json'), 'utf8'));
apiDoc['x-express-openapi-additional-middleware'] = [validate];

module.exports = apiDoc;

Is there an initialize setting I’m missing?

e.g.

    openapi.initialize({
        apiDoc: fs.readFileSync(path.resolve(__dirname, './api-doc.json'), 'utf8'),
        app: app,
        paths: path.resolve(__dirname, './routes'),
        middleware: {validate: validate}
    });

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:1
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
Frizzledcommented, Jun 26, 2018

That sounds great -

Having to merge logic into JSON or YAML isn’t a deal-breaker. I’m very happy with how fully Swagger 2.0 is supported; thanks for all the hard work on this project!

2reactions
jsdevelcommented, Feb 7, 2020

@SkyaTura feel free to submit a PR.

Read more comments on GitHub >

github_iconTop Results From Across the Web

express-openapi - npm
You can directly control what middleware express-openapi adds to your express app by using the following vendor extension properties. These ...
Read more >
How to add custom middleware to express-openapi-validator ...
js file), I've got a validateSecurity key, with a handlers key that then has the correlating keys that are in my swagger.yml (verifyApiKey...
Read more >
How to Build Better APIs in Express with OpenAPI
In this article, I will share how to build robust REST APIs in Express. First, I will present some of the challenges of...
Read more >
Express API with autogenerated OpenAPI doc through Swagger
In past years OpenAPI has arise as the preferred way to document APIs. ... REST API you more probably will desire to have...
Read more >
How to use the express-openapi.initialize function in ... - Snyk
userSession = payload; resolve( true ); } ); } ); initializedApi = initialize( { app, docPath: "api-docs", apiDoc: { ...v1ApiDoc, "x-express-openapi-additional- ...
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