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

Deal with charset #232

merged 2 commits into from
Feb 4, 2020

Conversation

fabien0102
Copy link
Contributor

Issue

#231

Why

We didn't deal with more advanced content type, this should be way more flexible.

@fabien0102 fabien0102 requested a review from mpotomin February 3, 2020 16:53
@fabien0102 fabien0102 self-assigned this Feb 3, 2020
Copy link
Contributor

@mpotomin mpotomin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good and test run as expected! A minor readability suggestion:

Comment on lines 197 to 208
} 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";
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we are touching this part of the code, let's improve the readability a little bit by decreasing the amount of levels of code indentation. I suggest:

export const getResReqTypes = (
  responsesOrRequests: Array<[string, ResponseObject | ReferenceObject | RequestBodyObject]>,
) =>
  uniq(
    responsesOrRequests.map(([_, res]) => {
      if (!res) {
        return "void";
      }

      if (isReference(res)) {
        return getRef(res.$ref);
      }

      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(" | ");

@mpotomin mpotomin self-requested a review February 4, 2020 09:39
Copy link
Contributor

@mpotomin mpotomin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test are ✅

@fabien0102 fabien0102 merged commit ab65d3e into master Feb 4, 2020
@fabien0102 fabien0102 deleted the charset-in-content branch February 4, 2020 09:45
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants