Skip to content

Error when response is plain text / csv #1165

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
1 task done
vdawg-git opened this issue Jun 13, 2023 · 3 comments
Closed
1 task done

Error when response is plain text / csv #1165

vdawg-git opened this issue Jun 13, 2023 · 3 comments
Labels
bug Something isn't working openapi-fetch Relevant to the openapi-fetch library

Comments

@vdawg-git
Copy link

Description

The parsing of the response fails when the response is not json.
Subsequently responses of text/plain and text/csv throw an error, which is not returned, but remains uncaught.

Reproduction

Query an api endpoint which return text/*, like https://api64.ipify.org.

Checklist

@vdawg-git vdawg-git added bug Something isn't working openapi-fetch Relevant to the openapi-fetch library labels Jun 13, 2023
@drwpow drwpow mentioned this issue Jun 16, 2023
3 tasks
@drwpow
Copy link
Contributor

drwpow commented Jun 16, 2023

This is improved in 0.3.0. Now, the .json() response will fall back to .text(). Or you can override the default behavior with the parseAs option

@drwpow drwpow closed this as completed Jun 16, 2023
@CEOehis
Copy link

CEOehis commented Jun 16, 2023

@drwpow is there a parse-as flag for the openapi-typescript CLI?

For context, I have a remote schema that returns json but the Content-Type is text/plain. Openapi-typescript only checks for .json or .yml extension or content-type. Hence in this case, the schema is never parsed: https://github.com/drwpow/openapi-typescript/blob/5ca0255281d5341e1e859eb60db0054224c39ac5/packages/openapi-typescript/src/load.ts#L125-L136

@drwpow
Copy link
Contributor

drwpow commented Jun 20, 2023

@drwpow is there a parse-as flag for the openapi-typescript CLI?

There’s not. It sounds like your server isn’t sending the right MIME types. The best solution is fixing that. But as a workaround you could write a short script that saves that file to a temporary local .json file and just running openapi-typescript locally.

Making the wrong “guess” of whether something is JSON or YAML is expensive and slows down everyone, hence that bit of code you referenced

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working openapi-fetch Relevant to the openapi-fetch library
Projects
None yet
Development

No branches or pull requests

3 participants