Skip to content

Inline time.Time schema for top-level request and response bodies#49

Merged
moutonjeremy merged 4 commits intomainfrom
fix/time-type-toplevel-payload
May 4, 2026
Merged

Inline time.Time schema for top-level request and response bodies#49
moutonjeremy merged 4 commits intomainfrom
fix/time-type-toplevel-payload

Conversation

@moutonjeremy
Copy link
Copy Markdown
Member

When time.Time (or *time.Time) is used directly as a handler's input or output type, GenerateOpenAPISpec emitted a $ref to a non-existent #/components/schemas/Time, since collectAllTypes intentionally skips it. Inline the schema in the same branch that already inlines map types.

When time.Time (or *time.Time) is used directly as a handler's input or
output type, GenerateOpenAPISpec emitted a $ref to a non-existent
#/components/schemas/Time, since collectAllTypes intentionally skips it.
Inline the schema in the same branch that already inlines map types.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings May 4, 2026 08:15
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 OpenAPI schema generation so top-level time.Time/*time.Time request and success response bodies are emitted inline as string/date-time instead of referencing a missing #/components/schemas/Time. It fits the codebase’s schema-generation logic by extending the existing inline-schema handling for special cases.

Changes:

  • Inline time.Time schemas for top-level request bodies in GenerateOpenAPISpec.
  • Inline time.Time schemas for top-level 200 responses in GenerateOpenAPISpec.
  • Add a regression test covering top-level *time.Time request/response schema generation.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
fiberoapi.go Extends request/response schema generation to inline top-level time.Time instead of emitting a component ref.
time_type_test.go Adds regression coverage for OpenAPI output when handlers use top-level *time.Time input/output types.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread fiberoapi.go Outdated
Comment thread time_type_test.go
Comment thread fiberoapi.go Outdated
Comment thread fiberoapi.go Outdated
moutonjeremy and others added 3 commits May 4, 2026 10:24
Same fix as the request/response branch: when time.Time is used as the
ErrorType, GenerateOpenAPISpec emitted a $ref to a missing
#/components/schemas/Time. isEmptyStruct does not filter time.Time out
(it has unexported fields). Inline the schema instead.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
parsePathParams, parseQueryParams, and parseHeaderParams unconditionally
called NumField on the dereferenced TInput. When TInput is a non-struct
(e.g. *time.Time or any pointer type), the dereferenced type is a Ptr
kind and NumField panics. Skip when the input is not a struct, and
nil-check the value before dereferencing. Adds a runtime test for a
top-level time.Time payload.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The earlier branch only inlined map and time.Time. Other types that
collectAllTypes never registers — primitives like string/int and slices
whose element type is itself inlined — also produced dangling $refs in
operation bodies. Centralize the decision in shouldInlineOperationSchema
and apply it to request, response, and error bodies.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@moutonjeremy moutonjeremy merged commit 0cdbab3 into main May 4, 2026
4 checks passed
@moutonjeremy moutonjeremy deleted the fix/time-type-toplevel-payload branch May 4, 2026 08:34
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