forked from fastify/fastify-type-provider-json-schema-to-ts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
47 lines (43 loc) · 1.55 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import {
FastifyTypeProvider,
FastifyPluginOptions,
RawServerBase,
RawServerDefault,
FastifyPluginCallback,
FastifyPluginAsync
} from 'fastify'
import { JSONSchema7, FromSchema, FromSchemaOptions, FromSchemaDefaultOptions } from 'json-schema-to-ts'
export interface JsonSchemaToTsProvider<Options extends FromSchemaOptions = FromSchemaDefaultOptions> extends FastifyTypeProvider {
output: this['input'] extends JSONSchema7 ? FromSchema<this['input'], Options> : never;
}
/**
* FastifyPluginCallback with JSON Schema to Typescript automatic type inference
*
* @example
* ```typescript
* import { FastifyPluginCallbackJsonSchemaToTs } from "@fastify/type-provider-json-schema-to-ts"
*
* const plugin: FastifyPluginCallbackJsonSchemaToTs = (fastify, options, done) => {
* done()
* }
* ```
*/
export type FastifyPluginCallbackJsonSchemaToTs<
Options extends FastifyPluginOptions = Record<never, never>,
Server extends RawServerBase = RawServerDefault
> = FastifyPluginCallback<Options, Server, JsonSchemaToTsProvider>;
/**
* FastifyPluginAsync with JSON Schema to Typescript automatic type inference
*
* @example
* ```typescript
* import { FastifyPluginAsyncJsonSchemaToTs } fromg "@fastify/type-provider-json-schema-to-ts"
*
* const plugin: FastifyPluginAsyncJsonSchemaToTs = async (fastify, options) => {
* }
* ```
*/
export type FastifyPluginAsyncJsonSchemaToTs<
Options extends FastifyPluginOptions = Record<never, never>,
Server extends RawServerBase = RawServerDefault
> = FastifyPluginAsync<Options, Server, JsonSchemaToTsProvider>;