diff --git a/.chronus/changes/fix-multipart-name-2024-6-19-17-57-10.md b/.chronus/changes/fix-multipart-name-2024-6-19-17-57-10.md new file mode 100644 index 0000000000..814681fb27 --- /dev/null +++ b/.chronus/changes/fix-multipart-name-2024-6-19-17-57-10.md @@ -0,0 +1,8 @@ +--- +# Change versionKind to one of: internal, fix, dependencies, feature, deprecation, breaking +changeKind: fix +packages: + - "@typespec/http" +--- + +Fix `HttpPart` not respecting explicit part name by always using the property name diff --git a/packages/http/src/payload.ts b/packages/http/src/payload.ts index 1beeeeef08..e447c16bf4 100644 --- a/packages/http/src/payload.ts +++ b/packages/http/src/payload.ts @@ -311,7 +311,7 @@ function resolveMultiPartBodyFromModel( for (const item of type.properties.values()) { const part = diagnostics.pipe(resolvePartOrParts(program, item.type, visibility)); if (part) { - parts.push({ ...part, name: item.name, optional: item.optional }); + parts.push({ ...part, name: part.name ?? item.name, optional: item.optional }); } } diff --git a/packages/http/test/multipart.test.ts b/packages/http/test/multipart.test.ts index 735a2e8e27..784039f3ff 100644 --- a/packages/http/test/multipart.test.ts +++ b/packages/http/test/multipart.test.ts @@ -79,7 +79,7 @@ describe("define with the tuple form", () => { }); describe("define with the object form", () => { - it("use name from property name", async () => { + it("part explicit name is used", async () => { const body = await getMultipartBody(` op read( @header contentType: "multipart/mixed", @@ -89,7 +89,7 @@ describe("define with the object form", () => { `); strictEqual(body.parts.length, 1); - strictEqual(body.parts[0].name, "myPropertyPart"); + strictEqual(body.parts[0].name, "myPart"); }); it("using an array of parts marks the part as multi: true", async () => {