Unable to send multiple media types in header
Issue #98
resolved
I'm sending multiple media types in header but swagger is unable to parse these values.
Content Type: application/json, application/xml
I have debugged the issue and found that RequsetValidator class is using MediaType.parse method for parsing of the header values and throwing exception.
@Nonnull
private ValidationReport validateMediaTypes(@Nonnull final Request request,
@Nonnull final String headerName,
@Nonnull final Collection<String> specMediaTypes,
@Nonnull final String invalidTypeKey,
@Nonnull final String notAllowedKey) {
final Collection<String> requestHeaderValues = request.getHeaderValues(headerName);
if (requestHeaderValues.isEmpty()) {
return empty();
}
final List<MediaType> requestMediaTypes = new ArrayList<>();
for (final String requestHeaderValue : requestHeaderValues) {
try {
requestMediaTypes.add(MediaType.parse(requestHeaderValue));
} catch (final IllegalArgumentException e) {
return ValidationReport.singleton(messages.get(invalidTypeKey, requestHeaderValue));
}
}
Comments (5)
-
-
I'm using swagger-request-validator-springmvc module. I'm sending my request via Postman
-
Thanks for the clarification. I think this one will be fixed with the fix for issue
#97. I'll update this ticket when its available. -
@ooxaam - the proposed fix for this is available in v1.3.9+
I'll close this ticket on the assumption that you issue is resolved. If it isn't, feel free to re-open the ticket.
-
- changed status to resolved
Available in v1.3.9
- Log in to comment
This looks very similar to Issue
#97.The
Request
implementation is supposed to split out the headers into a collection before it reaches this point. Can I ask what adapter you used, or how you constructed theRequest
object? I think the bug is there rather than in the validate code.Thanks.