fastify-type-provider-typebox
fastify-type-provider-typebox copied to clipboard
Type.Record Generating Incorrect Model in Fastify
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.3
Plugin version
4.0.0
Node.js version
v20.11.0
Operating system
Windows
Operating system version (i.e. 20.04, 11.3, 10)
Windows 10 Version 1809
Description
Type.Record from the @sinclair/typebox library does not generate a correct model. Model does not match expected structure. Instead it generates a unrelated Generic Model.
{
"additionalProp1": "string",
"additionalProp2": "string",
"additionalProp3": "string"
}
Steps to Reproduce
const TempModel = Type.Record(Type.String(), Type.Number())
export const testRoutes: FastifyPluginAsyncTypebox = async (fastify, opts) =>
{
fastify.post("/data", {
schema: {
description: "returns data",
tags: [TAG_TEST],
response: {
200: TempModel,
}
}
}, async (request, reply) => {
// DO NOTHING
});
}
Output
Expected Behavior
"String": number
Example:
"test": 123
You should provide the exact version of typebox you use otherwise we cannot determine if the result is related to which library.
I have double checked the output of typebox between version.
It provides similar output as
{
"type": "object",
"patternProperties": { "^(.*)$": { "type": "number" } },
}
The above property patternProperties is unsupported by Swagger UI which means it should not show any field in the output.
Somewhere in your schema is adding { "additionalProperties": { "type": "string" }.