Skip to content

YYYY-M-D is incorrectly allowed as a format for dates #685

Closed
@DJTommek

Description

@DJTommek

Hi,
I'm struggling with validating "date" type. According to specifications it should be in format YYYY-MM-DD (4 digits - 2 digits - 2 digits) but this jsonschema validator is ok with YYYY-M-D.

Example schema snippet:

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

If I test it in https://www.jsonschemavalidator.net/ it properly throws error: String '2000-1-01' does not validate against format 'date'.

I don't think that is expected behaviour.

See live demo here: https://repl.it/@TomasPalider/QueasyDrabServerapplication

I came up with workaround by combination date and regex but I don't like it since schema validation should be strict.

"d": {
    "type": "string",
    "format": "date",
    "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}$"
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugSomething doesn't work the way it should.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions