Skip to content
This repository has been archived by the owner on Jan 11, 2019. It is now read-only.

Compliance Assertion does not validate XML responses #53

Open
flounderpinto opened this issue Feb 15, 2017 · 4 comments
Open

Compliance Assertion does not validate XML responses #53

flounderpinto opened this issue Feb 15, 2017 · 4 comments

Comments

@flounderpinto
Copy link

flounderpinto commented Feb 15, 2017

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
Copy link
Contributor

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

@flounderpinto
Copy link
Author

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

@olensmar
Copy link
Contributor

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
Copy link
Author

Yes, that fixes it. Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants