Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HotFix: OpenAPI3 creating conflicting type declaration when type was used in multipart implicit body and json body. #2752

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"] });
});
});