-
-
Notifications
You must be signed in to change notification settings - Fork 28
Open
Description
Prerequisites
- I have written a descriptive issue title
- I have searched existing issues to ensure the feature has not already been requested
🚀 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);
},
);
};
Metadata
Metadata
Assignees
Labels
No labels