invalid jsonType: time.Time
ssmall opened this issue · 3 comments
It does not seem possible to validate schemas that contain strings with format date
as they will automatically get unmarshaled into a Go time.Time
and validation will fail with the message:
jsonschema: invalid jsonType: time.Time
The code on this Go Playground illustrates the issue: https://go.dev/play/p/Q1ciGF5PE5Y
Is this a bug with schema validation, or expected behavior? If it is expected behavior, is there a workaround to allow validating documents that contain date-formatted strings?
Thanks!
this is the expected behaviour;
the documentation clearly says value must be raw json value
i.e it must be string, boolean, number, map, array and composite of these.
in your case yaml unmarshalled it into time.Time
. you unmarshal that value into string.
There's actually no way to control this behavior. It is the default behavior of the YAML unmarshaler when unmarshaling to any
. Please reopen and consider a fix.
if you have used quotes around the value then it will get converted into string:
yamlString := `date: "2025-01-01"`