-
Notifications
You must be signed in to change notification settings - Fork 349
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
Issue in findBestHttpContentByMediaType due to inconsistent behaviour between accepts
and type-is
libraries
#1152
Comments
TS code for Potential Fix 2 (which we are using internally) is:
|
Hey @mpretty-cyro thanks a lot for the super-detailed report. I'm going to have a look into this but we can probably go with the fix 2 you have proposed. We've migrated most of the parts to use type-is, but as you can see we might have forgot some parts. |
@XVincentX No worries, sorry I'd submit a PR myself but am pretty slammed at work at the moment. Just to note with the fix 2 - I ran into some problems with empty responses and when debugging found that a change to the |
Hey, I've checked your alternative (and other combinations) that won't solve the issue. The Kind of the same with the
To me the behaviour looks correct. The accept header has no What would no version mean? Version 1? Latest version? I am going to check out the RFC to see if there's a standard behaviour about that but if not, I would say the accept library (and thous Prism) is behaving correctly since there's no way to know which version you'd like to return |
I tried reading through this issue, and AFAIK |
@dougwilson I'm sorry I have pinged you (it was not my intention). I've just clarified my comment, I also agree that the library is behaving correctly. Here's the excerpt:
|
@mpretty-cyro I've verified and effectively the only "kind of standardised" parameter is the quality. There's nothing about version and so we can't really assume anything about it. |
@XVincentX So I'm less concerned about be able to version responses (while that would be nice I accept that it's not really part of the standard); the main issue I was having is that I would have expected the |
@mpretty-cyro Can you try the branch linked to the PR #1159 ? I should have been able to overcome both the limitations there. |
@XVincentX Sorry can't seem to get the branch building correctly - I tried updating the code in the |
That's weird @mpretty-cyro, what problems are you facing when trying the branch? |
Describe the bug
Our API provides versioning information in the
Accept
header with this structureapplication/vnd.archa.api+json; version=1
but trying to use this structure as the content type seems to result in one of two errors depending on how it's specified:If we specify a
Content-Type
ofapplication/vnd.archa.api+json; version=1
we get an error sayingViolation: response The received media type "application/vnd.archa.api+json; version=1" does not match the one specified in the current response: application/vnd.archa.api+json; version=1
(though the request returns).version
value (Support for media type version request jshttp/type-is#14)Or, if we specify a
Content-Type
ofapplication/vnd.archa.api+json
we get an error sayingRequest terminated with error: https://stoplight.io/prism/errors#NOT_ACCEPTABLE: The server cannot produce a representation for your accept header
.To Reproduce
Run this CLI command
prism mock api.yaml
See error
After sending a Get request with the correct
Accept
header (see below) you receive theRequest terminated with error: https://stoplight.io/prism/errors#NOT_ACCEPTABLE: The server cannot produce a representation for your accept header
error.Expected behavior
Providing an
Accept
header ofapplication/vnd.archa.api+json; version=1
should find a response with aContent-Type
ofapplication/vnd.archa.api+json
.Environment (remove any that are not applicable):
Question
Which is the expected
Content-Type
in this case? (application/vnd.archa.api+json; version=1
orapplication/vnd.archa.api+json
)Potential Fix 1
I've done something wrong and change my spec 😛
Potential Fix 2
One work-around I've found is to update the
findBestHttpContentByMediaType
method to use the "type-is" library, this way it matches theapplication/vnd.archa.api+json; version=1
Accept
header to theapplication/vnd.archa.api+json
Content-Type
.Potential Fix 3
An option which seems pretty hacky to me would be to remove anything after a
;
in the media type so we can continue to use the "accepts" library.The text was updated successfully, but these errors were encountered: