refactor!: Pass GistsService required params by value#4320
refactor!: Pass GistsService required params by value#4320JamBalaya56562 wants to merge 3 commits into
GistsService required params by value#4320Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
GistsService required params by value
993c86d to
0a16bd5
Compare
BREAKING CHANGE: GistsService.Create / Update / CreateComment / UpdateComment now take dedicated request structs by value (CreateGistRequest, UpdateGistRequest, CreateGistCommentRequest, UpdateGistCommentRequest) instead of *Gist / *GistComment. Edit is renamed to Update and EditComment is renamed to UpdateComment. This completes the stalled PR google#3680, applying the maintainer-agreed review feedback that was never addressed: drop the deprecated wrappers entirely and rename Edit/EditComment to Update/UpdateComment for API consistency. The now-obsolete Gist and GistComment entries are removed from the paramcheck body-allowed-pointer-types allow-list in .golangci.yml. Relates to google#3644.
0a16bd5 to
2a65d2f
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #4320 +/- ##
=======================================
Coverage 97.48% 97.48%
=======================================
Files 193 193
Lines 19400 19400
=======================================
Hits 18912 18912
Misses 270 270
Partials 218 218 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
gmlewis
left a comment
There was a problem hiding this comment.
Thank you, @JamBalaya56562!
LGTM.
Awaiting second LGTM+Approval from any other contributor to this repo before merging.
| type CreateGistRequest struct { | ||
| Description *string `json:"description,omitempty"` | ||
| Public *bool `json:"public,omitempty"` | ||
| Files map[GistFilename]GistFile `json:"files,omitempty"` |
There was a problem hiding this comment.
This parameter is required:
| Files map[GistFilename]GistFile `json:"files,omitempty"` | |
| Files map[GistFilename]GistFile `json:"files"` |
There was a problem hiding this comment.
Done — dropped omitempty so files is always sent (json:"files"), and it now uses GistFileRequest. b85f702
| // UpdateGistRequest represents the input for updating a gist. | ||
| type UpdateGistRequest struct { | ||
| Description *string `json:"description,omitempty"` | ||
| Files map[GistFilename]GistFile `json:"files,omitempty"` |
There was a problem hiding this comment.
Done — added doc comments to the Files field and the new GistFileRequest. b85f702
| type CreateGistRequest struct { | ||
| Description *string `json:"description,omitempty"` | ||
| Public *bool `json:"public,omitempty"` | ||
| Files map[GistFilename]GistFile `json:"files,omitempty"` |
There was a problem hiding this comment.
Done — introduced GistFileRequest{Content, Filename} for the request file value instead of reusing the GistFile response type. Confirmed against the OpenAPI: the create file value is {content} (content required) and update is {content, filename}, so neither matches the read-only-heavy GistFile. b85f702
There was a problem hiding this comment.
I'm sorry that I missed this before, but I think the maps should be maps to pointers, since the values are structs. This would match our preference to have slices of pointers to structs.
@alexandear - do you agree?
There was a problem hiding this comment.
Agree.
@JamBalaya56562 Please use a pointer for values in the map.
There was a problem hiding this comment.
Good point — switched the Files maps to pointer values (map[GistFilename]*CreateGistFile / *UpdateGistFile) to match the pointers-to-structs preference. a332585
Per review, the gist create/update request files map should not reuse
the GistFile response type (which carries read-only fields like size,
raw_url, type and language). Introduce GistFileRequest{Content, Filename}
for the request file value, mark CreateGistRequest.Files required (drop
omitempty), and add field doc comments. The OpenAPI schema confirms the
create file value is {content} (content required) and the update file
value is {content, filename}.
| // GistFileRequest represents a file's content within a CreateGistRequest or | ||
| // UpdateGistRequest. The gist's files are keyed by filename. | ||
| type GistFileRequest struct { | ||
| // Content is the contents of the file. (Required when creating a gist.) | ||
| Content *string `json:"content,omitempty"` | ||
| // Filename, if set, renames the file. (Used when updating a gist.) | ||
| Filename *string `json:"filename,omitempty"` | ||
| } |
There was a problem hiding this comment.
It's better to have two separate structs for creating and for updating.
There was a problem hiding this comment.
Done — split into separate CreateGistFile ({content}) and UpdateGistFile ({content, filename}) structs. a332585
| // Files is the set of files to add, change or rename, keyed by filename. | ||
| Files map[GistFilename]GistFileRequest `json:"files,omitempty"` |
There was a problem hiding this comment.
Good catch — UpdateGistFile now documents that mapping a filename to a nil value deletes the file, and I added a test for it. a332585
Per review, use separate CreateGistFile and UpdateGistFile structs for the request files (matching the distinct create/update schemas), and key the Files maps to pointers (map[GistFilename]*...), matching the repo's preference for pointers to structs. A nil value in an UpdateGistRequest's Files map deletes that file from the gist, which is now documented and covered by a test.



BREAKING CHANGE:
GistsServicemethods now pass required params by-value instead of by-ref.What problem are you solving?
This completes #3680 (open and unanswered for ~1 year), which addresses #3644 by
passing required
GistsServiceinputs by value instead of by pointer.It applies the review feedback that was agreed on #3680 but never implemented by
the original author:
CreateGistRequest,UpdateGistRequest,CreateGistCommentRequest,UpdateGistCommentRequest.CreateandCreateCommentnow take the request struct by value.Edit→UpdateandEditComment→UpdateCommentfor APIconsistency (suggested by @stevehipwell, agreed by @gmlewis).
with the earlier
GitServicerefactor in refactor!: ChangeGitServicemethods to pass required params by-value instead of by-ref #3654).Gist/GistCommententries from the paramcheckbody-allowed-pointer-typesallow-list in.golangci.yml.BREAKING CHANGE: theCreate/Update/CreateComment/UpdateCommentsignatures change, and
Edit/EditCommentare renamed.Patch coverage is 100% (the four methods and the generated accessors for the new
request structs are fully covered); generated files are regenerated and the
OpenAPI metadata is unchanged (the method renames do not affect
//meta:operation).Relates toFixes: #3644.SupersedesCloses: #3680.