Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(typescript): types for schemaController #3369

Merged
merged 5 commits into from Oct 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions fastify.d.ts
Expand Up @@ -15,6 +15,8 @@ import { FastifySchemaValidationError } from './types/schema'
import { ConstructorAction, ProtoAction } from "./types/content-type-parser";
import { Socket } from 'net'
import { Options as FJSOptions } from 'fast-json-stringify'
import { ValidatorCompiler } from '@fastify/ajv-compiler'
import { FastifySerializerCompiler } from './types/schema';

/**
* Fastify factory function for the standard fastify http, https, or http2 server instance.
Expand Down Expand Up @@ -126,6 +128,17 @@ export type FastifyServerOptions<
constraints?: {
[name: string]: ConstraintStrategy<FindMyWayVersion<RawServer>, unknown>,
},
schemaController?: {
bucket?: (parentSchemas?: unknown) => {
addSchema(schema: unknown): FastifyInstance;
getSchema(schemaId: string): unknown;
getSchemas(): Record<string, unknown>;
};
compilersFactory?: {
buildValidator?: ValidatorCompiler;
buildSerializer?: (externalSchemas: unknown, serializerOptsServerOption: FastifyServerOptions["serializerOpts"]) => FastifySerializerCompiler<unknown>;
};
};
return503OnClosing?: boolean,
ajv?: {
customOptions?: AjvOptions,
Expand Down
15 changes: 15 additions & 0 deletions test/types/fastify.test-d.ts
Expand Up @@ -26,9 +26,24 @@ expectType<FastifyInstance<https.Server, http.IncomingMessage, http.ServerRespon
expectType<FastifyInstance<http2.Http2Server, http2.Http2ServerRequest, http2.Http2ServerResponse> & PromiseLike<FastifyInstance<http2.Http2Server, http2.Http2ServerRequest, http2.Http2ServerResponse>>>(fastify({ http2: true, http2SessionTimeout: 1000 }))
expectType<FastifyInstance<http2.Http2SecureServer, http2.Http2ServerRequest, http2.Http2ServerResponse> & PromiseLike<FastifyInstance<http2.Http2SecureServer, http2.Http2ServerRequest, http2.Http2ServerResponse>>>(fastify({ http2: true, https: {}, http2SessionTimeout: 1000 }))
expectType<LightMyRequestChain>(fastify({ http2: true, https: {} }).inject())
expectType<FastifyInstance<https.Server, http.IncomingMessage, http.ServerResponse> & PromiseLike<FastifyInstance<https.Server, http.IncomingMessage, http.ServerResponse>>>(fastify({ schemaController: {} }))
expectType<FastifyInstance<https.Server, http.IncomingMessage, http.ServerResponse> & PromiseLike<FastifyInstance<https.Server, http.IncomingMessage, http.ServerResponse>>>(
fastify({
schemaController: {
compilersFactory: {}
}
})
)

expectError(fastify<http2.Http2Server>({ http2: false })) // http2 option must be true
expectError(fastify<http2.Http2SecureServer>({ http2: false })) // http2 option must be true
expectError(
fastify({
schemaController: {
bucket: () => ({}) // cannot be empty
}
})
)

// light-my-request
expectAssignable<InjectOptions>({ query: '' })
Expand Down