From 3fd035c8864af1d071f11d0e5192e5202410d9c1 Mon Sep 17 00:00:00 2001 From: "a.gorbunov" Date: Sun, 18 Jan 2026 23:22:17 +0200 Subject: [PATCH] fix: change Explode field from bool to *bool for proper serialization 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. --- encoding.go | 4 ++-- header.go | 4 ++-- parameter.go | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/encoding.go b/encoding.go index e28a62d..b21f9d2 100644 --- a/encoding.go +++ b/encoding.go @@ -64,7 +64,7 @@ type Encoding struct { // For all other styles, the default value is false. // This property SHALL be ignored if the request body media type is not application/x-www-form-urlencoded or multipart/form-data. // If a value is explicitly defined, then the value of contentType (implicit or explicit) SHALL be ignored. - Explode bool `json:"explode,omitempty" yaml:"explode,omitempty"` + Explode *bool `json:"explode,omitempty" yaml:"explode,omitempty"` // Determines whether the parameter value SHOULD allow reserved characters, as defined by [RFC3986] // :/?#[]@!$&'()*+,;= // to be included without percent-encoding. @@ -138,7 +138,7 @@ func (b *EncodingBuilder) Style(v string) *EncodingBuilder { } func (b *EncodingBuilder) Explode(v bool) *EncodingBuilder { - b.spec.Spec.Explode = v + b.spec.Spec.Explode = &v return b } diff --git a/header.go b/header.go index 9b3426c..13b6d52 100644 --- a/header.go +++ b/header.go @@ -29,7 +29,7 @@ type Header struct { // For other types of parameters this property has no effect. // When style is form, the default value is true. // For all other styles, the default value is false. - Explode bool `json:"explode,omitempty" yaml:"explode,omitempty"` + Explode *bool `json:"explode,omitempty" yaml:"explode,omitempty"` // Determines whether this header is mandatory. // The property MAY be included and its default value is false. Required bool `json:"required,omitempty" yaml:"required,omitempty"` @@ -118,7 +118,7 @@ func (b *HeaderBuilder) Style(v string) *HeaderBuilder { } func (b *HeaderBuilder) Explode(v bool) *HeaderBuilder { - b.spec.Spec.Spec.Explode = v + b.spec.Spec.Spec.Explode = &v return b } diff --git a/parameter.go b/parameter.go index 20f1552..bb7c50c 100644 --- a/parameter.go +++ b/parameter.go @@ -155,7 +155,7 @@ type Parameter struct { // For other types of parameters this property has no effect. // When style is form, the default value is true. // For all other styles, the default value is false. - Explode bool `json:"explode,omitempty" yaml:"explode,omitempty"` + Explode *bool `json:"explode,omitempty" yaml:"explode,omitempty"` // Determines whether the parameter value SHOULD allow reserved characters, as defined by [RFC3986] // :/?#[]@!$&'()*+,;= // to be included without percent-encoding. @@ -370,7 +370,7 @@ func (b *ParameterBuilder) Name(v string) *ParameterBuilder { } func (b *ParameterBuilder) Explode(v bool) *ParameterBuilder { - b.spec.Spec.Spec.Explode = v + b.spec.Spec.Spec.Explode = &v return b }