Skip to content
This repository has been archived by the owner on Nov 11, 2023. It is now read-only.

Deal with charset #232

Merged
merged 2 commits into from
Feb 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions src/scripts/import-open-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,17 +194,19 @@ export const getResReqTypes = (

if (isReference(res)) {
return getRef(res.$ref);
} else {
if (res.content && res.content["application/json"]) {
const schema = res.content["application/json"].schema!;
return resolveValue(schema);
} else if (res.content && res.content["application/octet-stream"]) {
const schema = res.content["application/octet-stream"].schema!;
return resolveValue(schema);
} else {
return "void";
}

if (res.content) {
for (let contentType of Object.keys(res.content)) {
if (contentType.startsWith("application/json") || contentType.startsWith("application/octet-stream")) {
const schema = res.content[contentType].schema!;
return resolveValue(schema);
}
}
return "void";
}

return "void";
}),
).join(" | ");

Expand Down
16 changes: 16 additions & 0 deletions src/scripts/tests/import-open-api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,22 @@ describe("scripts/import-open-api", () => {
expect(getResReqTypes(responses)).toEqual("FieldListResponse");
});

it("should return the type of application/json;charset=utf-8", () => {
const responses: Array<[string, ResponseObject]> = [
[
"200",
{
description: "An array of schema fields",
content: {
"application/json;charset=utf-8": { schema: { $ref: "#/components/schemas/FieldListResponse" } },
},
},
],
];

expect(getResReqTypes(responses)).toEqual("FieldListResponse");
});

it("should return the type of application/octet-stream if we don't have application/json response", () => {
const responses: Array<[string, ResponseObject]> = [
[
Expand Down