fern-api / fern

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

feat(csharp): add pagination helper methods to C# SDK generator #5187

Closed Swimburger closed 2 days ago

Swimburger commented 6 days ago

This feature works, but the code is still a little rough and needs some cleaning.

⚠️ Assumption: For cursor-based pagination, the cursor is assumed to be a string. This is probably correct in 95% of cases, but that's just a guess. Does the cursor type need to be configurable?

⚠️ Big change: The generator thus far assumes that each endpoint generates one method on a client. This PR changes that so that an endpoint generator can generate multiple methods. For generated SDKs, this isn't too big of a change, but this also affects generated snippets and references. There's some code duplication to quickly get snippets and references to work as expected with this pager variation method for the endpoint

  1. Should we stick to one method per endpoint to reduce the amount of change in this generator and downstream dependencies? Or
  2. Should we push forward on an endpoint with multiple methods and refactor the generator at a larger scale for this to be supported seamlessly?
github-actions[bot] commented 6 days ago

🌿 Preview your docs: https://fern-preview-c360b9f1-650a-46ff-bc3a-99fc70f3cefc.docs.buildwithfern.com/learn

Swimburger commented 3 days ago

Decisions:

Swimburger commented 3 days ago

The mockResponse is generated incorrectly in ListWithExtendedResultsAndOptionalDataTest and ListWithExtendedResultsTest. The mockresponse JSON should have the data property. The list within data is optional so that's fine, but there should be a data: {} property since that isn't optional in Fern definition.

Swimburger commented 3 days ago

Improvements:

For initializing towards cursor and offset property, I assume the types don't have required fields and initialize an empty instance using ?? = new().

I'm worried if one of these types does have a required field, at which point the compiler will complain.

Swimburger commented 3 days ago

I added a shallow clone using the record with {} feature. Future versions of C# may include a DeepClone feature for records.