jsonschema-generator icon indicating copy to clipboard operation
jsonschema-generator copied to clipboard

LocalDateTime and "date-time"

Open mbechto opened this issue 1 year ago • 3 comments

Currently, a LocalDateTime field in a POJO will generate a schema field with "format": "date-time".

Looking at the JSON Schema spec (section 7.3.1), "date-time" seems to denote a timestamp after RFC 3339, section 5.6, which must include a "time-offset" so either "Z" or a numerical offset.

If that is true, "date-time" is not an applicable format for LocalDateTime, right?

mbechto avatar Mar 18 '25 17:03 mbechto

Hi @mbechto,

Thanks for the input. Your argument seems sound. I suppose that means LocalDateTime can only be treated as { "type": "string" } without any format then. Pity.

Do you care to provide the PR for it?

CarstenWickner avatar Mar 22 '25 21:03 CarstenWickner

@CarstenWickner, I can try when I find some time.

Do you think it should be implemented as an option for backward compatibility?

I suppose that means LocalDateTime can only be treated as { "type": "string" } without any format then. Pity.

Right. But a simple regex could be added as "pattern", e.g.:

^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?$

mbechto avatar Mar 24 '25 16:03 mbechto

I'm open to removing the invalid "format". I'm hesitant regarding the "pattern" though. 9999-99-99T99:99:99.9999999999 would satisfy that regular expression as well, while not being a valid timestamp. With the various opinions on how strict/simple/complex it would need to be, I'd rather omit it and leave it up to the configuration, i.e., you could easily add that pattern for LocalDateTime instances if you wanted to.

CarstenWickner avatar Mar 24 '25 16:03 CarstenWickner