Open flounderpinto opened 7 years ago
awesome - do you want to submit a PR or is it ok if I just look at incorporating your code above?
Go right ahead. If you're available to do it that would be great.
ok - i've pushed the branch https://github.com/SmartBear/readyapi-swagger-plugin/tree/swagger-compliance-assertion-improvements that contains this - can you give it a try on your end?
Yes, that fixes it. Thanks!
When responses are in XML format, the plugin tries to run them through the JSON parser, resulting in a failure on every XML response.
I was able to fix this by making the following modifications to SwaggerComplianceAssertion.java in validatePayload():
CHANGE:
JsonNode contentObject = Json.mapper().readTree(payload);
TO:if (contentType.equalsIgnoreCase("application/json")) { final ObjectMapper jsonMapper = new ObjectMapper(); contentObject = jsonMapper.readTree(payload); } else if (contentType.equalsIgnoreCase("application/xml")) { final XmlMapper xmlMapper = new XmlMapper(); contentObject = xmlMapper.readTree(payload); } else { throw new AssertionException( new AssertionError("Swagger Compliance testing failed. Invalid content type: " + contentType)); }
"contentType" is passed into validatePayload() as a parameter. Of course there may be a cleaner way to do this.