SwaggerRequestResponseValidator fails with XML body

Issue #65 resolved
Giovanni Bussu created an issue

Using SwaggerRequestResponseValidator to validate requests against Swagger specs, validation fails when when request body is an XML.

For example using the pet store specification, and invoking the POST /pet operation, which consumes both application/json and application/xml

/pet: {
  post: {
    ...
    consumes: [
      "application/json",
      "application/xml"
    ],
    ...
    parameters: [
      {
      in: "body",
      name: "body",
      description: "Pet object that needs to be added to the store",
      required: true,
      schema: {
        $ref: "#/definitions/Pet"
      }
    ...
}

I get the following error when request body is an XML:

Unable to parse JSON - Unexpected character ('<' (code 60)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')
     at [Source: <Pet><name>doggie</name><photoUrls>http://localhost:8080/doggie.jpg</photoUrls></Pet>; line: 1, column: 2].: []

On the other side, if request body is a JSON, request is correctly validated, as you can see in attached test class.

Comments (2)

  1. James Navin

    Version 1.4.2 fixes the validation error, but doesn't validate the XML body. I have raised #111 to track adding support for XML validation.

  2. Log in to comment