Vertx-web: NullPointerException when creating router from OpenAPI3RouterFactory using "path params" and "splitted" yaml (explode)

Created on 21 Jan 2019  路  4Comments  路  Source: vert-x3/vertx-web

Version

  • vert.x core: 3.6.2
  • vert.x web: 3.6.2
  • vert.x web api-contract : 3.6.2

Context

I encountered an exception which looks suspicious while I was creating the Router from the OpenAPI3RouterFactory.

I am creating the Router from the OpenAPI3RouterFactory using YAML OpenApi3 files.
I'm using "reference" in our Yaml to be able to split them. Everything is fine as long as I don't use "path params".
When I want to use path params and reference it in another YAML I get an exception :

Caused by: java.lang.NullPointerException: null
    at io.vertx.ext.web.api.contract.openapi3.impl.OpenAPI3RequestValidationHandlerImpl.checkSupportedAndNeedWorkaround(OpenAPI3RequestValidationHandlerImpl.java:384)
    at io.vertx.ext.web.api.contract.openapi3.impl.OpenAPI3RequestValidationHandlerImpl.parseParameter(OpenAPI3RequestValidationHandlerImpl.java:426)
    at io.vertx.ext.web.api.contract.openapi3.impl.OpenAPI3RequestValidationHandlerImpl.parseOperationSpec(OpenAPI3RequestValidationHandlerImpl.java:97)
    at io.vertx.ext.web.api.contract.openapi3.impl.OpenAPI3RequestValidationHandlerImpl.<init>(OpenAPI3RequestValidationHandlerImpl.java:87)
    at io.vertx.ext.web.api.contract.openapi3.impl.OpenAPI3RouterFactoryImpl.getRouter(OpenAPI3RouterFactoryImpl.java:300)

The call to parameter.getExplode() return null in that case.

Important Notes :

  • If I don't split in another YAML file it's working as expected.
  • If I don't use path param but still using splitted YAML : it's working as expected.

Its seems to be a combination of "path param" + "using ref".

Workaround :
declare explode: false in the splitted yaml file and it will work as the parameter.getExplode() will be "false" (or true depending on your input).

Do you have a reproducer?

root.yaml :

openapi: 3.0.0
info:
  version: 1.0.0
  title: Swagger Test
  license:
    name: MIT
servers:
- url: /
paths:
  /api/pet/{petId}:
    $ref: "/paths/file.yaml"

file.yaml :

get:
  summary: Info for a specific pet
  operationId: getById
    parameters:
    - name: petId
      in: path
      required: true
      description: The id of the pet to retrieve
      schema:
        type: integer
    responses:
      200:
        description: Expected response to a valid request
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Pet'
components:
  schemas:
    Cat:
      required:
      - name
      - id
      type: object
      properties:
        id:
          type: integer
          readOnly: true
        name:
          type: string
    Pet:
      required:
      - id
      - name
      type: object
      properties:
        id:
          type: string
          format: uuid
        name:
          type: string
          minLength: 3
          maxLength: 20
        stringWithPattern:
          type: string
          pattern: '^\d{3}-\d{2}-\d{4}$'
        tagnullable:
          type: string
          nullable: true
        count:
          type: integer
          minimum: 23
          exclusiveMinimum: true
          maximum: 50
        multipleOfTenPointFive:
          type: number
          multipleOf: 10.5
        date:
          type: string
          format: date
        myBool:
          type: boolean
        cats:
          type: array
          items:
            $ref: '#/components/schemas/Cat'
          maxItems: 2
          uniqueItems: true
    Error:
      required:
      - code
      - message
      type: object
      properties:
        code:
          type: integer
          format: int32
        message:
          type: string

Steps to reproduce

  1. Create the Router from the OpenAPI3RouterFactory (from a YAML OpenAPI3 specification using path param and split yaml)

Thank you and don't hesitate if you need more information on that.

Guillaume.

componenapi-contracbug

All 4 comments

This is a bug of the parser. I raised an issue for it https://github.com/swagger-api/swagger-parser/issues/1014

Thank you @slinkydeveloper for the forwarding :)

This is not relevant anymore in Vert.x 4, since the new module vertx-web-openapi (that will replace vertx-web-api-contract) uses an internal parser that replaces swagger-parser. Porting your application to vert.x 4 and the new module vertx-web-openapi should solve the issue (look at the https://github.com/vert-x3/vertx-4-migration-guide/blob/master/asciidoc/openapi.adoc to learn more about it). Reopen if you need it

Thank you. I'll update soon to Vert.x 4 so I'll be able to give you feedback on that when done.

Was this page helpful?
0 / 5 - 0 ratings