fastify-extract-definitions
v3.1.0
Published
Retrieves TypeScript definitions from Fastify router schema
Downloads
825
Maintainers
Readme
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 [email protected]
.
For fastify@3
use [email protected]
.
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