fastify-type-provider-json-schema-to-ts
fastify-type-provider-json-schema-to-ts copied to clipboard
this package adds non-existing props to the generated type
Prerequisites
- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the bug has not already been reported
Fastify version
4.24.0
Plugin version
2.2.2
Node.js version
18.x
Operating system
Linux
Operating system version (i.e. 20.04, 11.3, 10)
22
Description
following your example:
const plugin: FastifyPluginAsyncJsonSchemaToTs = async function (
fastify,
_opts
) {
fastify.get(
"/",
{
schema: {
body: {
type: "object",
properties: {
x: { type: "string" },
y: { type: "number" },
z: { type: "boolean" },
},
required: ["x", "y", "z"],
} as const,
},
},
(req) => {
/// The `x`, `y`, and `z` types are automatically inferred
const { x, y, z } = req.body;
}
);
};
now req.body has the following type
{
// extra property that allows arbitrary props that don't exist in the original schema
[x: string]: unknown;
x: string;
y: string;
z: string;
}
remove the extra prop, and you may add an option to allow arbitrary props
Steps to Reproduce
.
Expected Behavior
No response
What happens if you do additionalProperties: false
What happens if you do
additionalProperties: false
this works, please add this note to the docs. also, I think it may be better to allow additional properties only if it set explicitly to trye