-
-
Notifications
You must be signed in to change notification settings - Fork 450
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
Support application/openapi
content type
#1347
Comments
right that really is the only content type that’s not supported—something that doesn’t give any hint that I’m not opposed to adding support for this, even if it’s “unofficial.” but are you aware of any prior art that suggests that the default is YAML? Would adding As additional information, I’d like to find ways to “know” whether to parse something as YAML or JSON before parsing, mostly for error purposes. if you did have a syntax error, I want to be able to show the proper error message, and not leave people scratching their heads why a syntax error in their JSON schema threw a YAML parse error, etc. |
Yeah makes sense, totally with you! It looks like this is the current draft for adding the content types to ietf. It looks like the application/openapi type has been remove and instead you always have to provide +json and +yaml (which makes a lot of sense!) https://datatracker.ietf.org/doc/draft-ietf-httpapi-rest-api-mediatypes/. Seems like that means adding 'support' for
That being said how do you feel about this suggestion? I would be nice if I could still use the tool despite the API im using being a bit crazy (and using a fake content type)
What do you mean by "know" here. Are you suggesting you should peek into the response data and try and determine if it json or yaml? For the error message it feels like it would be nice to have a else statement inside the |
🤔 we do something “dumb” for readable streams where we just check if it starts with I’m wondering if that would just be a better solution across the board. There’s not an intentional reason why the two code paths diverge.
I just mean I want to always show a YAML error for YAML, and a JSON error for JSON. that means having some idea which is which before parsing (or, even if you blindly tried to parse as both to see if either worked but both threw, which error message do you show?). So I think just checking for |
@JElgar published |
Sorry very late but this has fixed the issue, thank you so much! |
Description
I have an API which provides an endpoint to fetch the schema but returns the
content-type
header asapplication/vnd.oai.openapi; charset=utf-8
. Briefly looking at https://stackoverflow.com/a/52542061/13473952 it seems that this content type is a bit fake but might be real at somepoint.Currently when the API returns this content type an exception is thrown.
This is the error
This seems to make sense given the current process for determining what format the file is in here
https://github.com/drwpow/openapi-typescript/blob/33b87df44e96442734bdd4682253312a32dc18c7/packages/openapi-typescript/src/load.ts#L129
which seems to be based on either an extension at the end of the url or if the content type includes yaml (which obviously isn't the case for application/vnd.oai.openapi). (It works for json as +json is in the spec)
Proposal
It feels like there are a couple of options here:
Add support for these semi fake content types:
And/or allow callers to override the expected response type (yaml/json) via a cli flag, something like
(quite frankly I like having this as a fall back [even if the above is implemented] as if the service Im relying on returns a crazy content type but I know its yaml/json it would be nice to be able to override the detection)
Not sure if you think either of these make sense/if I have just missed an option I can already use but more than happy to contribute either.
Checklist
The text was updated successfully, but these errors were encountered: