Allow empty fields on channel custom field definitions#410
Allow empty fields on channel custom field definitions#410caitlynstocker wants to merge 3 commits intomainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adjusts JSON serialization for channel custom field definitions by removing omitempty from relevant struct tags so empty values are emitted rather than omitted.
Changes:
- Remove
omitemptyfromChannel.CustomFieldDefinitionsJSON tag. - Remove
omitemptyfromChannelCustomFieldDefinition.FieldNameand.DescriptionJSON tags.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| pkg/channels/channel.go | Forces CustomFieldDefinitions to be included in marshaled JSON payloads. |
| pkg/channels/channel_custom_field_definition.go | Forces FieldName/Description to be included in marshaled JSON payloads. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| type Channel struct { | ||
| CustomFieldDefinitions []ChannelCustomFieldDefinition `json:"CustomFieldDefinitions,omitempty"` | ||
| CustomFieldDefinitions *[]ChannelCustomFieldDefinition `json:"CustomFieldDefinitions,omitempty"` |
There was a problem hiding this comment.
* means that the field is a pointer to a slice. Instead of holding the slice directly, it holds a reference to a slice (or nothing at all if nil). When we use a pointer instead of the slice itself, omitempty treats an empty slice differently to an omitted field.
This will enable us to:
- clear the custom field definitions by setting the pointer to an empty slice.
- leave the custom field definitions unchanged by omitting the pointer entirely.
| TenantTags: []string{}, | ||
| GitReferenceRules: []string{}, | ||
| GitResourceRules: []ChannelGitResourceRule{}, | ||
| CustomFieldDefinitions: []ChannelCustomFieldDefinition{}, |
There was a problem hiding this comment.
Now that we are using a pointer above, if we left this line in we would be creating a custom field definition property on every new channel. The terraform provider will now create the new channel and then add the custom field definitions.
Background 🌇
We are currently making a change to the Octopus Terraform provider to enable the creation and removal of custom field definitions on a channel. In order to completely clear custom fields from the channel we need to be able to send an empty array of custom field definitions to the API.
Currently, when the
CustomFieldDefinitionsfield is empty, the go client would omit it entirely. This is because we have marked this field asomitempty. This makes it impossible to signal to the API that all definitions should be removed.What's this? 🌵
This change introduces a pointer to the
CustomFieldDefinitionsfield in order to distinguish between cases where it contains an empty list and cases where the field not provided.🚩🚩🚩 The proposed change would be a breaking one in that:
CustomFieldDefinitionshas changed. This could cause compile errors for anyone who is referring directly to the type (e.g., like us).How to review 🔍
☑️ Carefully. This is my first time making changes in this repository.
🚩 See my red flags above! I'm putting this up as a draft for now to get some advice on the approach.
Part of DEVEX-147