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 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..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 @@ -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); + }); });