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

date-time validation fails with ajv-formats@3.0.1 #96

Open
ghost opened this issue Apr 20, 2024 · 3 comments
Open

date-time validation fails with ajv-formats@3.0.1 #96

ghost opened this issue Apr 20, 2024 · 3 comments

Comments

@ghost
Copy link

ghost commented Apr 20, 2024

I have a schema as:

          "createDate": {
            "type": "string",
            "format": "date-time"
          },

It does not validate the below date:

        "createDate": "2024-04-15T00:00:00",

It fails on validation with the error below:

[
    {
        "instancePath": "/createDate",
        "schemaPath": "#/properties/createDate/format",
        "keyword": "format",
        "params": {
            "format": "date-time"
        },
        "message": "must match format \"date-time\""
    }
]

My settings are as below:

  • package.json:
    "ajv": "^8.12.0",
    "ajv-formats": "^3.0.1",

I just had to downgrade to "ajv-formats": "2.1.1"

@mustafababil
Copy link

There is no explicit changelog published but as the error message suggests date-time fields should have proper format; meaning that it must have timezone specified.

So, createDate should be like '2024-04-15T00:00:00Z'. You need to check if expecting a timezoned date-time value breaks any contract.

@radeno
Copy link

radeno commented May 9, 2024

Based on https://datatracker.ietf.org/doc/html/rfc3339#section-5.6 i see partial-time and time could be without timezone, so v3 is doing it too much restrictive. Only way is to revert into v2

@silverwind
Copy link

silverwind commented Jun 4, 2024

Based on https://datatracker.ietf.org/doc/html/rfc3339#section-5.6 i see partial-time and time could be without timezone, so v3 is doing it too much restrictive. Only way is to revert into v2

partial-time is part of the date-time but time-offset is also so the latter is required.

So the behaviour of requiring time-offset is in line with the RFC and the issue therefor invalid. I suggest you use ajv.addFormat to define your custom formats.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants