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

[TCGC] Fix multipart for client customization #1392

Merged
merged 3 commits into from
Aug 19, 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
7 changes: 7 additions & 0 deletions .chronus/changes/multipart-fix-2024-7-19-14-19-40.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
changeKind: fix
packages:
- "@azure-tools/typespec-client-generator-core"
---

Fix multipart for client customization
27 changes: 15 additions & 12 deletions packages/typespec-client-generator-core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1795,18 +1795,6 @@ export function getAllModelsWithDiagnostics(
ogs.push(...operationGroup.subOperationGroups);
}
}
// orphan models
for (const model of client.service.models.values()) {
handleServiceOrphanType(context, model);
}
// orphan enums
for (const enumType of client.service.enums.values()) {
handleServiceOrphanType(context, enumType);
}
// orphan unions
for (const unionType of client.service.unions.values()) {
handleServiceOrphanType(context, unionType);
}
// server parameters
const servers = getServers(context.program, client.service);
if (servers !== undefined && servers[0].parameters !== undefined) {
Expand All @@ -1826,6 +1814,21 @@ export function getAllModelsWithDiagnostics(
updateUsageOfModel(context, UsageFlags.ApiVersionEnum, sdkVersionsEnum);
}
}
// update for orphan models/enums/unions
for (const client of listClients(context)) {
// orphan models
for (const model of client.service.models.values()) {
handleServiceOrphanType(context, model);
}
// orphan enums
for (const enumType of client.service.enums.values()) {
handleServiceOrphanType(context, enumType);
}
// orphan unions
for (const unionType of client.service.unions.values()) {
handleServiceOrphanType(context, unionType);
}
}
// update access
updateAccessOfModel(context);
// update spread model
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -619,4 +619,40 @@ describe("typespec-client-generator-core: multipart types", () => {
strictEqual(nameProperty.name, "name");
strictEqual((nameProperty as SdkBodyModelPropertyType).serializedName, "serializedName");
});

it("multipart in client customization", async () => {
const testCode = [
`
@service({title: "Test Service"}) namespace TestService;
model MultiPartRequest {
profileImage: bytes;
}

@post op multipartUse(@header contentType: "multipart/form-data", @body body: MultiPartRequest): NoContentResponse;
`,
`
namespace Customizations;

@client({name: "FirstOrderClient", service: TestService})
interface FirstOrder {}

@client({name: "SecondOrderClient", service: TestService})
interface SecondOrder {
myOp is TestService.multipartUse
}
`,
];

await runner.compileWithCustomization(testCode[0], testCode[1]);

const models = runner.context.sdkPackage.models;
const MultiPartRequest = models.find((x) => x.name === "MultiPartRequest");
ok(MultiPartRequest);
const property = MultiPartRequest.properties.find((x) => x.name === "profileImage");
ok(property);
strictEqual(property.kind, "property");
strictEqual(property.isMultipartFileInput, true);
ok(property.multipartOptions);
strictEqual(property.multipartOptions.isFilePart, true);
});
});
Loading