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 :
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).
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
Thank you and don't hesitate if you need more information on that.
Guillaume.
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.