3.1.0 • Published 8 months ago
fastify-extract-definitions v3.1.0
fastify-extract-definitions
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
.
Pre requirements
node.js
:>=10.*
fastify
:>=3.*
Installation
Install it with yarn:
yarn add fastify-extract-definitions
Or with npm:
npm install fastify-extract-definitions
Usage
Add it to your project with register, pass it some options, and you are done!
⚠️ Note! Use this plugin for development only, make sure it is disabled in production.
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.
Options
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 |
Outputs config
[outputPath: string]: {
target: 'serverTypes' | 'clientTypes';
};
License
MIT