-
Notifications
You must be signed in to change notification settings - Fork 149
Description
What I See
Setting a parameter in the mime type (e.g. charset=utf-8 in text/plain;charset=utf-8) inside the consumes field in the swagger file ends up not matching any request.
You get the error
{"code":415,"message":"unsupported media type \"text/plain\", only [text/plain; charset=utf-8] are allowed"}
even if the client content type is set to text/plain; charset=utf-8
Sample swagger consumes line:
definitions:
'/test/{id}':
post:
consumes:
- text/plain; charset=utf-8
What I think is happening
It looks like the problem is that we're doing a string match of the parsed request mime type (text/plain), against the "allowed" mime types (text/plain; charset=utf-8)
runtime/middleware/validation.go
Line 45 in 3d6572c
| if swag.ContainsStringsCI(allowed, mt) { |
I talked briefly with @casualjim on slack and his opinion on this is:
I’m leaning towards saying it should only match the base + any parameters the client sends
So it seems like the behavior should be changed to
- Pass, client sends
text/plainand server acceptstext/plain;charset=utf-8 - Fail, client sends
text/plain;blah=trueand server acceptstext/plain;charset=utf-8 - Pass, client sends
text/plain;charset=utf-8and server acceptstext/plain - Pass, client sends
text/plain;charset=utf-8and server acceptstext/plain;charset=utf-8 - Fail, client sends
text/plain;charset=utf-8and server acceptstext/plain;charset=ascii
I'll try and submit a patch for this when I get a chance.