SmartBear / readyapi-swagger-plugin

Ready! API Plugin for importing Swagger definitions as REST Services
36 stars 27 forks source link

Compliance Assertion does not validate XML responses #53

Open flounderpinto opened 7 years ago

flounderpinto commented 7 years ago

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.

olensmar commented 7 years ago

awesome - do you want to submit a PR or is it ok if I just look at incorporating your code above?

flounderpinto commented 7 years ago

Go right ahead. If you're available to do it that would be great.

olensmar commented 7 years ago

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?

flounderpinto commented 7 years ago

Yes, that fixes it. Thanks!