Skip to content

Commit

Permalink
Fix #2347.
Browse files Browse the repository at this point in the history
  • Loading branch information
tjprescott committed Sep 20, 2023
1 parent 8e3240a commit 9da9a94
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@typespec/http",
"comment": "",
"type": "none"
}
],
"packageName": "@typespec/http"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@typespec/openapi3",
"comment": "Fix issue where response schemas would sometimes appear as \"anyOf\" with duplicate identical references when they should just be a single schema reference.",
"type": "none"
}
],
"packageName": "@typespec/openapi3"
}
3 changes: 2 additions & 1 deletion packages/http/src/responses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ function getResponseStatusCodes(
}
}

return codes;
// eliminate duplicate status codes
return [...new Set(codes)];
}

/**
Expand Down
22 changes: 22 additions & 0 deletions packages/openapi3/test/openapi-output.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,28 @@ describe("openapi3: operations", () => {

strictEqual(res.paths["/"].get.deprecated, true);
});

it("define operation response structure", async () => {
const res = await openApiFor(
`
model CustomUnauthorizedResponse {
@statusCode _: 401;
@body body: UnauthorizedResponse;
}
op list(): CustomUnauthorizedResponse;
`
);
const responses = res.paths["/"].get.responses;
ok(responses);
ok(responses["401"]);
ok(responses["401"].content);
ok(responses["401"].content["application/json"]);
ok(responses["401"].content["application/json"].schema);
deepStrictEqual(responses["401"].content["application/json"].schema, {
$ref: "#/components/schemas/TypeSpec.Http.UnauthorizedResponse",
});
});
});

describe("openapi3: request", () => {
Expand Down

0 comments on commit 9da9a94

Please sign in to comment.