refactor!: Pass the Codespaces body types by value and rename them to ...Request - #4540
refactor!: Pass the Codespaces body types by value and rename them to ...Request#4540JamBalaya56562 wants to merge 3 commits into
...Request#4540Conversation
…eCreateForUserOptions` POST /user/codespaces takes a oneOf body: either `repository_id` (with an optional `ref`) or `pull_request`. Neither field had an omit option, so every request sent both `"repository_id": 0` and `"pull_request": null` regardless of which branch of the schema was intended.
The PATCH /user/codespaces/{codespace_name} request schema has `machine`,
`display_name` and `recent_folders`, but `display_name` was missing.
… `...Request` `CreateCodespaceOptions`, `CodespaceCreateForUserOptions`, `UpdateCodespaceOptions` and `PublishCodespaceOptions` are renamed to `CreateCodespaceRequest`, `CreateCodespaceForUserRequest`, `UpdateCodespaceRequest` and `PublishCodespaceRequest`, and the five `CodespacesService` methods taking them now take them by value. This removes all four types from both `paramcheck` exception lists in `.golangci.yml`.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #4540 +/- ##
=======================================
Coverage 98.53% 98.54%
=======================================
Files 195 196 +1
Lines 17875 17938 +63
=======================================
+ Hits 17614 17677 +63
Misses 261 261 ☔ 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 CreateCodespaceOptions struct { | ||
| // CreateCodespaceRequest represents a request to create a codespace in a repository. | ||
| // | ||
| //meta:schema request POST /repos/{owner}/{repo}/codespaces |
There was a problem hiding this comment.
Why are we adding meta:schema request ... to structs?
There was a problem hiding this comment.
Fair question. They are for the check-schema-fields command in #4375 (not merged yet): it checks an annotated struct's field optionality against the request body schema of the named operation in the OpenAPI descriptions, the same way //meta:operation ties a method to its operation. Running it on this branch is how the missing display_name and the oneOf problem here were found. #4519 added the first one on CreateDependencyGraphSnapshotRequest.
Until #4375 lands they are inert comments, so if you would rather not carry them in unrelated PRs before that, I'm happy to drop them from this PR.
Updates #3644
This converts the last four
CodespacesServicebody types, removing 8 entries from theparamcheckexception lists in.golangci.yml(4 frombody-allowed-pointer-typesand 4 frombody-allowed-wrong-names).Checking the four types against the OpenAPI descriptions turned up two problems that are fixed here in separate commits:
POST /user/codespacestakes aoneOfbody: eitherrepository_id(with an optionalref) orpull_request.CodespaceCreateForUserOptionsdeclared bothRepositoryID int64 \json:"repository_id"`andPullRequest *CodespacePullRequestOptions `json:"pull_request"`without an omit option, so every request sent"repository_id": 0and"pull_request": nulltogether, no matter which branch the caller meant.RepositoryIDis now*int64and both fields useomitempty, so only the branch the caller filled in is sent. ThatoneOf` is also why these two fields stay pointers instead of becoming required value types.PATCH /user/codespaces/{codespace_name}schema hasmachine,display_nameandrecent_folders, butDisplayNamewas missing fromUpdateCodespaceOptions.A few notes on what is deliberately not changed:
CodespacesService.Publishkeeps its name. The docs page is titled "Create a repository from an unpublished codespace", but the operation id iscodespaces/publish-for-authenticated-user, so the current verb already matches the operation.CodespacePullRequestOptionskeeps its name. It is a nested field type rather than a body parameter type, so theOptionssuffix rule does not apply to it.CreateCodespaceRequeststays shared betweenCreateInRepoandCreateFromPullRequest. The only difference between the two schemas is that the pull request variant has noref, which is also why its//meta:schemaannotation names only the repository operation.BREAKING CHANGE:
CreateCodespaceOptions,CodespaceCreateForUserOptions,UpdateCodespaceOptionsandPublishCodespaceOptionsare renamed toCreateCodespaceRequest,CreateCodespaceForUserRequest,UpdateCodespaceRequestandPublishCodespaceRequest;CodespacesService.CreateInRepo,CreateFromPullRequest,Create,UpdateandPublishnow take them by value instead of by pointer;CreateCodespaceForUserRequest.RepositoryIDis now*int64.🤖 Generated with Claude Code