Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix HttpPart not respecting part name #3909

Merged
merged 3 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading