Skip to content

Commit f3aaf87

Browse files
sserrataclaude
andcommitted
fix(multipart-encoding): show encoding in snippet before file is uploaded
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>
1 parent 7a12bf6 commit f3aaf87

2 files changed

Lines changed: 32 additions & 10 deletions

File tree

packages/docusaurus-theme-openapi-docs/src/theme/ApiExplorer/Body/FormBodyItem/index.tsx

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -98,16 +98,18 @@ export default function FormBodyItem({
9898
<>
9999
{label && <FormLabel label={label} required={required} />}
100100
{hasMultipleEncodings && (
101-
<FormSelect
102-
label="Content-Type"
103-
options={encodingOptions}
104-
value={selectedEncoding}
105-
onChange={(e: React.ChangeEvent<HTMLSelectElement>) => {
106-
const ct = e.target.value;
107-
setSelectedEncoding(ct);
108-
dispatch(setFieldEncoding({ field: id, contentType: ct }));
109-
}}
110-
/>
101+
<div style={{ marginTop: "0.5rem" }}>
102+
<FormSelect
103+
label="Content-Type"
104+
options={encodingOptions}
105+
value={selectedEncoding}
106+
onChange={(e: React.ChangeEvent<HTMLSelectElement>) => {
107+
const ct = e.target.value;
108+
setSelectedEncoding(ct);
109+
dispatch(setFieldEncoding({ field: id, contentType: ct }));
110+
}}
111+
/>
112+
</div>
111113
)}
112114
<FormFileUpload
113115
placeholder={schemaObject.description || id}

packages/docusaurus-theme-openapi-docs/src/theme/ApiExplorer/buildPostmanRequest.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,26 @@ function setBody(
303303
}
304304

305305
if (body.type === "empty") {
306+
// When the original request has formdata and encoding is declared, keep the
307+
// placeholder params so the code snippet reflects the selected encoding even
308+
// before the user has uploaded a file.
309+
if (
310+
clonedPostman.body?.mode === "formdata" &&
311+
encoding &&
312+
Object.keys(encoding).length > 0
313+
) {
314+
const members: any[] =
315+
(clonedPostman.body.formdata as any)?.members ?? [];
316+
members.forEach((param: any) => {
317+
const partContentType = encoding[param.key]?.contentType
318+
?.split(",")[0]
319+
.trim();
320+
if (partContentType) {
321+
param.contentType = partContentType;
322+
}
323+
});
324+
return;
325+
}
306326
clonedPostman.body = undefined;
307327
return;
308328
}

0 commit comments

Comments
 (0)