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

Commit

Permalink
Deal with charset
Browse files Browse the repository at this point in the history
Close #231
  • Loading branch information
fabien0102 committed Feb 4, 2020
1 parent 347a924 commit 77f316b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/scripts/import-open-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,14 @@ 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);
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";
} else {
return "void";
}
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

0 comments on commit 77f316b

Please sign in to comment.