Automatically extracts TypeScript definitions from Fastify router schema and generates server and client typings. Based on json-schema-to-typescript package.
For fastify@>=4.2
use fastify-extract-definitions@1.3.0
.
For fastify@3
use fastify-extract-definitions@0.0.4
.
node.js
:>=10.*
fastify
:>=3.*
Install it with yarn:
yarn add fastify-extract-definitions
Or with npm:
npm install fastify-extract-definitions
Add it to your project with register, pass it some options, and you are done!
import Fastify from 'fastify';
import extractor from 'fastify-extract-definitions';
const fastify = Fastify();
fastify.register(extractor, {
enabled: process.env.NODE_ENV === 'development',
outputs: {
'./types.d.ts': {
target: 'serverTypes',
},
},
});
See example for more details.
key | type | default | description |
---|---|---|---|
enabled | boolean |
false |
Is the plugin enabled? |
ignoreHead | boolean |
false |
Ignore HEAD endpoints |
outputs | object |
{} |
Outputs config |
compilerOptions | object |
See json-schema-to-typescript default options | json-schema-to-typescript options |
onSchemaReady | (schema: JSONSchema4) => Promise<void> |
- | Set the handler to custom handle json schema |
[outputPath: string]: {
target: 'serverTypes' | 'clientTypes';
};
MIT