@@ -2324,6 +2324,17 @@ Force the presence of the JSON tag `omitempty` on a field
23242324<tr >
23252325<td >
23262326
2327+ ` x-omitzero `
2328+
2329+ </td >
2330+ <td >
2331+ Force the presence of the JSON tag ` omitzero ` on a field
2332+ </td >
2333+ </tr >
2334+
2335+ <tr >
2336+ <td >
2337+
23272338` x-go-json-ignore `
23282339
23292340</td >
@@ -2678,6 +2689,61 @@ Notice that the `ComplexField` is still generated in full, but the type will the
26782689
26792690You can see this in more detail in [ the example code] ( examples/extensions/xomitempty/ ) .
26802691
2692+ ### ` x-omitzero ` - force the presence of the JSON tag ` omitzero ` on a field
2693+
2694+ > [ !NOTE]
2695+ > ` omitzero ` was added in Go 1.24. If you're not using Go 1.24 in your project, this won't work.
2696+
2697+ In a case that you may want to add the JSON struct tag ` omitzero ` to types, you can use the ` x-omitempty ` extension.
2698+
2699+ We can see this at play with the following schemas:
2700+
2701+ ``` yaml
2702+ openapi : " 3.0.0"
2703+ info :
2704+ version : 1.0.0
2705+ title : x-omitempty
2706+ components :
2707+ schemas :
2708+ Client :
2709+ type : object
2710+ required :
2711+ - name
2712+ properties :
2713+ name :
2714+ type : string
2715+ id :
2716+ type : number
2717+ ClientWithExtension :
2718+ type : object
2719+ required :
2720+ - name
2721+ properties :
2722+ name :
2723+ type : string
2724+ id :
2725+ type : number
2726+ x-omitzero : true
2727+ ` ` `
2728+
2729+ From here, we now get two different models:
2730+
2731+ ` ` ` go
2732+ // Client defines model for Client.
2733+ type Client struct {
2734+ Id *float32 `json:"id,omitempty"`
2735+ Name string `json:"name"`
2736+ }
2737+
2738+ // ClientWithExtension defines model for ClientWithExtension.
2739+ type ClientWithExtension struct {
2740+ Id *float32 `json:"id,omitempty,omitzero"`
2741+ Name string `json:"name"`
2742+ }
2743+ ```
2744+
2745+ You can see this in more detail in [ the example code] ( examples/extensions/xomitzero/ ) .
2746+
26812747### ` x-go-json-ignore ` - when (un)marshaling JSON, ignore field(s)
26822748
26832749By default, ` oapi-codegen ` will generate ` json:"..." ` struct tags for all fields in a struct, so JSON (un)marshaling works.
0 commit comments