fastify / fastify/help

Override FastifyTypeProviderDefault

Open
#734 8 comments 1 reaction 0 assignees View on GitHub
Dominant language
No language data
Stars
68
Forks
8
Avg merge
11h 2m
Merged PRs (30d)
2

Description

I would like to define a single route as a constant variable like this
```
const createTaskRoute: RouteOptions = {
url: '/task',
method: 'POST',
schema: {
body: {
type: 'object',
properties: {
title: {type: 'string'},
},
required: ['title'],
},
} as const,
handler: async (request) => {
// request.body is unknown
},
};
```
and register it somewhere else in a plugin like this:
```
function TaskRouter(app: FastifyInstance) {
app.route(createTaskRoute);
}
```
The issue is that the request body is of type unknown, despite using `@fastify/type-provider-json-schema-to-ts`. Is there any possiblity to have json-schema-to-ts support in the handler, without using the app as a FastifyInstance to override the `FastifyTypeProviderDefault`?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.