Vertx-web: OpenApi: JsonTypeValidator does not check for null string

Created on 17 Nov 2017  路  2Comments  路  Source: vert-x3/vertx-web

Version

  • vert.x core: 3.5.0
  • vert.x web: 3.5.0

Context

On a route created by the OpenApi spec with a required request body of content-type "application/json, a NullPointerException occurs if the request has a content-type header of "application/json" but a null body. This null pointer arises from the JsonTypeValidator class passing the request body to the validator without first checking if it is null.

Steps to reproduce

  1. Create a valid openapi file with a required request of content-type "application-json"
  2. Make a request to this route with content-type header "application/json" and no body.

Extra

Example request:

Request method:  PUT
Request URI:     http://localhost:4000/route-requiring-json-request
Proxy:           <none>
Request params:  <none>
Query params:    <none>
Form params:     <none>
Path params:     <none>
Headers:         Accept=application/json
                 Content-Type=application/json; charset=UTF-8
Cookies:         <none>
Multiparts:      <none>
Body:            <none>

causes this to occur:

[vert.x-eventloop-thread-3] WARN  i.t.w.a.v.h.DefaultErrorHandler - Unexpected exception
java.lang.NullPointerException: null
    at com.networknt.schema.TypeFactory.getValueNodeType(TypeFactory.java:61)
    at com.networknt.schema.TypeValidator.validate(TypeValidator.java:54)
    at com.networknt.schema.JsonSchema.validate(JsonSchema.java:143)
    at com.networknt.schema.RefValidator.validate(RefValidator.java:85)
    at com.networknt.schema.JsonSchema.validate(JsonSchema.java:143)
    at com.networknt.schema.AllOfValidator.validate(AllOfValidator.java:49)
    at com.networknt.schema.JsonSchema.validate(JsonSchema.java:143)
    at com.networknt.schema.BaseJsonValidator.validate(BaseJsonValidator.java:79)
    at io.vertx.ext.web.api.validation.impl.JsonTypeValidator.isValid(JsonTypeValidator.java:31)
    at io.vertx.ext.web.api.validation.impl.BaseValidationHandler.validateEntireBody(BaseValidationHandler.java:238)
    at io.vertx.ext.web.api.validation.impl.BaseValidationHandler.handle(BaseValidationHandler.java:72)
    at io.vertx.ext.web.api.validation.impl.BaseValidationHandler.handle(BaseValidationHandler.java:20)

I would instead expect a ValidationException to occur.

Most helpful comment

Fixed inside branch contracts_fix

All 2 comments

I'm investigating!

Fixed inside branch contracts_fix

Was this page helpful?
0 / 5 - 0 ratings