Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
tadelesh committed Sep 19, 2024
1 parent dbb5c29 commit 8ed87e3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
11 changes: 6 additions & 5 deletions packages/typespec-client-generator-core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -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({
Expand All @@ -1672,7 +1673,7 @@ function updateTypesFromOperation(
format: {
modelName: sdkType.name,
},
})
}),
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
`
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit 8ed87e3

Please sign in to comment.