[v2.0] SchemaValidator does not handle missing components correctly

Issue #139 resolved
Former user created an issue

In the SchemaValidator, when setting up the schema definition refs, it seems to be assumed, that components do always exist for a given api. However in the OpenAPI spec it is shown, that the components section may be non-existant.

Currently a missing components section (which may even be empty) leads to a NPE, which fails the whole validation. The unchecked getComponents() seems to be the issue here.

// SchemaValidator@e37ef1528d830afe0805e1fd0ac319da3c87bf52:164-166
definitions = api.getComponents().getSchemas() == null ?
    Json.mapper().createObjectNode() :
    Json.mapper().readTree(Json.pretty(api.getComponents().getSchemas()));

Therefore i would suggest to check for getComponents() ahead of time, like this:

definitions = (api.getComponents() == null || api.getComponents().getSchemas() == null) ?
    Json.mapper().createObjectNode() :
    Json.mapper().readTree(Json.pretty(api.getComponents().getSchemas()));