Inline time.Time schema for top-level request and response bodies#49
Merged
moutonjeremy merged 4 commits intomainfrom May 4, 2026
Merged
Inline time.Time schema for top-level request and response bodies#49moutonjeremy merged 4 commits intomainfrom
moutonjeremy merged 4 commits intomainfrom
Conversation
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>
Contributor
There was a problem hiding this comment.
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.Timeschemas for top-level request bodies inGenerateOpenAPISpec. - Inline
time.Timeschemas for top-level 200 responses inGenerateOpenAPISpec. - Add a regression test covering top-level
*time.Timerequest/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.
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>
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.
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.