Repository navigation
fix(cli): warn when --data fields cannot be sent - #225
Merged
Merged
Conversation
genBindBody binds the --data body into the SDK request struct with json.Unmarshal, which silently discards any field the struct lacks. A field newer than the bundled SDK (or a mistyped one) therefore vanished before the request left the client while the call still succeeded. genBindBody now walks the body against the request type and names every dropped path on stderr (nested fields as a.b, array elements as a[].b). The request itself is unchanged, so read-modify-write flows that pass extra read-only fields keep working. The insight export's second bind of the same body (incident total) discards the warning to avoid a duplicate.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
--databodies are bound into the SDK request struct withjson.Unmarshal, which silently discards fields the struct does not declare. When the server accepts a field that the bundled SDK does not know yet (or the caller mistypes a key), the field disappears before the request is sent and the command still exits 0.Change
genBindBodytakes anio.Writerand, after binding, walks the body against the request type (unboundFields/wireField, following encoding/json name matching: exact then case-insensitive, untagged embedded structs,url-tagged GET structs, stopping at types with their ownUnmarshalJSON).warning: --data fields not sent, unknown to this CLI version: investigation_targets[].bogusctx.Cmd.ErrOrStderr(); the insight export's second bind of the same body (incident total) passesio.Discard.go run ./internal/cmd/cligen(only the call line changes).Verification
go test ./...passes;make check-cardsOK; new unit test covers nested objects, arrays, maps, embedded structs, url tags, case folding andjson.RawMessage.monit rule-v2-create --datacarryinginvestigation_targets[].purposeplus an unknown key:purposeis in the outgoing body; the unknown key is reported on stderr.Also supersedes #223: main already carries go-flashduty v0.15.15 (which includes the
purposefield) via #224.