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
An OpenAPI 3.1 nullable wrapper around an inline oneOf or anyOf generates a union struct without its JSON methods. Generation succeeds, but unmarshalling and then marshalling silently drops the union payload.
Reproduced on main at 833a968f84b4b0ec7c2f3fb5bb119e3c449f7a4f, using Go 1.27.1 on darwin/arm64, with compatibility.schema-merging-behavior set to v1, v2, or v3.
Reproduction
Save these three files in a new directory. The reproduction is provided under Apache-2.0.
go mod init example.com/nested-nullable-repro
go run github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen@833a968f84b4b0ec7c2f3fb5bb119e3c449f7a4f --config=config.yaml spec.yaml
go get github.com/oapi-codegen/runtime@v1.7.0
go test.
Actual result:
got {"pet":{}}, want {"pet":{"meow":"purr"}}
Expected: the complete payload survives the JSON round trip.
Cause
The nullable-union collapse path drops UnionElements and Discriminator, so the union's JSON methods and accessors are not generated.
Related to #2218. This reproduces after the OpenAPI 3.1 support added in #2336.
Activity