Skip to content

feat(multipart): add multipart JSON field explode support - #1093

Open
lsdch wants to merge 2 commits into
danielgtaylor:mainfrom
lsdch:multipart-array-explode
Open

feat(multipart): add multipart JSON field explode support#1093
lsdch wants to merge 2 commits into
danielgtaylor:mainfrom
lsdch:multipart-array-explode

Conversation

@lsdch

@lsdch lsdch commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

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.explode rules from OpenAPI spec when serializing multipart requests.

For example, an array field can be represented in two valid ways.

With explode: false:

Content-Disposition: form-data; name="tags"
Content-Type: application/json

["tag1", "tag2"]

With explode: true (the default for multipart requests):

Content-Disposition: form-data; name="tags"
Content-Type: application/json

"tag1"

Content-Disposition: form-data; name="tags"
Content-Type: application/json

"tag2"

Huma should accept both representations according to the OpenAPI contract.

This PR:

  • adds support for the OpenAPI encoding.explode setting on multipart form fields (only effective for array properties)
  • preserves multipart encoding metadata in the generated OpenAPI document
  • supports decoding JSON arrays with both explode=true and explode=false

For example:

type Input struct {
	RawBody huma.MultipartFormFiles[struct {
		Tags   []string `form:"tags" contentType:"application/json"` // explode=true by default
		Numbers []int   `form:"numbers" contentType:"application/json" explode:"false"`
		Value  string   `form:"value" contentType:"application/json"`
	}]
}

This change assumes that clients respect the OpenAPI multipart encoding contract. Fields declared with contentType:"application/json" must always contain valid JSON.

Copilot AI lite review requested due to automatic review settings August 7, 2026 15:38
@codecov

codecov Bot commented Aug 7, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.47619% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 93.18%. Comparing base (9d0a320) to head (6cf485d).

Files with missing lines Patch % Lines
huma.go 87.50% 2 Missing and 2 partials ⚠️
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.
📢 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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 explode struct-tag support for multipart JSON array decoding (explode=true multi-part items; explode=false single JSON array).
  • Preserve explode metadata in the generated OpenAPI multipart encoding object.
  • 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.

Comment thread formdata.go
Comment thread huma.go
@lsdch
lsdch force-pushed the multipart-array-explode branch 3 times, most recently from f296048 to 2c2affc Compare August 9, 2026 07:44
Support OpenAPI encoding.explode for multipart form fields with
contentType application/json, including exploded JSON arrays and JSON
scalar/object values.
@lsdch
lsdch force-pushed the multipart-array-explode branch from 2c2affc to ade220e Compare August 9, 2026 21:18
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.

3 participants