From 3f040eecc9a9b244a1f180adc549b05ba7ee91bc Mon Sep 17 00:00:00 2001 From: Yuchao Yan Date: Mon, 19 Aug 2024 14:17:25 +0800 Subject: [PATCH 1/3] fix multipart for client cusotmization --- .../src/types.ts | 27 +++++++------ .../test/types/multipart-types.test.ts | 39 +++++++++++++++++++ 2 files changed, 54 insertions(+), 12 deletions(-) diff --git a/packages/typespec-client-generator-core/src/types.ts b/packages/typespec-client-generator-core/src/types.ts index dddcae2b00..be899c5f11 100644 --- a/packages/typespec-client-generator-core/src/types.ts +++ b/packages/typespec-client-generator-core/src/types.ts @@ -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) { @@ -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 diff --git a/packages/typespec-client-generator-core/test/types/multipart-types.test.ts b/packages/typespec-client-generator-core/test/types/multipart-types.test.ts index b2a8f4141a..f361963691 100644 --- a/packages/typespec-client-generator-core/test/types/multipart-types.test.ts +++ b/packages/typespec-client-generator-core/test/types/multipart-types.test.ts @@ -619,4 +619,43 @@ 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); + }); }); From f1ee4568ac87aa34bde3faa03d58c6243b2f7e2a Mon Sep 17 00:00:00 2001 From: Yuchao Yan Date: Mon, 19 Aug 2024 14:19:19 +0800 Subject: [PATCH 2/3] format --- .../test/types/multipart-types.test.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/packages/typespec-client-generator-core/test/types/multipart-types.test.ts b/packages/typespec-client-generator-core/test/types/multipart-types.test.ts index f361963691..8ad3e632fa 100644 --- a/packages/typespec-client-generator-core/test/types/multipart-types.test.ts +++ b/packages/typespec-client-generator-core/test/types/multipart-types.test.ts @@ -643,10 +643,7 @@ describe("typespec-client-generator-core: multipart types", () => { `, ]; - await runner.compileWithCustomization( - testCode[0], - testCode[1] - ); + await runner.compileWithCustomization(testCode[0], testCode[1]); const models = runner.context.sdkPackage.models; const MultiPartRequest = models.find((x) => x.name === "MultiPartRequest"); From ab5bdc9959d0d7d6133d6571253b0e3fab5dfd38 Mon Sep 17 00:00:00 2001 From: Yuchao Yan Date: Mon, 19 Aug 2024 14:19:52 +0800 Subject: [PATCH 3/3] changelog --- .chronus/changes/multipart-fix-2024-7-19-14-19-40.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .chronus/changes/multipart-fix-2024-7-19-14-19-40.md diff --git a/.chronus/changes/multipart-fix-2024-7-19-14-19-40.md b/.chronus/changes/multipart-fix-2024-7-19-14-19-40.md new file mode 100644 index 0000000000..335fae7d55 --- /dev/null +++ b/.chronus/changes/multipart-fix-2024-7-19-14-19-40.md @@ -0,0 +1,7 @@ +--- +changeKind: fix +packages: + - "@azure-tools/typespec-client-generator-core" +--- + +Fix multipart for client customization \ No newline at end of file