Skip to content

Allow empty fields on channel custom field definitions#410

Draft
caitlynstocker wants to merge 3 commits intomainfrom
cat/temp-check-custom-fields
Draft

Allow empty fields on channel custom field definitions#410
caitlynstocker wants to merge 3 commits intomainfrom
cat/temp-check-custom-fields

Conversation

@caitlynstocker
Copy link
Copy Markdown

@caitlynstocker caitlynstocker commented Apr 9, 2026

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 CustomFieldDefinitions field is empty, the go client would omit it entirely. This is because we have marked this field as omitempty. 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 CustomFieldDefinitions field 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:

  • Anyone who was sending an empty slice in an API request and expecting it to be ignored, will now have their custom field definitions cleared instead!
  • The type of CustomFieldDefinitions has 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

@caitlynstocker caitlynstocker requested a review from Copilot April 10, 2026 00:40
@caitlynstocker caitlynstocker changed the title Remove omit empties Allow empty fields on channel custom field definitions Apr 10, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 omitempty from Channel.CustomFieldDefinitions JSON tag.
  • Remove omitempty from ChannelCustomFieldDefinition.FieldName and .Description JSON 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.

@caitlynstocker caitlynstocker marked this pull request as draft April 10, 2026 01:14

type Channel struct {
CustomFieldDefinitions []ChannelCustomFieldDefinition `json:"CustomFieldDefinitions,omitempty"`
CustomFieldDefinitions *[]ChannelCustomFieldDefinition `json:"CustomFieldDefinitions,omitempty"`
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

* 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{},
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

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.

@caitlynstocker caitlynstocker requested a review from a team April 12, 2026 23:52
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.

2 participants