Skip to content

Commit

Permalink
HotFix: OpenAPI3 creating conflicting type declaration when type was …
Browse files Browse the repository at this point in the history
…used in multipart implicit body and json body. (#2752)

fix #2751

Problem was when we reduce the context it is a patch not a replace so if
we delete the contentType to have the default handling then it would
keep the previous value instead of actually removing it.
  • Loading branch information
timotheeguerin authored Dec 13, 2023
1 parent 8be7c23 commit 85343de
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@typespec/openapi3",
"comment": "Fix: OpenAPI3 creating conflicting type declaration when type was used in multipart implicit body and json body",
"type": "none"
}
],
"packageName": "@typespec/openapi3"
}
2 changes: 1 addition & 1 deletion packages/openapi3/src/schema-emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export class OpenAPI3SchemaEmitter extends TypeEmitter<
const contentType = this.#getContentType();

if (contentType === "application/json") {
delete patch.contentType;
patch.contentType = undefined;
}

return patch;
Expand Down
17 changes: 17 additions & 0 deletions packages/openapi3/test/multipart.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,21 @@ describe("typespec-autorest: multipart", () => {
}
);
});

it("enum used in both a json payload and multipart part shouldn't create 2 models", async () => {
const res = await openApiFor(
`
enum FilePurpose {
one,
two,
}
interface Files {
@get listFiles(purpose: FilePurpose): string;
@post uploadFile(@header contentType: "multipart/form-data", purpose: FilePurpose): string;
}
`
);
deepStrictEqual(res.components.schemas.FilePurpose, { type: "string", enum: ["one", "two"] });
});
});

0 comments on commit 85343de

Please sign in to comment.