diff --git a/packages/typespec-client-generator-core/src/types.ts b/packages/typespec-client-generator-core/src/types.ts index 2253551e2..7626bede4 100644 --- a/packages/typespec-client-generator-core/src/types.ts +++ b/packages/typespec-client-generator-core/src/types.ts @@ -1331,8 +1331,8 @@ function updateMultiPartInfo( : undefined, contentType: httpOperationPart.body.contentTypeProperty ? diagnostics.pipe( - getSdkModelPropertyType(context, httpOperationPart.body.contentTypeProperty, operation), - ) + getSdkModelPropertyType(context, httpOperationPart.body.contentTypeProperty, operation), + ) : undefined, defaultContentTypes: httpOperationPart.body.contentTypes, }; @@ -1662,8 +1662,9 @@ function updateTypesFromOperation( // conflicting usage between multipart and regular body if (sdkType.kind === "model") { const isUsedInMultipart = (sdkType.usage & UsageFlags.MultipartFormData) > 0; - const isUsedInOthers = ((sdkType.usage & UsageFlags.Json) | (sdkType.usage & UsageFlags.Xml)) > 0; - if (!multipartOperation && isUsedInMultipart || multipartOperation && isUsedInOthers) { + const isUsedInOthers = + ((sdkType.usage & UsageFlags.Json) | (sdkType.usage & UsageFlags.Xml)) > 0; + if ((!multipartOperation && isUsedInMultipart) || (multipartOperation && isUsedInOthers)) { // This means we have a model that is used both for formdata input and for regular body input diagnostics.add( createDiagnostic({ @@ -1672,7 +1673,7 @@ function updateTypesFromOperation( format: { modelName: sdkType.name, }, - }) + }), ); } } 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 a224bd05e..8211de495 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 @@ -44,7 +44,7 @@ describe("typespec-client-generator-core: multipart types", () => { ok(profileImage.multipartOptions); strictEqual(profileImage.multipartOptions.isFilePart, true); }); - + it("multipart conflicting model usage", async function () { await runner.compile( ` @@ -80,14 +80,14 @@ describe("typespec-client-generator-core: multipart types", () => { @post @route("/basic2") op basic2(@header contentType: "multipart/form-data", @body body: MultiPartRequest): NoContentResponse; - ` + `, ); deepEqual(runner.context.diagnostics.length, 0); const address = runner.context.sdkPackage.models.find((x) => x.name === "Address"); ok(address); deepEqual(address.usage, UsageFlags.Input); const multiPartRequest = runner.context.sdkPackage.models.find( - (x) => x.name === "MultiPartRequest" + (x) => x.name === "MultiPartRequest", ); ok(multiPartRequest); deepEqual(multiPartRequest.usage, UsageFlags.MultipartFormData | UsageFlags.Input); @@ -113,14 +113,14 @@ describe("typespec-client-generator-core: multipart types", () => { @post @route("/basic2") op basic2(@header contentType: "multipart/form-data", @body body: MultiPartRequest): NoContentResponse; - ` + `, ); deepEqual(runner.context.diagnostics.length, 0); const address = runner.context.sdkPackage.models.find((x) => x.name === "Address"); ok(address); deepEqual(address.usage, UsageFlags.Input | UsageFlags.Json); const multiPartRequest = runner.context.sdkPackage.models.find( - (x) => x.name === "MultiPartRequest" + (x) => x.name === "MultiPartRequest", ); ok(multiPartRequest); deepEqual(multiPartRequest.usage, UsageFlags.MultipartFormData | UsageFlags.Input);