Skip to content

Commit

Permalink
Fix HttpPart not respecting part name (#3909)
Browse files Browse the repository at this point in the history
fix  [#3779](#3779)

Fixing this issue where the property name always won against the
explicit part name for naming the part over the wire. This was the
opposite of what the design said.
  • Loading branch information
timotheeguerin committed Jul 30, 2024
1 parent da41e74 commit 44ffaf7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
8 changes: 8 additions & 0 deletions .chronus/changes/fix-multipart-name-2024-6-19-17-57-10.md
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion packages/http/src/payload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}
}

Expand Down
4 changes: 2 additions & 2 deletions packages/http/test/multipart.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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 () => {
Expand Down

0 comments on commit 44ffaf7

Please sign in to comment.