OpenAPI Tests
Testing OpenAPI/Swagger Generation Libraries for Servers
These were mostly created for swagger-jsdoc:
- Abstract Controller - Initially created this as super type to all controllers
- getMethods returns an array of MethodDefs that map routes to methods
- Example Types
- MethodDef
- ExampleError
- ExampleParam
- ExampleResponse
- BaseResponse
- ExampleMethod
- MethodDef
Swagger JSDoc
https://github.com/Surnet/swagger-jsdoc
- First Tried this
- Requires JSDoc at top of each method
- With full OpenAPI definition
- CON: needs to be updated with any changes to the API
npm run build-swagger-jsdoc
- to create swagger jsdoc openapi file- generates
spec/swagger-jsdoc-openapi.yaml
- generates
- PRO: Doesn't need typescript though (maybe?)
- CON: Creates some extra nonsense (
channels
) that needs to be removed to match OpenAPI spec
TSOA
https://github.com/lukeautry/tsoa
- Route and SpecFile configs defined in
tsoa.doc.js
- Scripts:
npm run build-tsoa
- create typoa openapi file (usestsoa.doc.ts
)npm run serve-tsoa
- run express server onhttp://localhost:3000
(usesserver.ts
to run
template.hbs
used to generateroutes.ts
file for server- CON: Missing
info.version
property but otherwise OpenAPI compliant - PRO: uses Typescript decorators
TYPOA
https://github.com/Eywek/typoa
- Tried this next
- Worked okay
- Based on TSOA - but uses
ts-morph
(what does this do exactly?) typoa.config.ts
- configuration for generating openapi- Added Scripts
npm run build-typoa
- create typoa openapi file (usestypoa.doc.ts
)npm run serve-typoa
- run express server onhttp://localhost:3000
(usesserver.ts
to runapp.ts
with routes)
- Generated by build script:
src/typoa/build/routes.ts
spec/tsoa-openapi.yaml
template.hbs
used to generateroutes.ts
file for server- PRO: Typescript Decorators
- PRO: Seemed to work best for generating OpenAPI compliant spec file
Notes
- Also added swagger-ui-express package to serve generated openapi yaml specs file
Ideas
- Postman/Newman for testing