fluent-json-schema icon indicating copy to clipboard operation
fluent-json-schema copied to clipboard

.string() method validate all type values

Open alifuma92 opened this issue 3 years ago • 1 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.1.0

Plugin version

3.1.0

Node.js version

16.14.12

Operating system

macOS

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

Monterey

Description

i try to validate my body prop "name" as a required string, but if i sent a number value from POSTMAN json, i've got an successful validation... it's very strange.

Steps to Reproduce

S.prop('name', S.string().required())

Expected Behavior

No response

alifuma92 avatar Jun 24 '22 15:06 alifuma92

It is not because the value is coerced.

https://github.com/fastify/fastify/blob/main/docs/Reference/Validation-and-Serialization.md#validation

Try:

const fastify = Fastify({
  ajv: {
    customOptions: {
      coerceTypes: false
    }
  }
})

Eomm avatar Jun 25 '22 09:06 Eomm

Not related to fluent-json-schema

aboutlo avatar Aug 25 '22 13:08 aboutlo