Swagger compliance assertion with content type different than application/json always fails
The swagger compliance assertion has a too strict validation on the content type. Currently only the content type application/xml and application/json are allowed, otherwise the swagger compliance assertion fails.
According to RFC6839 the content-type can contain +json (or +xml) to signify that the document can be interpreted as json (or xml) in addition to some other schema.
I have included the response I received on an API call and a screenshot of the error we receive.
Is there a workaround for this such that the swagger compliance can still be used to validate the response in case the content-type is not application/json or application/xml?
I tried modifying the response headers inspired by
but I wasn't able to do this
I added a RequestFilter.afterRequest event with the following code. But editing the content type does not seem possible
context.httpResponse.contentType = "application/json;charset=UTF-8"
HTTP/1.1 200 OK
X-Backside-Transport: OK OK
Date: Wed, 20 Oct 2021 12:04:05 GMT
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Strict-Transport-Security: max-age=31536000 ; includeSubDomains
X-Xss-Protection: 1; mode=block
Solved! Go to Solution.
Just so I understand - so you're swagger/OAS has mediatypes that include the +json suffix, but the Compliance Assertion isn't supporting requests with extended Content-Type header values? Is that right?
You can raise a Customer Support ticket to see if SmartBear can help and a New Feature request to include extended mediatype assertions -if it gets enough upvotes it could be considered for future ReadyAPI releases,
The following link --> https://swagger.io/docs/specification/media-types/. indicates the supported extended media types supported by OAS currently and even explicitly mentions RFC 6368 (which is the RFC relating to vendor extensions which you appear to have in your payload) so you'd hope the Compliance Assertion would support them.
However - there still might be a way to sort - at least we should be able to update your headers using an Event Handler at least.
You mentioned you tried using an event handler but it didn't work.
Can you confirm exactly what happened - what you mean by it didn't work? Did you get errors? No visible change? What did it say in the ReadyAPI Log and the Error Log?
Can you supply the code you used to attempt to change the header value please?
Did you use RequestFilter.afterRequest or RequestFilter.filterRequest