【发布时间】:2022-10-01 15:09:25
【问题描述】:
我有以下路线
export default async function (fastify) {
// fastify routes here...
fastify.get(
\'/\',
{
schema: {
params: {
type: \'object\',
properties: {
id: {
type: \'number\',
description: \'configuration id\',
},
},
},
},
},
async (req) => {
console.log(req.params);
return {};
},
);
}
// Prefix for fastify autoload
export const autoPrefix = `/configuration/:id/jobs`;
如何在该函数中为我的所有路由设置参数模式,这样我就不会复制我的参数模式:
{
params: {
type: \'object\',
properties: {
id: {
type: \'number\',
description: \'configuration id\',
},
},
},
}
我知道我可以做到:
const params = {
type: \'object\',
properties: {
id: {
type: \'number\',
description: \'configuration id\',
},
},
};
fastify.get(
\'/\',
{
schema: {
params,
},
},
async (req) => {
console.log(req.params);
return {};
},
);
但是询问是否有一种方法我不需要为每条路线都这样做
标签: fastify