Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type.Record Generating Incorrect Model in Fastify #135

Open
2 tasks done
LR-EbramMekhail opened this issue Apr 10, 2024 · 2 comments
Open
2 tasks done

Type.Record Generating Incorrect Model in Fastify #135

LR-EbramMekhail opened this issue Apr 10, 2024 · 2 comments

Comments

@LR-EbramMekhail
Copy link

Prerequisites

  • I have written a descriptive issue title
  • 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

@climba03003
Copy link
Member

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

@climba03003
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants