-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
schema.d.ts
55 lines (49 loc) · 1.75 KB
/
schema.d.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
48
49
50
51
52
53
54
55
import { ValidatorCompiler } from '@fastify/ajv-compiler'
import { FastifyInstance, FastifyServerOptions } from '../fastify'
/**
* Schemas in Fastify follow the JSON-Schema standard. For this reason
* we have opted to not ship strict schema based types. Instead we provide
* an example in our documentation on how to solve this problem. Check it
* out here: https://github.com/fastify/fastify/blob/main/docs/Reference/TypeScript.md#json-schema
*/
export interface FastifySchema {
body?: unknown;
querystring?: unknown;
params?: unknown;
headers?: unknown;
response?: unknown;
}
export interface FastifyRouteSchemaDef<T> {
schema: T;
method: string;
url: string;
httpPart?: string;
httpStatus?: string;
}
export interface FastifySchemaValidationError {
keyword: string;
instancePath: string;
schemaPath: string;
params: Record<string, string | string[]>;
message?: string;
}
export interface FastifyValidationResult {
(data: any): boolean | PromiseLike<any> | { error?: Error, value?: any }
errors?: FastifySchemaValidationError[] | null;
}
/**
* Compiler for FastifySchema Type
*/
export type FastifySchemaCompiler<T> = (routeSchema: FastifyRouteSchemaDef<T>) => FastifyValidationResult
export type FastifySerializerCompiler<T> = (routeSchema: FastifyRouteSchemaDef<T>) => (data: any) => string
export interface FastifySchemaControllerOptions{
bucket?: (parentSchemas?: unknown) => {
add(schema: unknown): FastifyInstance;
getSchema(schemaId: string): unknown;
getSchemas(): Record<string, unknown>;
};
compilersFactory?: {
buildValidator?: ValidatorCompiler;
buildSerializer?: (externalSchemas: unknown, serializerOptsServerOption: FastifyServerOptions['serializerOpts']) => FastifySerializerCompiler<unknown>;
};
}