Error is thrown when non-required field is null
Issue #235
resolved
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)
-
-
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
-
- changed status to resolved
- Log in to comment
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
If you update your schema to add
nullable: true
it should fix the problem.