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

Add multiple optional format validators like java.time.format.DataTimeFormatterBuilder #518

Open
jacob2221 opened this issue Jan 30, 2025 · 1 comment

Comments

@jacob2221
Copy link

Hi,

I have a field in JSON which may either just have a DATE in yyyy-MM-dd format or DATETIME in yyyy-MM-dd HH:mm:ss format. Similar to java.time.format.DateTimeFormatterBuilder where we can append optional formats to a base format, is there any way to do the same in everit without defining our own custom date format validator or any other code changes?

type: "string",
format: "date",
format:"time"

Regards
Jacob

@erosb
Copy link
Contributor

erosb commented Jan 30, 2025

Hello, adding duplicate keys to the schema json won't work, since keys in json should be unique (parsers will either throw an error, or pick one of the provided values).

On the other hand, you can do this with the "anyOf" json schema keyword as follows:

{
  "anyOf": [
    {
      "type": "string", "format": "date"
    },
    {
      "type": "string", "format": "datetime"
    }
  ]
}

By the way, this library is in maintenance mode, and it is very unlikely to see newer releases (and also won't support the latest version of json schema). I suggest migrating to https://github.com/erosb/json-sKema

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

No branches or pull requests

2 participants