fix(bind): honor OpenAPI date, date-time and date-time-local format tags - #3145
Merged
Merged
Conversation
Co-authored-by: vishr <314036+vishr@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Resolve format tag conflicts with swag
Support OpenAPI date-time formats in time binding
Oct 2, 2026
This was referenced Oct 5, 2026
Map format:"date" (OpenAPI full-date) to 2006-01-02, state that the format tag applies to time.Time and *time.Time fields but not slices, and use the ok/nok subtest naming used elsewhere in bind_test.go.
vishr
marked this pull request as ready for review
October 5, 2026 19:10
vishr
added a commit
that referenced
this pull request
Oct 5, 2026
…ags (v4) (#3156) Backport of #3145. Swag and OpenAPI put format names such as `format:"date-time"` on `time.Time` fields. Since v4.14.0 added `format` tag support, the binder has treated those names as Go time layouts, so valid input failed to bind. - `date-time` uses the same RFC3339 decoding as an untagged `time.Time`, restoring the pre-v4.14.0 behavior. - `date-time-local` accepts `2006-01-02T15:04:05` with optional fractional seconds, rejects time-zone suffixes, and assigns UTC. - `date` accepts `2006-01-02` and assigns UTC. - Other `format` values are still Go layouts. Slice fields, JSON/XML decoding, and custom unmarshalers are unchanged. Refs #3107
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adding a swag
format:"date-time"tag to atime.Timefield made Echo read the OpenAPI format name as a Go time layout, which rejected valid RFC3339 input.This change recognizes three OpenAPI format names for
time.Timeand*time.Timefields in path, query, header, and form binding:date-timeuses the same standard-library text decoder as an untaggedtime.Time. It accepts RFC3339 timestamps withZor a numeric offset.date-time-localaccepts2006-01-02T15:04:05with optional fractional seconds and rejects time-zone suffixes.dateaccepts2006-01-02.Parsing uses Go's
timepackage, so it is as lenient as untaggedtime.Timebinding (for example, it accepts a comma before fractional seconds).dateanddate-time-localgive UTC times, as custom layouts without a time zone already do. That is Echo's parsing policy; the input itself does not specify UTC. The formats have distinct meanings in the OpenAPI registry. Other format values are still Go layouts. JSON/XML decoding, custom unmarshalers, and slice fields (which never used the format tag) are unchanged. TheDefaultBinderdoc also points HTMLdatetime-localinputs, which omit seconds by default, to a Go layout such as2006-01-02T15:04.Compared with master, the only inputs that bound before and now fail are the literal strings
date-time,date-time-local, anddate, which parsed to0000-01-01T00:00:00Z.Validation:
go test -race ./...,go vet ./...,staticcheck ./...,golint -set_exit_status ./...Fixes #3107