Skip to content

fix: change Explode field from bool to *bool for proper serialization - #132

Merged
SVilgelm merged 2 commits into
sv-tools:mainfrom
curiosity-the-rover:fix/explode-bool-pointer
Jul 30, 2026
Merged

fix: change Explode field from bool to *bool for proper serialization#132
SVilgelm merged 2 commits into
sv-tools:mainfrom
curiosity-the-rover:fix/explode-bool-pointer

Conversation

@curiosity-the-rover

Copy link
Copy Markdown
Contributor

Problem

When Explode is bool with omitempty JSON/YAML tag, false values are not serialized to the output. This prevents users from explicitly setting explode: false in OpenAPI specs.

For example:

type Parameter struct {
    Explode bool `json:"explode,omitempty" yaml:"explode,omitempty"`
}

p := Parameter{Explode: false}
yaml.Marshal(p) // Output: {} - Explode field is missing!

Solution

Change Explode from bool to *bool in:

  • Parameter struct (parameter.go)
  • Header struct (header.go)
  • Encoding struct (encoding.go)

This allows:

  • nil → omit the field (use default behavior)
  • &true → serialize as explode: true
  • &false → serialize as explode: false

The builder methods are updated to take address of the value.

Changes

  • parameter.go: Explode boolExplode *bool, builder updated
  • header.go: Explode boolExplode *bool, builder updated
  • encoding.go: Explode boolExplode *bool, builder updated

Testing

All existing tests pass.

Related

This change is needed to support explicit explode: false generation in tools like swaggo/swag.

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.

@SVilgelm SVilgelm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, sorry, I didn't check this repo for a while. Approved, but this is kind of breaking incompatible, but I don't want to create v2, so will bump the minor part only, like v1.3.0 or so

@SVilgelm SVilgelm linked an issue Jul 30, 2026 that may be closed by this pull request
@SVilgelm
SVilgelm merged commit fa534ba into sv-tools:main Jul 30, 2026
7 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Parameter.Explode (bool + omitempty) can't represent explode: false

2 participants