Skip to content

Richargh/api-first-typebox-to-swagger-via-fastify-npm-ts-sandbox

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

API First going from Typebox to Swagger with Fastify (Sandbox)

Features

  • Fastify + Typebox + TypeScript
  • Generated Swagger Schema based on registered routes and Typebox schemas
  • Swagger UI

Usage

  • npm run start and then, via httpie or cURL:
    • GET all users http localhost:8080/users?name=Taylor
    • CREATE new user http POST localhost:8080/users name=Alex
    • Check the generate Schema: http GET http://localhost:8080/docs/json
    • View the Swagger UI

Troubleshooting

  • Take care to always add routes inside a .register block. Otherwise swagger does not seem to pick up on them.

Created via

  • npm init -y
  • npm i fastify
  • npm i -D typescript @types/node ts-node
  • npx tsc --init and configure outdir: "dist", "target": "es2017" and other smaller things.
  • mkdir src && touch src/index.ts and put code from fastify swagger.
  • Add "build": "tsc" and "start": "ts-node src/server.ts" to package.json.
  • npm i @sinclair/typebox @fastify/type-provider-typebox @fastify/swagger and add /users with schema to src/index.ts according to the official docs

References

About

API First going from Typebox to Swagger with Fastify

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published