Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(fix, go): Required properties don't specify omitempty #4231

Merged
merged 6 commits into from
Aug 7, 2024

Conversation

amckinney
Copy link
Contributor

@amckinney amckinney commented Aug 7, 2024

Overview

This fixes an issue where required properties are omitted in the type's wire representation. This feature is gated behind a feature flag to preserve the behavior found in current SDKs.

When alwaysSendRequiredProperties is enabled, required properties are never omitted in the type's wire representation. Any required property that is not explicitly set will send the default value for that type. The configuration to enable this behavior is shown below:

- name: fernapi/fern-go-sdk
  version: 0.23.0
  config:
    alwaysSendRequiredProperties: true

Example

Consider the following types:

type CreateUserRequest struct {
  Admin   *User   `json:"admin"`
  Members []*User `json:"members"`
}

type User struct {
  Name string `json:"name"`
}

If the CreateUserRequest is constructed without any values, it will send null for both fields. If it is instead constructed with the zero value of the underlying type, the empty representation will be sent:

// The following is serialized as `{"admin": null, "members": null}`
nullRequest := &CreateUserRequest{}

// The following is serialized as `{"admin": null, "members": []}`
noMembersRequest := &CreateUserRequest{
  Members: []*User{},
}

// The following is serialized as `{"admin":{"name":""}, "members":[]}`
emptyValueUserRequest := &CreateUserRequest{
  Admin:   &User{},
  Members: []*User{},
}

// The following is serialized as `{"admin":{"name": "john.doe"}, "members":[{"name": "jane.doe"}]}`
simpleUserRequest := &CreateUserRequest{
  Admin:   &User{
     Name: "john.doe",
  },
  Members: []*User{
    {
      Name: "jane.doe",
    },
  },
}

@amckinney amckinney requested a review from dsinghvi as a code owner August 7, 2024 22:46
@amckinney amckinney marked this pull request as draft August 7, 2024 23:00
@amckinney amckinney changed the title (fix, go): Required properties don't specify omitempty [DO NOT MERGE] (fix, go): Required properties don't specify omitempty Aug 7, 2024
@amckinney amckinney marked this pull request as ready for review August 7, 2024 23:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants