Skip to content

Fix OpenAPI schema to render time.Time in date-time format#48

Merged
moutonjeremy merged 1 commit intomainfrom
time.Time-bug-empty-struct
May 4, 2026
Merged

Fix OpenAPI schema to render time.Time in date-time format#48
moutonjeremy merged 1 commit intomainfrom
time.Time-bug-empty-struct

Conversation

@moutonjeremy
Copy link
Copy Markdown
Member

This pull request improves how the OpenAPI schema generator handles Go's time.Time type. Now, time.Time fields 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 of time.Time.

OpenAPI schema generation improvements:

  • Added logic in collectAllTypes, generateSchema, and generateFieldSchema in fiberoapi.go to detect time.Time and render it inline as a string with date-time format, rather than as a component schema. [1] [2] [3]
  • Introduced the helper function isTimeType to reliably detect the time.Time type.

Testing enhancements:

  • Added time_type_test.go with tests to ensure time.Time and *time.Time fields are rendered as "type": "string", "format": "date-time" and are not registered as component schemas in the OpenAPI output.

Copilot AI review requested due to automatic review settings May 4, 2026 08:06
@moutonjeremy moutonjeremy merged commit 82e906f into main May 4, 2026
8 checks passed
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 isTimeType detection and special-cased time.Time during schema collection and field/schema generation.
  • Prevented time.Time from being registered as a component schema.
  • Added tests asserting nested time.Time and *time.Time fields render inline as string/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 thread fiberoapi.go
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 thread time_type_test.go
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants