Skip to content

Commit

Permalink
fix(oas): adjust according to code review
Browse files Browse the repository at this point in the history
closes #210
  • Loading branch information
ostridm committed Sep 20, 2023
1 parent 2dedf06 commit 8290abf
Show file tree
Hide file tree
Showing 10 changed files with 1,818 additions and 2,787 deletions.
13 changes: 10 additions & 3 deletions packages/oas/src/converter/parts/headers/HeadersConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ export abstract class HeadersConverter<T extends OpenAPI.Document>
implements SubConverter<Header[]>
{
private readonly CONTENT_TYPE_METHODS = ['post', 'put', 'patch', 'delete'];
private readonly ACCEPT_HEADER = 'accept';
private readonly CONTENT_TYPE_HEADER = 'content-type';

protected constructor(
private readonly spec: T,
Expand All @@ -34,13 +36,18 @@ export abstract class HeadersConverter<T extends OpenAPI.Document>
const headers: Header[] = [];
const pathObj = getOperation(this.spec, path, method);

if (this.CONTENT_TYPE_METHODS.includes(method.toLowerCase())) {
headers.push(...this.parseFromParams(path, method));

if (this.CONTENT_TYPE_METHODS.includes(method.toLowerCase()) &&
!headers.find(header=> header.name.toLowerCase() === this.CONTENT_TYPE_HEADER)
) {
headers.push(...this.createContentTypeHeaders(pathObj));
}

headers.push(...this.createAcceptHeaders(pathObj));
if (!headers.find(header=> header.name.toLowerCase() === this.ACCEPT_HEADER)) {
headers.push(...this.createAcceptHeaders(pathObj));
}

headers.push(...this.parseFromParams(path, method));

return headers;
}
Expand Down
8 changes: 4 additions & 4 deletions packages/oas/tests/fixtures/circular-refs.swagger.result.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
"bodySize": 0,
"cookies": [],
"headers": [
{
"name": "content-type",
"value": "application/json"
},
{
"name": "api_key",
"value": ""
},
{
"name": "content-type",
"value": "application/json"
}
],
"headersSize": 0,
Expand Down
8 changes: 4 additions & 4 deletions packages/oas/tests/fixtures/empty-schema.oas.result.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@
"url": "https://petstore.swagger.io/store/order/?dummy=",
"method": "PUT",
"headers": [
{
"value": "application/json",
"name": "content-type"
},
{
"name": "api_key",
"value": ""
},
{
"value": "application/json",
"name": "content-type"
}
],
"httpVersion": "HTTP/1.1",
Expand Down
Loading

0 comments on commit 8290abf

Please sign in to comment.