fix(go): skip empty request structs when wrapper has no user-facing fields#12336
Open
tstanmay13 wants to merge 1 commit intomainfrom
Open
fix(go): skip empty request structs when wrapper has no user-facing fields#12336tstanmay13 wants to merge 1 commit intomainfrom
tstanmay13 wants to merge 1 commit intomainfrom
Conversation
…ields Co-Authored-By: tanmay.singh@buildwithfern.com <tstanmay13@gmail.com>
Contributor
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
Contributor
🌱 Seed Test SelectorSelect languages to run seed tests for:
How to use: Click the ⋯ menu above → "Edit" → check the boxes you want → click "Update comment". Tests will run automatically and snapshots will be committed to this PR. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Refs: Slack thread
Fixes a bug where the Go SDK generator creates empty request struct parameters for GET/DELETE endpoints. This was reported by a Polytomic user who noticed
Getmethods taking an emptyRequeststruct argument that's never referenced (e.g.,modelsync.ExecutionsGetRequest{}).Link to Devin run: https://app.devin.ai/sessions/33187a2cad704a4abd6dc89f64f5e1da
Requested by: @tstanmay13
Root Cause
needsRequestParameter()insdk.gohad two issues:endpoint.Headersbut not the service's headers, so it couldn't account for whether service headers contributed fields to the request struct.true— when anSdkRequestwrapper existed but none of the explicit checks (path params, query params, headers, body) matched, it still generated a request parameter, producing an empty struct.Why TS/Python don't have this bug: Those generators flatten wrapper properties into individual function parameters, so an empty wrapper naturally produces zero parameters. Go uses a single struct parameter, making the empty case visible.
Changes Made
serviceHeaders []*ir.HttpHeaderparameter toneedsRequestParameter()andshouldSkipRequestType()len(serviceHeaders) > 0check alongside existinglen(endpoint.Headers) > 0checkreturn truetoreturn falseat end ofneedsRequestParameter()— if we've exhausted all field checks and found nothing, don't generate a request parameterserviceHeadersthrough the full call chain:WriteClient→NewGeneratedClient→newGeneratedEndpoint→newEndpointSnippet→getEndpointParametersgenerators/go/sdk/versions.ymlwith v1.23.8Testing
return true→return false(sdk.go:3903): This is the most impactful change. Verify there are no edge cases where the wrapper has meaningful fields that aren't covered by the explicit checks above (path params, query params, endpoint headers, service headers, request body).NewGeneratedClientsignature change: This is an exported function — confirm no external consumers exist.len(serviceHeaders) > 0check: Returnstruefor all service headers (including literal ones). This is intentional since literal headers still produce struct fields, but worth verifying this is correct behavior.