Skip to content

refactor!: Pass the Codespaces body types by value and rename them to ...Request - #4540

Open
JamBalaya56562 wants to merge 3 commits into
google:masterfrom
JamBalaya56562:refactor/3644-codespaces-request-types
Open

refactor!: Pass the Codespaces body types by value and rename them to ...Request#4540
JamBalaya56562 wants to merge 3 commits into
google:masterfrom
JamBalaya56562:refactor/3644-codespaces-request-types

Conversation

@JamBalaya56562

Copy link
Copy Markdown
Contributor

Updates #3644

This converts the last four CodespacesService body types, removing 8 entries from the paramcheck exception lists in .golangci.yml (4 from body-allowed-pointer-types and 4 from body-allowed-wrong-names).

Checking the four types against the OpenAPI descriptions turned up two problems that are fixed here in separate commits:

  1. POST /user/codespaces takes a oneOf body: either repository_id (with an optional ref) or pull_request. CodespaceCreateForUserOptions declared both RepositoryID 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. That oneOf` is also why these two fields stay pointers instead of becoming required value types.
  2. The PATCH /user/codespaces/{codespace_name} schema has machine, display_name and recent_folders, but DisplayName was missing from UpdateCodespaceOptions.

A few notes on what is deliberately not changed:

  • CodespacesService.Publish keeps its name. The docs page is titled "Create a repository from an unpublished codespace", but the operation id is codespaces/publish-for-authenticated-user, so the current verb already matches the operation.
  • CodespacePullRequestOptions keeps its name. It is a nested field type rather than a body parameter type, so the Options suffix rule does not apply to it.
  • CreateCodespaceRequest stays shared between CreateInRepo and CreateFromPullRequest. The only difference between the two schemas is that the pull request variant has no ref, which is also why its //meta:schema annotation names only the repository operation.

BREAKING CHANGE: CreateCodespaceOptions, CodespaceCreateForUserOptions, UpdateCodespaceOptions and PublishCodespaceOptions are renamed to CreateCodespaceRequest, CreateCodespaceForUserRequest, UpdateCodespaceRequest and PublishCodespaceRequest; CodespacesService.CreateInRepo, CreateFromPullRequest, Create, Update and Publish now take them by value instead of by pointer; CreateCodespaceForUserRequest.RepositoryID is now *int64.

🤖 Generated with Claude Code

…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`.
@gmlewis gmlewis added NeedsReview PR is awaiting a review before merging. Breaking API Change PR will require a bump to the major version num in next release. Look here to see the change(s). labels Sep 10, 2026
@codecov

codecov Bot commented Sep 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.54%. Comparing base (9b114ec) to head (9c7bdcd).
⚠️ Report is 3 commits behind head on master.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@gmlewis gmlewis left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, @JamBalaya56562!
LGTM.
Awaiting second LGTM+Approval from any other contributor to this repo before merging.

cc: @stevehipwell - @Not-Dhananjay-Mishra

Comment thread github/codespaces.go
type CreateCodespaceOptions struct {
// CreateCodespaceRequest represents a request to create a codespace in a repository.
//
//meta:schema request POST /repos/{owner}/{repo}/codespaces

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we adding meta:schema request ... to structs?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Breaking API Change PR will require a bump to the major version num in next release. Look here to see the change(s). NeedsReview PR is awaiting a review before merging.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants