Error is thrown when non-required field is null

Issue #235 resolved
Former user created an issue

I am using testImplementation group: 'com.atlassian.oai', name: 'swagger-request-validator-restassured', version: '2.5.0' with Gradle in Java.

The field alias in the Waypoint definition is not required. So I am not returning it in my application.

However, swagger-request-validation says that the type of the field is not correct.

{
    "key" : "validation.request.body.schema.type",
    "level" : "ERROR",
    "message" : "[Path '/waypoints/0/alias'] Instance type (null) does not match any allowed primitive type (allowed: [\"string\"])",
    "context" : {
      "requestPath" : "/api/v1/transports",
      "apiRequestContentType" : "application/json",
      "location" : "REQUEST",
      "requestMethod" : "POST"
    }
  },

Since it is not required and null this error should not be thrown.

Comments (3)

  1. James Navin

    Can I just confirm - does the request body exclude the field altogether, or is it included but is null?

    In OpenAPI these are treated differently. See https://swagger.io/docs/specification/describing-parameters/ for details

    Note: nullable is not the same as an optional parameter or an empty-valued parameter. nullable means the parameter value can be null. Specific implementations may choose to map an absent or empty-valued parameter to null, but strictly speaking these are not the same thing.

    If you update your schema to add nullable: true it should fix the problem.

  2. Bernhard Vollnhofer

    Hi, @James Navin .

    Thank you for your fast response. The error was on my side. I mistook the response for the request.

    You can close this issue.

    Best wishes

  3. Log in to comment