feat(multipart): add multipart JSON field explode support - #1093
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1093 +/- ##
==========================================
- Coverage 93.20% 93.18% -0.02%
==========================================
Files 23 23
Lines 4988 5022 +34
==========================================
+ Hits 4649 4680 +31
- Misses 272 274 +2
- Partials 67 68 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
Adds support for OpenAPI encoding.explode when decoding multipart form fields tagged with contentType:"application/json", enabling array JSON fields to be represented either as a single JSON array part (explode=false) or as multiple JSON item parts (explode=true, default).
Changes:
- Add
explodestruct-tag support for multipart JSON array decoding (explode=truemulti-part items;explode=falsesingle JSON array). - Preserve
explodemetadata in the generated OpenAPI multipartencodingobject. - Update tests and docs to reflect exploded multipart JSON array behavior.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| schema.go | Introduces maybeBoolTag to support optional boolean tags (needed for OpenAPI encoding). |
| huma.go | Applies explode to form fields and updates multipart JSON decoding to support exploded arrays. |
| huma_test.go | Updates multipart JSON array test payload to use exploded representation for tags and non-exploded for numbers. |
| formdata.go | Emits Encoding.Explode into generated OpenAPI multipart encoding (when tag is set). |
| docs/docs/features/request-inputs.md | Documents explode support for multipart JSON fields with examples for both modes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
f296048 to
2c2affc
Compare
Support OpenAPI encoding.explode for multipart form fields with contentType application/json, including exploded JSON arrays and JSON scalar/object values.
2c2affc to
ade220e
Compare
Follow up to #1060, which adds support for decoding multipart fields with
contentType:"application/json".Until now, array fields were only handled as a single JSON value. This limited interoperability with OpenAPI clients, which need to follow the
encoding.exploderules from OpenAPI spec when serializing multipart requests.For example, an array field can be represented in two valid ways.
With
explode: false:With
explode: true(the default for multipart requests):Huma should accept both representations according to the OpenAPI contract.
This PR:
encoding.explodesetting on multipart form fields (only effective for array properties)explode=trueandexplode=falseFor example:
This change assumes that clients respect the OpenAPI multipart encoding contract. Fields declared with
contentType:"application/json"must always contain valid JSON.