swagger-api / swagger-node

Swagger module for node.js
http://swagger.io
Apache License 2.0
3.97k stars 585 forks source link

INVALID_TYPE on Date format field #576

Closed ghost closed 5 years ago

ghost commented 5 years ago

Hello everyone! I'm using node/express and swagger-codegen. I've a "birthday" field on the /users endpoint like the following:

- name: birthday
  description: Data de nascimento do usuário
  required: false
  in: query
  type: string
  format: date

No error is shown on the Swagger Editor. However, when I try send a POST, using Postman, with the following JSON on the body:

{
     "birthday":"1985-04-12"
}

It throws the following error:

{
    "message": "Request validation failed: Parameter (birthday) is not a valid date string: {{birthday}}",
    "code": "INVALID_TYPE",
    "failedValidation": true,
    "path": [
        "paths",
        "/users",
        "post",
        "parameters",
        "4"
    ],
    "paramName": "birthday"
}

I can't understand the reason. The Date format I'm using is the specified on Swagger's documentation. YYYY-MM-DD If I remove the "format: date" from swagger.yaml and try again, it works, because it's just a string.

I'd really appreciate any help!

Thank you in advance