devlinjunker / test.openapi.server

Testing OpenAPI/Swagger Server-side Generation

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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
  • 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 (uses tsoa.doc.ts)
    • npm run serve-tsoa - run express server on http://localhost:3000 (uses server.ts to run
  • template.hbs used to generate routes.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 (uses typoa.doc.ts)
    • npm run serve-typoa - run express server on http://localhost:3000 (uses server.ts to run app.ts with routes)
  • Generated by build script:
    • src/typoa/build/routes.ts
    • spec/tsoa-openapi.yaml
  • template.hbs used to generate routes.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

About

Testing OpenAPI/Swagger Server-side Generation


Languages

Language:TypeScript 60.6%Language:Handlebars 39.4%