fix update commands to preserve full PUT payloads#20
Conversation
|
ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughFour update commands—credential, gateway-group, and proto—are refactored to track which CLI flags were explicitly provided, fetch current resource state, conditionally parse and merge only provided changes, and send full PUT payloads that preserve unmodified fields required by the API schema. ChangesPartial Update Flag Mode Fix
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Important Pre-merge checks failedPlease resolve all errors before merging. Addressing warnings is optional. ❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
This PR fixes flag-based update commands that previously sent partial PUT payloads to API endpoints that require full resource replacement, by first reading the current resource and then merging only the explicitly-provided flags before issuing the PUT.
Changes:
proto update,credential update, andgateway-group update(flag mode) now GET the current resource and preserve unspecified fields when building the PUT payload.- Introduces
*Setbooleans (based oncobra.Flags().Changed(...)) to distinguish “flag not provided” vs “provided empty value”. - Adds/updates unit tests to assert preservation of required/existing fields in the generated PUT payload.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| pkg/cmd/proto/update/update.go | Fetches current proto and merges only changed flag fields before PUT to preserve required/existing fields. |
| pkg/cmd/proto/update/update_test.go | Updates test to validate PUT payload preserves content unless --content is explicitly set. |
| pkg/cmd/gateway-group/update/update.go | Fetches current gateway group and merges only changed flag fields before PUT to preserve required name. |
| pkg/cmd/gateway-group/update/update_test.go | New test ensuring required fields (e.g., name) are preserved when updating description/labels. |
| pkg/cmd/credential/update/update.go | Fetches current credential and merges only changed flag fields before PUT to preserve name/plugins. |
| pkg/cmd/credential/update/update_test.go | Updates tests to validate PUT payload preserves existing name/plugins and adds required GET mock for error-path test. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| var request api.GatewayGroup | ||
| if err := json.Unmarshal(currentBody, &request); err != nil { | ||
| return fmt.Errorf("failed to decode current gateway group: %w", err) | ||
| } | ||
| request.ID = opts.ID |
Summary
Fixes #18.
This PR changes flag-based update commands for resources whose API endpoints require full PUT payloads:
a7 credential updatenow reads the existing credential and preserves fields such asnameandpluginsunless the corresponding flags are provided.a7 proto updatenow preserves existingcontentunless--contentis provided.a7 gateway-group updatenow preserves required fields such asnamewhen only description, prefix, or labels are updated.File-based update mode remains unchanged and continues to send the provided file payload directly.
Validation
go test ./pkg/cmd/credential/update ./pkg/cmd/proto/update ./pkg/cmd/gateway-group/updatego test ./...credential update --descpreserves existing plugins.proto update --descpreserves existing content.gateway-group update --descriptionpreserves existing name.Follow-up
API capability/version boundary findings from the same live validation are tracked separately in #19.
Summary by CodeRabbit
Bug Fixes
Tests