Gathering detailed insights and metrics for @lambdacurry/express-oas-generator
Gathering detailed insights and metrics for @lambdacurry/express-oas-generator
Gathering detailed insights and metrics for @lambdacurry/express-oas-generator
Gathering detailed insights and metrics for @lambdacurry/express-oas-generator
OpenAPI (Swagger) specification generator for ExpressJS applications
npm install @lambdacurry/express-oas-generator
Typescript
Module System
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
Apache-2.0 License
225 Stars
280 Commits
42 Forks
11 Watchers
4 Branches
11 Contributors
Updated on Jul 02, 2025
Latest Version
1.0.56
Package Id
@lambdacurry/express-oas-generator@1.0.56
Unpacked Size
1.52 MB
Size
550.21 kB
File Count
103
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
10
3
Module to:
Note - make sure to also read the Advanced usage (recommended) section after this!
npm i express-oas-generator --save
;1const express = require('express'); 2const expressOasGenerator = require('express-oas-generator');
1let app = express(); 2expressOasGenerator.init(app, {}); // to overwrite generated specification's values use second argument.
Second argument of expressOasGenerator.init(app, {})
could be either an object or a function. In case of the object generated spec will be merged with the object. In case of function it will be used to apply changes for generated spec. Example of function usage:
1generator.init(app, function(spec) { 2 _.set(spec, 'info.title', 'New Title'); 3 _.set(spec, 'paths[\'/path\'].get.parameters[0].example', 2); 4 return spec; 5}); 6
To write specification into a file use third and forth (optional) arguments. Full signature of init()
function is following:
1expressOasGenerator.init( 2 app, 3 function(spec) { return spec; }, 4 'path/to/a/file/filename.json', 5 60 * 1000, 6 'api-docs', 7 ['User', 'Student'], 8 ['users', 'students'], 9 ['production'], 10 true, 11 SPEC_OUTPUT_FILE_BEHAVIOR.RECREATE 12)
where the last parameters are:
SPEC_OUTPUT_FILE_BEHAVIOR.RECREATE
- (Optional) Enum to indicate if the spec outfile file is recreated or preserved from current content (SPEC_OUTPUT_FILE_BEHAVIOR.PRESERVE
)Instead of using a single init
handler, we'll use 2 separate ones - one for responses, and one for requests.
1let app = express(); 2/** place handleResponses as the very first middleware */ 3expressOasGenerator.handleResponses(app, {}); 4 5/** initialize your `app` and routes */ 6 7/** place handleRequests as the very last middleware */ 8expressOasGenerator.handleRequests(); 9app.listen(PORT);
mind the order of the middleware handlers - first we apply the one for responses, then we apply the one for requests, which might seem counter-intuitive since requests come before responses, but this is how we need to do it because:
response.write()/end()
methods should be wrapped before any route or middleware call itbody-parser
Don't worry - we'll throw a loud error if you messed this up so that you can correct yourself quickly! 💥
See server_advanced.js for usage example.
In order to generate documentation, we need to analyze both responses and requests.
The tricky thing is - one handler must be placed as the very first middleware of the express app, and the other must be the very last. It is needed to intercept all the data (headers and payload) coming in and out out the app.
In the expressOasGenerator.init()
method, we assume that you place it straight after initializing the express app.
Inside we place response intercept middleware and then we call setTimeout
with 1000
miliseconds to make sure we place our request intercept middleware as the very last one.
The basic approach is error-prone because:
1000
milisecond setTimeout
passes and applies the request middleware.This could occur, for example, if you start your express server and then run the API tests immidiately - that wouldn't work. You'd have to start your server and then make your tests wait a second before the request middleware is applied.
If your service is running not at the root of the server add full base path URL to package.json
1{ 2 "baseUrlPath" : "/tokens" 3}
Here is a sample
1{ 2 "name": "cwt-sts-svc", 3 "version": "1.1.48", 4 "description": "JWT generation service", 5 "keywords": [], 6 "author": "", 7 "main": "lib", 8 "baseUrlPath" : "/tokens", 9 "bin": { 10 "cwt-sts-svc": "bin/server" 11 } 12}
This library uses swagger-ui-express as dependency , so if you need to edit the swagger's default documentation page style you can set swaggerDocumentOptions
. This option receives any custom swagger options and pass through when swaggerUi are configured.
You can follow these links to see how settings can be edited:
An basic example is:
generator.handleResponses(app, {
swaggerDocumentOptions: { customCss: '.swagger-ui { background-color: red }' }
});
And that would result in this:
Goal of the module is to provide developers with Swagger UI in development environments. Module process every request and response therefore it may slow down your app - is not supposed to be used in production environment.
Assuming you have ExpressJS REST API application and you
******
X-
treated as a apiKey type headers;Parameters and response body not documented!
Express-oas-generator (EOG) adds parameters handler as a very last middleware. If any middleware or path in router breaks the chain and doesn't pass execution to next middleware/router then very last EOG middleware won't be called. So call next() or next(err) as the very last line in your handler. Some docs:
For more info please read the entire issue report
Please read:
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 2/14 approved changesets -- score normalized to 1
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
0 commit(s) and 1 issue activity found in the last 90 days -- score normalized to 0
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
22 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More