Skip to content

Commit

Permalink
allow text/json for requestBody as well
Browse files Browse the repository at this point in the history
  • Loading branch information
dachrillz committed Aug 4, 2022
1 parent 536c0ed commit f4fff90
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
3 changes: 3 additions & 0 deletions src/api/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,11 @@ export const newContentBodyWithErrors = (error: ApiError): Content => {
};
};

export type Mime = "application/json" | "text/json";

export type Content = {
"application/json"?: MimeType;
"text/json"?: MimeType;

x_x_x_x_results: ReportResult;
};
Expand Down
16 changes: 8 additions & 8 deletions src/httpParsing/parseHar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ const parseContent = (input: {
if (!input) {
return undefined;
}
if (input.mimeType !== "application/json") {
console.warn("Only application/json is supported!");
return undefined;
if (input.mimeType === "application/json" || input.mimeType === "text/json") {
return {
mimeType: input.mimeType,
text: input.text,
parsed: null,
};
}
return {
mimeType: input.mimeType,
text: input.text,
parsed: null,
};
console.warn("Only application/json and text/json is supported!");
return undefined;
};

const parseOneHar = (entry: Record<string, any>): har.t => {
Expand Down
13 changes: 5 additions & 8 deletions src/rule/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,19 +146,16 @@ const matchRequestBody = (
incrementHit(operationNode.requestBody.content);
resultOperationNode.requestBody.content = a.newContentBody();

const requestMimeType = request.postData?.mimeType as string;
if (
requestMimeType === "application/json" &&
!operationNode.requestBody.content[requestMimeType]
) {
const requestMimeType = request.postData?.mimeType as a.Mime;
const mimeType = operationNode.requestBody.content[requestMimeType];
if (!mimeType) {
result.success = false;
resultOperationNode.requestBody.content["application/json"] =
resultOperationNode.requestBody.content[requestMimeType] =
a.newMimeTypeWithError("BAD MIMETYPE");
return;
}

if (operationNode.requestBody.content["application/json"])
incrementHit(operationNode.requestBody.content["application/json"]);
incrementHit(mimeType);

resultOperationNode.requestBody.content["application/json"] =
a.newMimeType(undefined); // TODO add the schema once we are ready!
Expand Down

0 comments on commit f4fff90

Please sign in to comment.