fix(buck): improve Complete API with optional body and docs#1931
Conversation
- Make Complete request body optional (Option<Json<CompletePayload>>) - Update rustdoc to reflect commit_message from session - Add regression tests for commit_message preservation Signed-off-by: Wan Yidong <1360947433yd@gmail.com>
|
Claude finished @genedna's task in 2m 12s —— View job Code Review Complete ✓
SummaryThis PR improves the Complete API by making the request body optional and enhancing documentation. The changes build logically on PR #1929, which established ✅ Strengths
|
| Json(payload): Json<CompletePayload>, | ||
| payload: Option<Json<CompletePayload>>, | ||
| ) -> Result<Json<CommonResult<CompleteResponse>>, ApiError> { | ||
| let payload = payload.map(|p| p.0).unwrap_or(CompletePayload {}); |
There was a problem hiding this comment.
Potential issue: Using unwrap_or(CompletePayload {}) could be problematic if CompletePayload gains fields in the future.
Consider using unwrap_or_default() instead:
| let payload = payload.map(|p| p.0).unwrap_or(CompletePayload {}); | |
| let payload = payload.map(|p| p.0).unwrap_or_default(); |
This requires implementing Default for CompletePayload, which would be more maintainable and conventional in Rust.
| ), | ||
| path = "/session/{cl_link}/complete", | ||
| request_body = CompletePayload, | ||
| request_body( |
There was a problem hiding this comment.
Documentation clarity: The OpenAPI documentation states "Can be omitted or sent as {}", but it might be clearer to explicitly state that the body can be completely omitted (no Content-Type header needed).
Consider updating to:
| request_body( | |
| description = "Optional empty payload. Request body can be completely omitted or sent as {} with application/json Content-Type", |
| .unwrap(); | ||
| assert_eq!(session.status, session_status::COMPLETED); | ||
|
|
||
| // Regression test: Verify session.commit_message is preserved |
There was a problem hiding this comment.
Good addition: These regression tests are excellent! They verify the core behavior that was broken in the previous version.
Minor suggestion: Consider adding a test case that explicitly calls the endpoint with None payload to verify the optional parameter behavior at the HTTP layer, not just the service layer.
There was a problem hiding this comment.
Pull request overview
This pull request addresses issue #1926 by eliminating redundant commit message handling in the Buck upload API. The Complete endpoint now treats its request body as optional and reads the commit message from the session (which is set during the Manifest phase), rather than accepting it redundantly in both phases.
Changes:
- Made Complete API request body optional, with commit message now exclusively sourced from session state set during Manifest phase
- Updated API documentation and parameter naming to reflect that payload is intentionally unused
- Added regression tests to verify commit_message preservation across the upload workflow
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| mono/src/api/router/buck_router.rs | Changed complete_upload handler to accept optional payload (Option<Json>); updated utoipa documentation to reflect optional body |
| jupiter/src/service/buck_service.rs | Updated rustdoc to clarify that commit_message is read from session; renamed payload parameter to _payload to indicate it's unused |
| ceres/src/api_service/mono_api_service.rs | Updated rustdoc consistently with jupiter changes; renamed payload parameter to _payload |
| mono/tests/buck_service_tests.rs | Added regression test assertions verifying session.commit_message is preserved and used for CL title |
| request_body( | ||
| content = Option<CompletePayload>, | ||
| description = "Optional empty payload. Can be omitted or sent as {}", | ||
| content_type = "application/json" | ||
| ), |
There was a problem hiding this comment.
The utoipa request_body syntax for optional payloads is incorrect. In utoipa 5.x, content = Option<CompletePayload> is not valid syntax.
For optional request bodies, you should either:
- Simply use
request_body = CompletePayloadin the utoipa annotation (which documents the schema without enforcing it's required), while the actual handler usesOption<Json<CompletePayload>>to make it optional at runtime - Or omit the request_body attribute entirely if the body is fully optional and empty
The current syntax will likely cause OpenAPI schema generation issues. The recommended approach is to change line 245-249 to:
request_body = CompletePayload,
And update the description comment to note that the body is optional and can be omitted or sent as {}.
link #1926