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 21, 2023
1 parent 82b8c61 commit f9592b5
Show file tree
Hide file tree
Showing 7 changed files with 1,914 additions and 1,904 deletions.
16 changes: 13 additions & 3 deletions packages/oas/src/converter/parts/headers/HeadersConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,22 @@ export abstract class HeadersConverter<T extends OpenAPI.Document>
implements SubConverter<Header[]>
{
private readonly CONTENT_TYPE_METHODS = ['post', 'put', 'patch', 'delete'];
private readonly CONTENT_TYPE_HEADER = 'content-type';

protected constructor(
private readonly spec: T,
private readonly sampler: Sampler
) {}

protected abstract createContentTypeHeaders(
pathObj: OperationObject
pathObj: OperationObject,
header?: Header
): Header[];

protected abstract createAcceptHeaders(pathObj: OperationObject): Header[];
protected abstract createAcceptHeaders(
pathObj: OperationObject,
header?: Header
): Header[];

protected abstract convertHeaderParam(
headerParam: LocationParam<ParameterObject>
Expand All @@ -34,7 +39,12 @@ 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())) {
if (
this.CONTENT_TYPE_METHODS.includes(method.toLowerCase()) &&
!headers.find(
(header) => header.name.toLowerCase() === this.CONTENT_TYPE_HEADER
)
) {
headers.push(...this.createContentTypeHeaders(pathObj));
}

Expand Down
Loading

0 comments on commit f9592b5

Please sign in to comment.