You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
strict fiber server returns nothing when using schema with oneOf #1872
type Test struct {
union json.RawMessage
}
type GetTest200JSONResponse Test
func (response GetTest200JSONResponse) VisitGetTestResponse(ctx *fiber.Ctx) error {
ctx.Response().Header.Set("Content-Type", "application/json")
ctx.Status(200)
return ctx.JSON(&response)
}
since union starts with a lower case letter the endpoint won't return anything.
I would expect it to return my Test struct.
changing the generated code to return ctx.JSON(&response.union) fixed the issue
The bug was that type GetTest200JSONResponse Test (a defined type, not an alias) did not inherit Test.MarshalJSON(), so ctx.JSON(&response) serialized the struct without exported fields and emitted {}. Commit 5260c72 (2026-04-21) fixed this by adding HasCustomMarshalJSON to schema.go and generating MarshalJSON/UnmarshalJSON delegators in all strict server templates when the response schema is a $ref to a oneOf/anyOf union. The repro spec now generates correct delegators in the current codebase. The fix was landed as 'Fixes #970' but resolves the identical underlying problem reported in #1872.
Closing as fixed. If you can still reproduce on a recent release, please reopen with the exact spec and version used.
Activity
holyfuchs commentedon Jan 1, 2025
it seems a workaround is changing the openapi.yaml to the following:
and to make sure the now unused Test is still generated adding the following to the output options
mromaszewicz commentedon May 1, 2026
The bug was that
type GetTest200JSONResponse Test(a defined type, not an alias) did not inheritTest.MarshalJSON(), soctx.JSON(&response)serialized the struct without exported fields and emitted{}. Commit 5260c72 (2026-04-21) fixed this by addingHasCustomMarshalJSONto schema.go and generating MarshalJSON/UnmarshalJSON delegators in all strict server templates when the response schema is a $ref to a oneOf/anyOf union. The repro spec now generates correct delegators in the current codebase. The fix was landed as 'Fixes #970' but resolves the identical underlying problem reported in #1872.Closing as fixed. If you can still reproduce on a recent release, please reopen with the exact spec and version used.