POC to generate swagger docs for express API written in typescript.
There is a sample express app in sample
directory.
The generated output is save in openapi.json
file.
To test the generated file:
- Go to Swagger Editor
- Click File -> Import URL
- Paste in
https://raw.githubusercontent.com/nerijusdu/swagger-generator/master/sample/openapi.json
- Clone repo
npm i
npm start
(generates for sample app)
- handle request body type
- handle response type
- move types to definitions
- handle query params
- handle path params
- handle response status
- handle multiple types (oneOf)
- handle arrays
- Type in a type without a name e.g. type T = { a: { b: string } }
- handle nested routes e.g. app.use('/api', router);
- handle nested routes for duplicated routers e.g. app.use('/api', router); app.use('/api/v2/', router);
- handle nested routes in routers e.g. router.use('/api', router2)
- handle enums
- handle generics (PaginatedList)
- handle inline route types (router.get<{ id: number }>)
- handle type joins (&)
- assign generated names for Pick/Omit
- handle deep nested routers (with merged parameters)
- generate descriptions for responses
- test if type arrangement for IRequestMatcher is always the same
- enum parsing generates values instead of enums