Skip to content

Conversation

@curiosity-the-rover
Copy link

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.
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.

1 participant