Skip to content

fix: validate the same body keys the decoder assigns - #1172

Merged
robtme merged 1 commit into
mainfrom
fix/body-validation-decode-mismatch
Nov 17, 2026
Merged

robtme merged 1 commit into
mainfrom
fix/body-validation-decode-mismatch

Conversation

@robtme

@robtme robtme commented Nov 17, 2026

Copy link
Copy Markdown
Collaborator

Validation and decoding now agree on which keys a request body contains. encoding/json assigns case-variant keys ("Role" for role) and merges duplicate object keys, while validation checked one key per property and only the last duplicate. This validates every case variant against its property, rejects duplicate keys in DefaultJSONFormat, and decodes CBOR with exact-case field names and no duplicate keys.

  • JSON bodies with duplicate keys now get a 400, and wrong-case CBOR keys are ignored instead of decoded. Worth a release note.
  • Custom JSON/CBOR formats aren't covered; they need equivalent decoder settings.
  • About +12% on BenchmarkFullRequest_Complex, no extra allocations.

encoding/json matches keys case-insensitively and merges duplicate
object keys, while validation saw a single key per property and only
the last duplicate. CBOR's decoder defaults behave the same way.

Validate every case-variant key against its property schema, reject
duplicate object keys when DefaultJSONFormat decodes for validation,
and decode CBOR with exact-case field names and no duplicate keys.
@codecov

codecov Bot commented Nov 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.08%. Comparing base (61c334f) to head (6d94a7d).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1172      +/-   ##
==========================================
+ Coverage   94.75%   95.08%   +0.33%     
==========================================
  Files          25       30       +5     
  Lines        5224     5882     +658     
==========================================
+ Hits         4950     5593     +643     
- Misses        269      284      +15     
  Partials        5        5              

☔ 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.

@robtme
robtme merged commit 40fd098 into main Nov 17, 2026
7 checks passed
@robtme
robtme deleted the fix/body-validation-decode-mismatch branch November 17, 2026 21:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant