Skip to content
This repository was archived by the owner on Jan 20, 2026. It is now read-only.
This repository was archived by the owner on Jan 20, 2026. It is now read-only.

Swagger client API calls omit fields whose values have meaning, if the values happen to be Go zero values #292

@dlipovetsky

Description

@dlipovetsky

Describe the bug

The generated swagger clients [1,2] annotate all fields with omitempty. When a field with this annotation has a value equal to the type's zero value, Go considers it empty, and omits from the marshaled output.

Some fields have a zero value that carries meaning. For example, the GracefulTimeoutPeriod has a zero value of 0. This value has meaning: it means the timeout should be disabled. In fact, the SDK client (in pkg/vcdsdk) disables this timeout. However, this has no effect: the swagger client removes the field from the API request, and so VCD service assigns the default timeout (a value of 1).

This problem is well-known by the Kubernetes community; it affected the core Kubernetes APIs. It is a topic of the Kubernetes API Conventions.

[1] https://github.com/vmware/cloud-provider-for-cloud-director/tree/868f15c9090e5b7799782047759cd0b5d069f4c7/pkg/vcdswaggerclient_36_0
[2] https://github.com/vmware/cloud-provider-for-cloud-director/tree/868f15c9090e5b7799782047759cd0b5d069f4c7/pkg/vcdswaggerclient_37_2

Reproduction steps

I'll try to create a failing unit test.

Expected behavior

The swagger client must not omit fields with values that have meaning, when the values happen to be Go zero values.

Additional context

For a quick demonstration of how omitempty works when marshaling, see https://go.dev/play/p/CAOw2aCY3Gk

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions