fix(explorer): respect encoding.contentType for multipart/form-data parts#1369
fix(explorer): respect encoding.contentType for multipart/form-data parts#1369
Conversation
…arts OpenAPI encoding objects specify per-part Content-Type for multipart/form-data but these were ignored, causing file parts to always send as application/octet-stream regardless of the spec. - setBody/buildPostmanRequest: thread encoding through and set contentType on sdk.FormParam for each field that declares one, so code snippets reflect the correct per-part Content-Type - makeRequest: wrap file and string parts in a typed Blob when encoding.contentType is present so the actual HTTP request uses it - Request/index.tsx: extract encoding from requestBody for the active content type and pass to both buildPostmanRequest and makeRequest - CodeSnippets: accept requestBody prop and derive encoding from it so generated code snippets stay in sync encoding.contentType may be comma-separated per OAS spec; the first value is used. Closes #1247
|
Size Change: +7.23 kB (+0.33%) Total Size: 2.22 MB
ℹ️ View Unchanged
|
|
Visit the preview URL for this PR (updated for commit df73f93): https://docusaurus-openapi-36b86--pr1369-jc719vzu.web.app (expires Wed, 29 Apr 2026 21:57:02 GMT) 🔥 via Firebase Hosting GitHub Action 🌎 Sign: bf293780ee827f578864d92193b8c2866acd459f |
…a encoding When a multipart/form-data field declares a comma-separated encoding.contentType (e.g. "image/png, image/jpeg, application/octet-stream"), a Content-Type dropdown appears next to the field input. Selecting a type updates both the generated code snippet and the actual request in real time. - EncodingSelection/slice: new Redux slice storing per-field content type selections - store/ApiItem: register slice and seed empty initial state - FormBodyItem: parse comma-separated contentType, render FormSelect picker when multiple types are available, dispatch selection to Redux - Body/index: extract encoding from spec and pass fieldEncoding to FormBodyItem - Request/index + CodeSnippets: merge spec encoding with Redux encodingSelection so user picks propagate to both buildPostmanRequest and makeRequest - multipartEncoding.yaml: add /post/multi-content-type demo endpoint with three selectable types to exercise the picker UI Related to #1247
/post/* paths don't exist on HTTPBin — /anything/{path} accepts
any method and echoes the full request.
…aded When the body is empty (no file selected), preserve the original placeholder formdata params from the Postman request and apply the selected encoding contentType to them. This ensures the code snippet reflects the encoding selection immediately — before the user uploads a file — since postman-code-generators emits `;type=<ct>` for FormParams that have a contentType set. Also wraps the Content-Type FormSelect in a div to push it onto its own row below the property label. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Code Review: PR #1369 —
|
| Area | Assessment |
|---|---|
| Core fix correctness | ✅ Correct approach for all three surfaces |
| Known limitation documented | ✅ Upstream codegen bug filed and linked |
| State management | |
| Code duplication | |
| Type safety | requestBody: any and state: any (consistent with existing patterns) |
| Test coverage | ❌ No automated tests added |
FileArrayFormBodyItem |
Not updated — array file inputs won't get encoding applied in the UI |
The core fix is sound and well-scoped. The main actionable items before merge are: extracting the duplicate merge logic into a hook, and wiring clearEncodingSelection on content-type switches to prevent stale state.
🤖 Generated with Claude Code
- Extract duplicate specEncoding+user-selection merge logic into a shared useResolvedEncoding(requestBody) hook; replaces copy-pasted blocks in Request/index.tsx and CodeSnippets/index.tsx - Narrow requestBody prop type in CodeSnippets from `any` to RequestBodyObject - Dispatch clearEncodingSelection when the active content type changes so stale per-field selections don't persist across content-type switches - Add comment explaining the mount-only useEffect in FormBodyItem Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Summary
When a
multipart/form-datarequest body defines an OpenAPIencodingobject with per-fieldcontentType, those values were silently ignored. File parts always sent asapplication/octet-streamand string parts astext/plainregardless of the spec.Changes:
buildPostmanRequest/setBody: threadencodingthrough and setcontentTypeon eachsdk.FormParamthat declares one — fixes code snippets for text-type parts (e.g.metadata: application/json)makeRequest: wrap file and string form parts in a typedBlobwhenencoding.contentTypeis present — fixes the actual HTTP request for all part typesRequest/index.tsx: extractencodingfromitem.requestBody?.content?.[contentType]?.encodingand pass to bothCodeSnippets/index.tsx: acceptrequestBodyprop (passed fromApiExplorer/index.tsx) and deriveencodingfrom it so snippets stay in sync with the active content typeEncodingSelection/slice.ts(new Redux slice): tracks per-field content-type selection whenencoding.contentTypeis a comma-separated listFormBodyItem: renders aContent-Typedropdown for fields with multiple declared encoding options; dispatches selection into ReduxbuildPostmanRequestempty-body case: preserves placeholder FormParams (with encoding applied) when no file has been uploaded yet, so the code snippet reflects the selected encoding immediatelyencoding.contentTypecan be comma-separated per the OAS spec; the first value is used for the actual request, and a selector is shown in the UI when multiple are declared.Known limitation — curl/Python snippets for binary file parts
The
postman-code-generatorscurl codegen readsFormParam.contentTypeduring preprocessing but does not emit;type=fortype === "file"params in the snippet — only for text-type params. As a result:metadata: application/json)file: image/png);type=application/jsonemitted;type=missing (codegen bug)contentTypecontentTypeThe actual HTTP request correctly uses the declared
contentTypefor all part types. The snippet gap for binary file parts is an upstream library bug filed at postmanlabs/postman-code-generators#815.Test plan
Content-Type— verify via HTTPBin (/anything/*endpoints echo the request back) or browser DevTools Network tab;type=application/jsonfor text-type parts withencoding.contentType: application/jsonencodingentry are unaffected (default browser behaviour)encodingobject behave identically to beforeencoding.contentTypeis a comma-separated list, aContent-Typedropdown appears in the form body; selecting a value updates both the snippet and the actual requestDemo specs added under
demo/examples/tests/multipartEncoding.yaml.Closes #1247
🤖 Generated with Claude Code