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

UTF-8 charset in response content causing the generator to replace all return types with void #231

Closed
ChristianIvicevic opened this issue Feb 3, 2020 · 3 comments

Comments

@ChristianIvicevic
Copy link

Describe the bug
When defining the responses and using the application/json;charset=UTF-8 mimetype the code generator fails to correctly type all requests and replaces the return types with void.

To Reproduce
Steps to reproduce the behavior:
Create an OpenAPI 3 schema file with this endpoint:

paths:
  /api/activities:
    get:
      operationId: getActivities
      responses:
        200:
          description: OK
          content:
            application/json;charset=UTF-8:
              schema:
                type: array
                description: Unordered list of activity names
                items:
                  type: string

Expected behavior
I expected the useGetActivities hook to return a string[], but it is typed as void. Replacing application/json;charset=UTF-8 with application/json fixes this issue.

Desktop (please complete the following information):

  • OS: macOS Catalina 10.15.2
@fabien0102
Copy link
Contributor

Nice catch, should be quite easy to fix, do you want to take this issue?

@fabien0102
Copy link
Contributor

We need to improve a bit this part to be more permissive

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";
}
}
}),

fabien0102 added a commit that referenced this issue Feb 3, 2020
@fabien0102
Copy link
Contributor

Was raining outside 🙄 So I fixed it ^^ Should be merge tomorrow 😉

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants