-
-
Notifications
You must be signed in to change notification settings - Fork 443
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
Add content-type wildcard support to validation #93
Add content-type wildcard support to validation #93
Conversation
This implements the cascading wildcard behavior described in the OpenAPI specification for request body and response body validation. https://swagger.io/docs/specification/describing-request-body/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm thinking we either should return nil
or panic or even not handle that case.
What do you think?
openapi3/content.go
Outdated
// try the x/* pattern. | ||
i = strings.IndexByte(mime, '/') | ||
if i < 0 { | ||
return content["*/*"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can there be mimes without /
in them? Should this case really be considered at all?
@fenollp I don't believe mime types are valid without the subtype. However, since they are arbitrary string input from a client I'd prefer if we degraded to the wildcard rather than panic. Alternatively, we can return
This seems to suggest that My concern is that if I'm using the request/response validation in production then a panic on bad input might be an avenue for denial of service if a client is sending invalid mime types. I'd prefer the response to be "400 Bad Request" wherever possible for faulty input. |
Agreed wrt panics. |
Rather than allow accidental fallthrough of invalid mime types we will return nil.
@fenollp I've updated the PR to return Adding the test for this actually exposed a bug in my initial patch where any mime type that did not have metadata such as |
Amazing! Thanks! |
This implements the cascading wildcard behavior described in the OpenAPI
specification for request body and response body validation.
https://swagger.io/docs/specification/describing-request-body/
Closes #91