### install ```bash npm install @fastify-dev-toolkit/plugin npm install ts-patch // add to package.json scripts: { "prepare": "ts-patch install -s" } ```
npm install @fastify-dev-toolkit/pluginbash
npm install @fastify-dev-toolkit/plugin
npm install ts-patch
// add to package.json
scripts: {
"prepare": "ts-patch install -s"
}
`add this in tsconfig.json
`json
{
"compilerOptions": {
"plugins": [
{
"transform": "@fastify-dev-toolkit/plugin/compiler/transformer", // auto compiler plugin
"transformProgram": true
}
]
}
}
``html
/
└── src
├── routes // file route
└── schema // type def in this folder will auto build to json schema
`example
`
/
└── src
├── routes
│ └── api
│ └── v1
│ └── test.ts // url for /api/v1/test
└── schema
└── api
└── one.ts
``typescript
// /api/v1/test.ts
import {A, B} from '../schema/api/one' export default class AAA {
get(): string {
return 'ok'
}
post(request?: IPost<{ Body: Omit, Querystring: B }>): string {
return 'ok'
}
put(): string {
return ''
}
delete(): string {
return ''
}
}
`
`typescript
// /schema/api/one.ts
type A = {
a: string
b: number
c: MultipartUploadField
}
type B = {
a: string
b: number
}
`if the ENVIRONMENT=development exist.
PORT=4002
use /documentation/ to view swagger
need ts-patch and add this in scripts
`json
scripts: {
"prepare": "ts-patch install -s"
}
``