Fix: Support non-JSON content types for request body validation#926
Conversation
Previously, Huma was hardcoded to look for the validation schema in RequestBody.Content["application/json"]. This caused validation to fail when operations only specified other content types like application/cbor or application/x-www-form-urlencoded. This commit makes the schema lookup more flexible: 1. First try application/json for backwards compatibility 2. If not found, fall back to the first available content type with a schema This allows operations to use contentType tags to specify non-JSON request bodies while still benefiting from Huma's validation.
|
@roidelapluie will this address #833? I've been trying to use |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #926 +/- ##
==========================================
+ Coverage 92.90% 92.95% +0.05%
==========================================
Files 23 23
Lines 4621 4628 +7
==========================================
+ Hits 4293 4302 +9
+ Misses 271 270 -1
+ Partials 57 56 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Hey @roidelapluie! This is an awesome change, thanks so much for contributing! |
|
@richard-hunter-hpe no, this doesn't resolve that issue. But I have a fix locally for it, and will push it shortly :) |
Previously, Huma was hardcoded to look for the validation schema in RequestBody.Content["application/json"]. This caused validation to fail when operations only specified other content types like application/cbor or application/x-www-form-urlencoded.
This commit makes the schema lookup more flexible:
This allows operations to use contentType tags to specify non-JSON request bodies while still benefiting from Huma's validation.