Fix OpenAPI schema to render time.Time in date-time format#48
Merged
moutonjeremy merged 1 commit intomainfrom May 4, 2026
Merged
Fix OpenAPI schema to render time.Time in date-time format#48moutonjeremy merged 1 commit intomainfrom
moutonjeremy merged 1 commit intomainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the OpenAPI schema generator so nested time.Time values are documented as inline string fields with date-time format instead of generating a separate Time component schema. It also adds targeted tests around nested and pointer time.Time fields in generated specs.
Changes:
- Added
isTimeTypedetection and special-casedtime.Timeduring schema collection and field/schema generation. - Prevented
time.Timefrom being registered as a component schema. - Added tests asserting nested
time.Timeand*time.Timefields render inline asstring/date-time.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
fiberoapi.go |
Adds time.Time detection and inline schema generation changes in type collection and schema builders. |
time_type_test.go |
Adds OpenAPI generation tests for nested time.Time and pointer time.Time fields. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+378
to
+382
| // time.Time is rendered inline as a date-time string, not as a component schema | ||
| if isTimeType(t) { | ||
| return | ||
| } | ||
|
|
Comment on lines
+25
to
+30
| func TestTimeTypeRendersAsDateTimeString(t *testing.T) { | ||
| app := fiber.New() | ||
| oapi := New(app) | ||
|
|
||
| Post(oapi, "/workspaces", func(c *fiber.Ctx, req *EmptyRequest) (*WorkspaceResponse, *ErrorResponse) { | ||
| return &WorkspaceResponse{}, nil |
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.
This pull request improves how the OpenAPI schema generator handles Go's
time.Timetype. Now,time.Timefields are rendered inline as"type": "string", "format": "date-time"instead of being registered as a separate schema component. This ensures that date-time fields are correctly described in generated OpenAPI specs, and avoids unnecessary component definitions. Comprehensive tests are added to verify this behavior for both direct and pointer uses oftime.Time.OpenAPI schema generation improvements:
collectAllTypes,generateSchema, andgenerateFieldSchemainfiberoapi.goto detecttime.Timeand render it inline as a string withdate-timeformat, rather than as a component schema. [1] [2] [3]isTimeTypeto reliably detect thetime.Timetype.Testing enhancements:
time_type_test.gowith tests to ensuretime.Timeand*time.Timefields are rendered as"type": "string", "format": "date-time"and are not registered as component schemas in the OpenAPI output.