Skip to content

Commit

Permalink
types: request route schema might be undefined (#5394)
Browse files Browse the repository at this point in the history
* types: request route schema might be undefined

* Update types/request.d.ts

Co-authored-by: Manuel Spigolon <behemoth89@gmail.com>
Signed-off-by: Nico Flaig <nflaig@protonmail.com>

* Comment why it might be undefined / empty

Signed-off-by: Nico Flaig <nflaig@protonmail.com>

---------

Signed-off-by: Nico Flaig <nflaig@protonmail.com>
Co-authored-by: Manuel Spigolon <behemoth89@gmail.com>
  • Loading branch information
nflaig and Eomm committed May 7, 2024
1 parent b8cbd33 commit 445e41a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions test/types/request.test-d.ts
Expand Up @@ -79,8 +79,8 @@ const getHandler: RouteHandler = function (request, _reply) {
expectType<FastifyRequestContext<ContextConfigDefault>['config']>(request.routeConfig)
expectType<FastifyRequestContext<ContextConfigDefault>['config']>(request.routeOptions.config)
expectType<ContextConfigDefault & FastifyRouteConfig & FastifyContextConfig>(request.routeOptions.config)
expectType<FastifySchema>(request.routeSchema)
expectType<FastifySchema>(request.routeOptions.schema)
expectType<FastifySchema | undefined>(request.routeSchema)
expectType<FastifySchema | undefined>(request.routeOptions.schema)
expectType<RouteHandlerMethod>(request.routeOptions.handler)
expectType<string | undefined>(request.routeOptions.url)

Expand Down
4 changes: 2 additions & 2 deletions types/request.d.ts
Expand Up @@ -31,7 +31,7 @@ export interface RequestRouteOptions<ContextConfig = ContextConfigDefault, Schem
exposeHeadRoute: boolean;
prefixTrailingSlash: string;
config: FastifyContextConfig & FastifyRouteConfig & ContextConfig;
schema: SchemaCompiler;
schema?: SchemaCompiler; // it is empty for 404 requests
handler: RouteHandlerMethod;
}

Expand Down Expand Up @@ -64,7 +64,7 @@ export interface FastifyRequest<RouteGeneric extends RouteGenericInterface = Rou
body: RequestType['body'];
context: FastifyRequestContext<ContextConfig>;
routeConfig: FastifyRequestContext<ContextConfig>['config'];
routeSchema: FastifySchema
routeSchema?: FastifySchema; // it is empty for 404 requests

/** in order for this to be used the user should ensure they have set the attachValidation option. */
validationError?: Error & { validation: any; validationContext: string };
Expand Down

0 comments on commit 445e41a

Please sign in to comment.