interagent / committee

A collection of Rack middleware to support JSON Schema.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Date validation for query params is not working properly, even if required is true

DevarajCoindcx opened this issue · comments

I have a route in which I want to add date validation for query params, but its getting passed to the controller without generating or responding with 400
localhost:3000/get_random?from_date=2020-111-11111&to_date=2021-11-22

Here is my swagger JSON

   "/get_random: {
      "get": {
        "summary": "get random",
        "parameters": [
          {
            "name": "from_date",
            "in": "query",
            "format": "date",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "to_date",
            "in": "query",
            "format": "date",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "successful"
          }
        }
      }
    }

Is this expected, or what should I do to validate date properly, even when it isn’t required

I ran it in v4.4.0 and could not reproduce it. Since I may be doing it wrong, can you give me more detailed reproducible code?

It's a problem with the schema itself - format key should be within schema i.e.

"schema": {
  "type": "string",
  "format": "date"
}

I've been using https://github.com/APIDevTools/swagger-cli to validate the schema itself (there's also https://github.com/Redocly/openapi-cli which seems to have better error feedback).

Yes, you're right, the schema is wrong, thanks!
(Sorry, I misread it as not returning a 400 response when it should be returning one in the first place, and wrote that it was handled correctly and not reproduced...)