Skip to content

Commit

Permalink
fix: add routeOptions.schema to types (#5035)
Browse files Browse the repository at this point in the history
  • Loading branch information
Uzlopak committed Sep 13, 2023
1 parent 5f09e05 commit 128b6d4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
1 change: 1 addition & 0 deletions test/types/request.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ const getHandler: RouteHandler = function (request, _reply) {
expectType<FastifyContext<ContextConfigDefault>['config']>(request.routeOptions.config)
expectType<ContextConfigDefault & FastifyRouteConfig & FastifyContextConfig>(request.routeOptions.config)
expectType<FastifySchema>(request.routeSchema)
expectType<FastifySchema>(request.routeOptions.schema)

expectType<RequestHeadersDefault & RawRequestDefaultExpression['headers']>(request.headers)
request.headers = {}
Expand Down
23 changes: 12 additions & 11 deletions types/request.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,17 @@ export interface ValidationFunction {
errors?: null | ErrorObject[];
}

export interface RequestRouteOptions<ContextConfig = ContextConfigDefault> {
method: string,
url: string,
bodyLimit:number,
attachValidation:boolean,
logLevel:string,
version: string | undefined,
exposeHeadRoute: boolean,
prefixTrailingSlash: string,
config: FastifyContextConfig & FastifyRouteConfig & ContextConfig
export interface RequestRouteOptions<ContextConfig = ContextConfigDefault, SchemaCompiler = FastifySchema> {
method: string;
url: string;
bodyLimit:number;
attachValidation:boolean;
logLevel:string;
version: string | undefined;
exposeHeadRoute: boolean;
prefixTrailingSlash: string;
config: FastifyContextConfig & FastifyRouteConfig & ContextConfig;
schema: SchemaCompiler;
}

/**
Expand Down Expand Up @@ -79,7 +80,7 @@ export interface FastifyRequest<RouteGeneric extends RouteGenericInterface = Rou
readonly method: string;
readonly routerPath: string;
readonly routerMethod: string;
readonly routeOptions: Readonly<RequestRouteOptions<ContextConfig>>
readonly routeOptions: Readonly<RequestRouteOptions<ContextConfig, SchemaCompiler>>
readonly is404: boolean;
readonly socket: RawRequest['socket'];

Expand Down

0 comments on commit 128b6d4

Please sign in to comment.