3.1.0 • Published 8 months ago

fastify-extract-definitions v3.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

fastify-extract-definitions

NPM version Tests

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

keytypedefaultdescription
enabledbooleanfalseIs the plugin enabled?
ignoreHeadbooleanfalseIgnore HEAD endpoints
outputsobject{}Outputs config
compilerOptionsobjectSee json-schema-to-typescript default optionsjson-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

3.1.0

8 months ago

3.0.1

9 months ago

3.0.0

9 months ago

2.2.2

11 months ago

2.2.1

1 year ago

2.2.0

2 years ago

1.2.0

2 years ago

1.1.0

2 years ago

1.0.0

2 years ago

1.3.0

2 years ago

2.1.2

2 years ago

2.1.1

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago