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
requestBody with oneOf does not generate marshal/unmarshal union data #1620
package oapi
import (
"encoding/json"
)
// CommandRequest1 defines model for CommandRequest1.
type CommandRequest1 struct {
Id string `json:"id"`
}
// CommandRequest2 defines model for CommandRequest2.
type CommandRequest2 struct {
GroupID string `json:"groupID"`
}
// CommandResponse defines model for CommandResponse.
type CommandResponse struct {
Command string `json:"command"`
}
// GetCommandJSONBody defines parameters for GetCommand.
type GetCommandJSONBody struct {
union json.RawMessage
}
// GetCommandJSONRequestBody defines body for GetCommand for application/json ContentType.
type GetCommandJSONRequestBody GetCommandJSONBody
There is GetCommandJSONBody struct with union data but no functions to use it.
Reacted by Egor Turchinovich, Toby Brain and Rohan Poojary
PR #2348 ('Overhaul anonymous schema hoisting', merged 2026-04-29) fixed this by including operation-derived type definitions in the boilerplate passes that emit union accessors. A repro using the exact spec from the issue now generates AsCommandRequest1, FromCommandRequest1, MergeCommandRequest1 (and *2 variants) plus MarshalJSON/UnmarshalJSON on GetCommandJSONBody. The fix is tested by TestBodyRootOneOf_RoundTripCat in internal/test/anonymous_inner_hoisting/client_test.go.
Closing as fixed. If you can still reproduce on a recent release, please reopen with the exact spec and version used.
Activity
stefanmcshane commentedon Nov 13, 2024
Also seeing this, which is a hard blocker. Using strict server also
freshteapot commentedon Apr 6, 2026
For what its worth,
I had a similiar problem, but not on all endpoints.
If you create a higher level object, with a discriminator, it will happily make the union.
But that would require a discriminator the above example, doesnt seem to have that.
feat(openapi): name UserConfigField + UserConfigFieldDefault schemas (#…
mromaszewicz commentedon May 1, 2026
PR #2348 ('Overhaul anonymous schema hoisting', merged 2026-04-29) fixed this by including operation-derived type definitions in the boilerplate passes that emit union accessors. A repro using the exact spec from the issue now generates AsCommandRequest1, FromCommandRequest1, MergeCommandRequest1 (and *2 variants) plus MarshalJSON/UnmarshalJSON on GetCommandJSONBody. The fix is tested by TestBodyRootOneOf_RoundTripCat in internal/test/anonymous_inner_hoisting/client_test.go.
Closing as fixed. If you can still reproduce on a recent release, please reopen with the exact spec and version used.