An example project to demonstrate how the OpenAPI schema can be used as the source of truth for a server.
The OpenAPI schema defines all the endpoints of the server.
Redocly bundles all the OpenAPI files in the config
folder into a single spec.
openapi-typescript generates type definitions, of all models in the endpoints, from the bundled OpenAPI spec.
fastify-openapi-glue plugs in the endpoints and models to fastify and handles all the routing and authentication.
- node 18
- pnpm
Command | Purpose |
---|---|
dev | Run the server locally |
build | Bundle the OpenAPI internal and public schemas, generate type definitions and build the project |
verify | Generates the OpenAPI schemas, type definitions and builds and lints the project |
preview | View the public API documentation |
test | Runs all the unit tests |
Note: after making a change to openapi.yml
, run pnpm build
to update all the models and server code.
Folder | Usage |
---|---|
config | Used to store the OpenAPI schema, separated into folders for each component type |
module | Database repository, service and controller code for each module in the service |
server | Functions used to start and run the server |
types | Type declarations within the modules |
util | Helper functions |
- Some dependencies are using older versions to use CommonJS. The same principles will work in ESM.
- The API key authentication is not secure or well crafted, it has been included to show the usage of hooking in the
security methods of
fastify-openapi-glue
.