fastify-type-provider-typebox icon indicating copy to clipboard operation
fastify-type-provider-typebox copied to clipboard

Type.Record Generating Incorrect Model in Fastify

Open LR-EbramMekhail opened this issue 1 year ago • 2 comments

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

image

Expected Behavior

"String": number

Example:

"test": 123

LR-EbramMekhail avatar Apr 10 '24 19:04 LR-EbramMekhail

You should provide the exact version of typebox you use otherwise we cannot determine if the result is related to which library.

climba03003 avatar Apr 11 '24 03:04 climba03003

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" }.

climba03003 avatar Apr 11 '24 04:04 climba03003