diff --git a/pkg/codegen/schema.go b/pkg/codegen/schema.go index d8001f199..567437a6e 100644 --- a/pkg/codegen/schema.go +++ b/pkg/codegen/schema.go @@ -553,7 +553,7 @@ func oapiSchemaToGoType(schema *openapi3.Schema, path []string, outSchema *Schem case "date": outSchema.GoType = "openapi_types.Date" case "date-time": - outSchema.GoType = "time.Time" + outSchema.GoType = "openapi_types.Time" case "json": outSchema.GoType = "json.RawMessage" outSchema.SkipOptionalPointer = true diff --git a/pkg/types/date.go b/pkg/types/date.go index 6ad852f63..b896bf6c9 100644 --- a/pkg/types/date.go +++ b/pkg/types/date.go @@ -41,3 +41,28 @@ func (d *Date) UnmarshalText(data []byte) error { d.Time = parsed return nil } + +type Time struct { + time.Time +} + +func (t *Time) UnmarshalJSON(data []byte) error { + var timeStr string + err := json.Unmarshal(data, &timeStr) + if err != nil { + return err + } + parsed, err1 := time.Parse(time.RFC3339, timeStr) + if err1 == nil { + t.Time = parsed + return nil + } + + parsed2, err2 := time.Parse("2006-01-02 15:04:05-07:00", timeStr) + if err2 == nil { + t.Time = parsed2 + return nil + } + + return err1 +}