fix: allow clearing organization domains by sending empty arrays#522
fix: allow clearing organization domains by sending empty arrays#522gjtorikian merged 2 commits intoworkos:mainfrom
Conversation
Greptile SummaryThis PR removes
Confidence Score: 3/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant Caller
participant SDK as workos-go SDK
participant API as WorkOS API
Note over Caller,API: Before fix (omitempty)
Caller->>SDK: UpdateOrganization({Name: "X", Domains: nil})
SDK->>API: PUT /organizations/{id} {"name":"X"}
Caller->>SDK: UpdateOrganization({Name: "X", Domains: []})
SDK->>API: PUT /organizations/{id} {"name":"X"} (empty slice omitted — cannot clear)
Note over Caller,API: After fix (no omitempty)
Caller->>SDK: UpdateOrganization({Name: "X", Domains: nil})
SDK->>API: PUT /organizations/{id} {"name":"X","domains":null,"domain_data":null}
Caller->>SDK: UpdateOrganization({Name: "X", Domains: []})
SDK->>API: PUT /organizations/{id} {"name":"X","domains":[],"domain_data":null} ✓ clears domains
|
Adds a custom MarshalJSON to UpdateOrganizationOpts that distinguishes between nil slices (omit from request) and empty slices (send [] to clear domains). The previous approach of simply removing omitempty would send null for these fields on every update call, even when the caller doesn't intend to modify domains.
|
Hey thanks for pointing this out. However, the fix of removing For example, a caller doing: client.UpdateOrganization(ctx, organizations.UpdateOrganizationOpts{
Organization: "org_123",
Name: "New Name",
})Now needs to shape it as This means the API receives explicit null values on every update, even when the caller has no intention of touching domains. Whether that causes problems depends on how the API handles null vs. absent, but it's a contract change for every existing user of this method. I took a different approach: a custom // Clear domains — sends "domain_data": []
opts := organizations.UpdateOrganizationOpts{
Organization: "org_123",
DomainData: []organizations.OrganizationDomainData{},
}
// Just rename — domain_data is omitted entirely
opts := organizations.UpdateOrganizationOpts{
Organization: "org_123",
Name: "New Name",
}Will release this as a patch version now. |
Actually, it'll go out as 6.5.0 -- there were a few other changes waiting. |
Summary
omitemptyfromDomainsandDomainDataJSON tags inUpdateOrganizationOptsjson:",omitempty"omits bothniland empty slices ([]string{}), making it impossible to send an empty array to the API to clear an organization's domainsnil→ serializes asnull(no change on API side)[]string{}→ serializes as[](clears domains)[]string{"foo.com"}→ serializes as["foo.com"](sets domains)Test plan
go test ./pkg/organizations/...passes