Prerequisites
Fastify version
4.0.0
Plugin version
No response
Node.js version
18.14.1
Operating system
macOS
Operating system version (i.e. 20.04, 11.3, 10)
Ventura 13.2.1
Description
I'm using the following validation schema for my response:
const responseSchema = {
type: "object",
required: ["ok", "data", "message"],
properties: {
ok: {
type: "boolean",
},
data: {
type: "object",
required: ["token"],
properties: {
token: {
type: "string",
nullable: true,
},
},
},
message: {
type: "string",
},
},
};
export const getSchema: RouteShorthandOptions = {
schema: {
response: {
200: responseSchema,
500: responseSchema,
},
},
};
When trying to send the following response in my endpoint:
return rep.status(500).send({
ok: false,
data: {},
message: "Access Token creation failed.",
});
It correctly fails because token is not present, but instead of showing the token field it returns the ok field:
{
"statusCode": 500,
"error": "Internal Server Error",
"message": "\"ok\" is required!"
}
It is basically returning the first field that finds in an array of required elements which corresponds to the parent object (ok field), instead of returning the specific field that is failing validation (token).
Trying Fastify for the first time and so far the experience is great, just found out this little issue, thanks!
Steps to Reproduce
Copy-paste the schema provided in the description pass it to the endpoint and hit it with Postman or curl.
Expected Behavior
Should return the name of the field that is failing the validation.
Prerequisites
Fastify version
4.0.0
Plugin version
No response
Node.js version
18.14.1
Operating system
macOS
Operating system version (i.e. 20.04, 11.3, 10)
Ventura 13.2.1
Description
I'm using the following validation schema for my response:
When trying to send the following response in my endpoint:
It correctly fails because token is not present, but instead of showing the token field it returns the ok field:
It is basically returning the first field that finds in an array of required elements which corresponds to the parent object (
okfield), instead of returning the specific field that is failing validation (token).Trying Fastify for the first time and so far the experience is great, just found out this little issue, thanks!
Steps to Reproduce
Copy-paste the schema provided in the description pass it to the endpoint and hit it with Postman or curl.
Expected Behavior
Should return the name of the field that is failing the validation.