x-express-openapi-additional-middleware when not using JS APIDoc?
See original GitHub issueIs 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:
- Created 5 years ago
- Reactions:1
- Comments:10 (5 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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!
@SkyaTura feel free to submit a PR.