The following spec, when loaded, will result in an example value of "2019-09-12T00:00:00Z". This is because the literal 2019-09-12 is parsed as a time.Time by the go-yaml package with 0 values for the hours, minutes etc and this is then formatted
as the full value when marshaled back to json using. the invopop/yaml package. The fix is somewhat ugly and shown below, I'll put together a PR shortly for it, but am open to better solutions.
openapi: 3.0.1
components:
schemas:
API:
properties:
dateExample:
type: string
format: date
example: 2019-09-12
A possible fix is the following change:
func (schema *Schema) UnmarshalJSON(data []byte) error {
err := jsoninfo.UnmarshalStrictStruct(data, schema)
if schema.Format == "date" {
if eg, ok := schema.Example.(string); ok {
eg = strings.TrimSuffix(eg, "T00:00:00Z")
schema.Example = eg
}
}
return err
}
The following spec, when loaded, will result in an example value of "2019-09-12T00:00:00Z". This is because the literal 2019-09-12 is parsed as a time.Time by the go-yaml package with 0 values for the hours, minutes etc and this is then formatted
as the full value when marshaled back to json using. the invopop/yaml package. The fix is somewhat ugly and shown below, I'll put together a PR shortly for it, but am open to better solutions.
A possible fix is the following change: