Prerequisites
🚀 Feature Proposal
The params property on a request could be inferred from the URL, as long as it's passed as a string literal.
Motivation
This would prevent param names from being mistyped in the schema property or the URL, thus breaking type safety. It would also make code more concise as you wouldn't need to manually write another schema.
It was previously implemented here: https://github.com/sinclairzx81/fastify-typebox#Params
Example
(excuse me for using Typebox syntax for the schemas, I hope it's readable enough)
server.get(
"/queries/:queryId",
{
schema: {
response: { [200]: Type.String() },
params: Type.Object({ queryId: Type.String() }),
},
},
async (req, res) => {
await res.send(req.params.queryId);
},
);
};
The above code should work without params: Type.Object({ queryId: Type.String() }):
server.get(
"/queries/:queryId",
{
schema: {
response: { [200]: Type.String() },
},
},
async (req, res) => {
await res.send(req.params.queryId);
},
);
};
Prerequisites
🚀 Feature Proposal
The
paramsproperty on a request could be inferred from the URL, as long as it's passed as a string literal.Motivation
This would prevent param names from being mistyped in the schema property or the URL, thus breaking type safety. It would also make code more concise as you wouldn't need to manually write another schema.
It was previously implemented here: https://github.com/sinclairzx81/fastify-typebox#Params
Example
(excuse me for using Typebox syntax for the schemas, I hope it's readable enough)
The above code should work without
params: Type.Object({ queryId: Type.String() }):