Skip to content

Commit

Permalink
Finishing touches
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Broadbent committed Dec 5, 2023
1 parent e89433d commit 3be1450
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 181 deletions.
3 changes: 2 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
build/
node_modules/
node_modules/
src/types/generated/
17 changes: 10 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,21 @@ 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](https://www.npmjs.com/package/openapi-typescript) generates type definitions, of all models in the endpoints, from the bundled OpenAPI spec.
[openapi-typescript](https://www.npmjs.com/package/openapi-typescript) generates type definitions, of all models in the
endpoints, from the bundled OpenAPI spec.

[fastify-openapi-glue](https://www.npmjs.com/package/fastify-openapi-glue) plugs in the endpoints and models to fastify and handles all the routing and authentication.
[fastify-openapi-glue](https://www.npmjs.com/package/fastify-openapi-glue) plugs in the endpoints and models to fastify
and handles all the routing and authentication.

## Prerequistes
## Prerequisites

- node 18
- pnpm

## Commands

| Command | Purpose |
| ------------ | -------------------------------------------------------------------------------- |
|--------------|----------------------------------------------------------------------------------|
| dev | Run the server locally |
| openapi | Bundle the OpenAPI internal and public schemas, and generate type defitions |
| verify | Generates the OpenAPI schemas, type definitions and builds and lints the project |
Expand All @@ -30,7 +32,7 @@ Note: after making a change to `openapi.yml`, run `pnpm openapi` to update all t
## Structure

| 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 |
Expand All @@ -39,5 +41,6 @@ Note: after making a change to `openapi.yml`, run `pnpm openapi` to update all t

## Notes

- Some dependancies 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`.
- 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`.
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "openapi-test",
"name": "openapi-demo",
"version": "0.1.0",
"description": "OpenAPI Demo",
"author": "Alexander Broadbent",
Expand All @@ -12,13 +12,13 @@
"build": "tsc",
"dev": "NODE_ENV=local nodemon -r dotenv-flow/config --watch src --files src/index.ts",
"test": "jest",
"verify": "pnpm openapi && pnpm lint && pnpm build && pnpm openapi:validate",
"openapi": "pnpm openapi:generate-internal && pnpm openapi:generate-api && pnpm openapi:generate-types",
"openapi:generate-api": "redocly bundle api -o ./src/config/openapi.bundle.json",
"openapi:generate-internal": "redocly bundle internal -o ./src/config/openapi-internal.bundle.json",
"openapi:generate-types": "openapi-typescript ./src/config/openapi-internal.bundle.json --output ./src/types/generated/openapi-schema.ts",
"openapi:validate": "redocly lint --lint-config error",
"docs:preview": "concurrently \"http-server docs/public\" \"open http://127.0.0.1:8080\""
"docs:preview": "concurrently \"http-server docs/public\" \"open http://127.0.0.1:8080\"",
"verify": "pnpm openapi:validate && pnpm openapi && pnpm lint && pnpm build",
"openapi": "pnpm bundle:internal && pnpm bundle:api && pnpm generate:types",
"openapi:validate": "redocly lint internal --lint-config error",
"bundle:api": "redocly bundle api -o ./src/config/openapi.bundle.json",
"bundle:internal": "redocly bundle internal -o ./src/config/openapi-internal.bundle.json",
"generate:types": "openapi-typescript ./src/config/openapi-internal.bundle.json --output ./src/types/generated/openapi-schema.ts"
},
"repository": {
"type": "git",
Expand Down
Loading

0 comments on commit 3be1450

Please sign in to comment.