Skip to content

Commit

Permalink
fix(oas): do not drop operation responses if they have external ref (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
chohmann authored Aug 4, 2023
1 parent fe074de commit d1209ca
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 1 deletion.
78 changes: 78 additions & 0 deletions src/oas3/__tests__/bundle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1006,4 +1006,82 @@ describe('bundleOas3Service', () => {
]),
);
});

it('should not drop operation response if it has an external reference', () => {
const res = bundleOas3Service({
document: {
openapi: '3.0.0',
info: {
version: '0.0.1',
title: 'ref source spec',
},
paths: {
'/path_refToComponents': {
post: {
operationId: 'create_path_refToComponents',
responses: {
'200': {
$ref: '#/components/responses/SharedResponse1',
},
default: {
description: 'create_path_refToComponents default response description',
content: {
'application/json': {
schema: {
$ref: '#/components/schemas/SharedSchema1',
},
},
},
},
},
},
},
},
components: {
schemas: {
SharedSchema1: {
type: 'object',
properties: {
schema1Prop1: {
type: 'string',
},
},
},
},
responses: {
SharedResponse1: {
$ref: 'target.yaml#/components/responses/SharedResponse1',
},
},
},
},
});

expect(res.operations[0].responses).toHaveLength(2);
expect(res.operations[0].responses).toEqual(
expect.arrayContaining([
{
$ref: '#/components/responses/SharedResponse1',
code: '200',
},
{
id: 'http_response-http_operation-undefined-post-/path_refToComponents-default',
code: 'default',
headers: [],
contents: [
{
id: 'http_media-http_response-http_operation-undefined-post-/path_refToComponents-default-application/json',
mediaType: 'application/json',
examples: [],
encodings: [],
schema: {
$ref: '#/components/schemas/0',
},
},
],
description: 'create_path_refToComponents default response description',
},
]),
);
});
});
2 changes: 1 addition & 1 deletion src/oas3/transformers/responses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const translateToResponse = withContext<
Optional<IHttpOperationResponse<true> | (Pick<IHttpOperationResponse, 'code'> & Reference)>
>
>(function ([statusCode, response]) {
const maybeResponseObject = this.maybeResolveLocalRef(response);
const maybeResponseObject = this.maybeResolveLocalRef(response) ?? response;

if (isReferenceObject(maybeResponseObject)) {
(maybeResponseObject as Pick<IHttpOperationResponse, 'code'> & Reference).code = statusCode;
Expand Down

0 comments on commit d1209ca

Please sign in to comment.