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
optional nullable field does not get omitempty json tag as mention in Readme #2091
#[0]$ oapi-codegen --config config.yaml2 spec.yaml2
#[0]$ cat gen.go
// Package preferskipoptionalpointerwithomitzero provides primitives to interact with the openapi HTTP API.
//
// Code generated by github.com/oapi-codegen/oapi-codegen/v2 version v2.5.0 DO NOT EDIT.
package preferskipoptionalpointerwithomitzero
// ClientWithExtension defines model for ClientWithExtension.
type ClientWithExtension struct {
Newfield *string `json:"newfield"`
}
#[0]$ oapi-codegen --version
github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen
v2.5.0
#[0]$ go version
go version go1.24.4 linux/amd64
Reacted by Marcus Weiner, Tim Hårek Andreassen, Nils Norman Haukås, Tavi Hartman, Donatas Tutinas and Maciej Bratek
I looked around - it's a bug. We have several generated files in our tests which fail to add the ,omitempty. The condition on whether a field should be omitted is much more complex than that.
That code was a bit strange. I think it resulted from some conflict being resolved incorrectly or something, because the condition right above the code I removed was correct.
Activity
timharek commentedon Sep 22, 2025
We have the same issue. Our temporary solution is to use overlay for the time being:
jamietanna commentedon Sep 23, 2025
Huh, thanks! Looks like this behaviour hasn't been true at least as far as back as v2.2.0, so could be we documented this incorrectly 🫣
jamietanna commentedon Sep 23, 2025
Looking at
oapi-codegen/pkg/codegen/schema.go
Line 730 in 3eff0a2
mromaszewicz commentedon Feb 14, 2026
I looked around - it's a bug. We have several generated files in our tests which fail to add the
,omitempty. The condition on whether a field should be omitted is much more complex than that.fix: add omitempty to optional nullable fields
mromaszewicz commentedon Feb 14, 2026
That code was a bit strange. I think it resulted from some conflict being resolved incorrectly or something, because the condition right above the code I removed was correct.
fix: add omitempty to optional nullable fields (oapi-codegen#2221)
Fix v2.6.0 omitempty regression (#2505)