Skip to content

Commit

Permalink
Fix #2575.
Browse files Browse the repository at this point in the history
  • Loading branch information
tjprescott committed Oct 17, 2023
1 parent 897507d commit 0e388f3
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
13 changes: 10 additions & 3 deletions packages/openapi3/src/openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -416,11 +416,18 @@ function createOAPIEmitter(program: Program, options: ResolvedOpenAPI3EmitterOpt
/**
* Validates that common responses are consistent and returns the minimal set that describes the differences.
*/
function validateCommonResponses(ops: HttpOperation[]): HttpOperationResponse[] {
function validateCommonResponses(
statusCode: string,
ops: HttpOperation[]
): HttpOperationResponse[] {
const statusCodeResponses: HttpOperationResponse[] = [];
for (const op of ops) {
for (const response of op.responses) {
statusCodeResponses.push(response);
if (getOpenAPI3StatusCodes(response.statusCodes, response.type).includes(statusCode)) {
statusCodeResponses.push(response);
} else {
const test = "best";
}
}
}
const ref = statusCodeResponses[0];
Expand Down Expand Up @@ -609,7 +616,7 @@ function createOAPIEmitter(program: Program, options: ResolvedOpenAPI3EmitterOpt
}
shared.bodies = validateCommonBodies(operations);
for (const [statusCode, ops] of responseMap) {
shared.responses.set(statusCode, validateCommonResponses(ops));
shared.responses.set(statusCode, validateCommonResponses(statusCode, ops));
}
results.push(shared);
return results;
Expand Down
23 changes: 21 additions & 2 deletions packages/openapi3/test/shared-routes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,13 +353,21 @@ describe("openapi3: shared routes", () => {
`
@service({title: "My Service"})
namespace Foo {
@error
model ErrorModel {
@header "x-ms-error-code": string;
description: string;
}
@sharedRoute
@route("/process")
op processInt(@body body: int32, @query options: string): int32;
op processInt(@body body: int32, @query options: string): int32 | ErrorModel;
@sharedRoute
@route("/process")
op processString(@body body: string, @query options: string): string;
op processString(@body body: string, @query options: string): string | ErrorModel;
}
`
);
Expand Down Expand Up @@ -402,6 +410,17 @@ describe("openapi3: shared routes", () => {
},
description: "The request has succeeded.",
},
default: {
description: "The request has succeeded.",
headers: {
"x-ms-error-code": {
required: true,
schema: {
type: "string",
},
},
},
},
});
});

Expand Down

0 comments on commit 0e388f3

Please sign in to comment.