Skip to content

Commit

Permalink
Testing with iso extended formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Nan Huang committed Dec 14, 2022
1 parent a444d30 commit 27a0c36
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/codegen/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 25 additions & 0 deletions pkg/types/date.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 27a0c36

Please sign in to comment.