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

string auto convert to number #82

Closed
2 tasks done
miniboxhaha opened this issue May 10, 2023 · 2 comments
Closed
2 tasks done

string auto convert to number #82

miniboxhaha opened this issue May 10, 2023 · 2 comments

Comments

@miniboxhaha
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

3.2.0

Plugin version

No response

Node.js version

18.0

Operating system

Windows

Operating system version (i.e. 20.04, 11.3, 10)

win10

Description

use fastify with TypeBoxTypeProvider,validate will auto cast sting to number,and auto cast sting to string[]

for example code blow:

Steps to Reproduce

//server.ts
const server = fastify().withTypeProvider<TypeBoxTypeProvider>()
fastify.post<
            { Body: User[] }
        >('/marks', { schema: { body: properties} }, async (request, reply) => {
            try {
                reply.code(200).send()
            } catch (err) {
                reply.code(400).send(err)
            }
        }),

//validate.ts
export const properties = Type.Object({
   timestamp: Type.Readonly(Type.Integer()),
   users:Type.Optional(Type.Array(Type.String()))
})



//testData1:
{
   timestamp:1683687611279,
   users:["tom","jerry"]
}
expect:OK
result:OK

//testData2:
{
   timestamp:"1683687611279",
   users:"tom"
}
expect:False
result:OK

Expected Behavior

No response

@mcollina
Copy link
Member

This is expected because Fastify creates Ajv with coerceTypes: "array" by default: https://www.fastify.io/docs/latest/Reference/Validation-and-Serialization/#schema-validator.

@mcollina mcollina closed this as not planned Won't fix, can't repro, duplicate, stale May 15, 2023
@miniboxhaha
Copy link
Author

thanks,i will follow the doc

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