Skip to content

Commit fa534ba

Browse files
curiosity-the-rovera.gorbunovSVilgelm
authored
fix: change Explode field from bool to *bool for proper serialization (#132)
When Explode is bool with omitempty, false values are not serialized to JSON/YAML output. This prevents users from explicitly setting explode: false in OpenAPI specs. Changing to *bool allows: - nil: omit the field (use default behavior) - &true: serialize as 'explode: true' - &false: serialize as 'explode: false' Affects: Parameter, Header, Encoding structs and their builders. Co-authored-by: a.gorbunov <a.gorbunov@2gis.ru> Co-authored-by: Sergey Vilgelm <523825+SVilgelm@users.noreply.github.com>
1 parent 6fb7912 commit fa534ba

3 files changed

Lines changed: 6 additions & 6 deletions

File tree

‎encoding.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ type Encoding struct {
6464
// For all other styles, the default value is false.
6565
// This property SHALL be ignored if the request body media type is not application/x-www-form-urlencoded or multipart/form-data.
6666
// If a value is explicitly defined, then the value of contentType (implicit or explicit) SHALL be ignored.
67-
Explode bool `json:"explode,omitempty" yaml:"explode,omitempty"`
67+
Explode *bool `json:"explode,omitempty" yaml:"explode,omitempty"`
6868
// Determines whether the parameter value SHOULD allow reserved characters, as defined by [RFC3986]
6969
// :/?#[]@!$&'()*+,;=
7070
// to be included without percent-encoding.
@@ -138,7 +138,7 @@ func (b *EncodingBuilder) Style(v string) *EncodingBuilder {
138138
}
139139

140140
func (b *EncodingBuilder) Explode(v bool) *EncodingBuilder {
141-
b.spec.Spec.Explode = v
141+
b.spec.Spec.Explode = &v
142142
return b
143143
}
144144

‎header.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ type Header struct {
2929
// For other types of parameters this property has no effect.
3030
// When style is form, the default value is true.
3131
// For all other styles, the default value is false.
32-
Explode bool `json:"explode,omitempty" yaml:"explode,omitempty"`
32+
Explode *bool `json:"explode,omitempty" yaml:"explode,omitempty"`
3333
// Determines whether this header is mandatory.
3434
// The property MAY be included and its default value is false.
3535
Required bool `json:"required,omitempty" yaml:"required,omitempty"`
@@ -118,7 +118,7 @@ func (b *HeaderBuilder) Style(v string) *HeaderBuilder {
118118
}
119119

120120
func (b *HeaderBuilder) Explode(v bool) *HeaderBuilder {
121-
b.spec.Spec.Spec.Explode = v
121+
b.spec.Spec.Spec.Explode = &v
122122
return b
123123
}
124124

‎parameter.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ type Parameter struct {
155155
// For other types of parameters this property has no effect.
156156
// When style is form, the default value is true.
157157
// For all other styles, the default value is false.
158-
Explode bool `json:"explode,omitempty" yaml:"explode,omitempty"`
158+
Explode *bool `json:"explode,omitempty" yaml:"explode,omitempty"`
159159
// Determines whether the parameter value SHOULD allow reserved characters, as defined by [RFC3986]
160160
// :/?#[]@!$&'()*+,;=
161161
// to be included without percent-encoding.
@@ -370,7 +370,7 @@ func (b *ParameterBuilder) Name(v string) *ParameterBuilder {
370370
}
371371

372372
func (b *ParameterBuilder) Explode(v bool) *ParameterBuilder {
373-
b.spec.Spec.Spec.Explode = v
373+
b.spec.Spec.Spec.Explode = &v
374374
return b
375375
}
376376

0 commit comments

Comments
 (0)
⌂ 换网址