fern-api / fern

Input OpenAPI. Output SDKs and Docs.
https://buildwithfern.com
Apache License 2.0
2.69k stars 151 forks source link

feat(go): Generate nil-safe getter methods #5137

Closed amckinney closed 1 week ago

amckinney commented 2 weeks ago

This adds support for nil-safe getter methods for each generated type. Callers can more easily access nested properties by chaining together getter method calls instead of a long series of != nil checks.

For example,

Before

response, err := client.Users.Get(ctx, "john.doe")
if err != nil {
  return nil, err
}
if response.User != nil && response.User.Address != nil {
  return response.User.Address.Street, nil
}

After

response, err := client.Users.Get(ctx, "john.doe")
if err != nil {
  return nil, err
}
if address := response.GetUser().GetAddress(); address != nil {
  return address.Street, nil
}
github-actions[bot] commented 2 weeks ago

🌿 Preview your docs: https://fern-preview-e4d0b737-4f47-4e4e-bd73-a57871530698.docs.buildwithfern.com/learn