[BUG][java-vertx-web] Code generation issues with enum
Description
Found this issue with the java-vertx-web code generator. I've seen this in 5.1.1 and also in latest 6.0.1. Code generation issue when enum is used in a parameter. For example:
...
paths:
/pets:
get:
summary: List all pets
operationId: ListPets
tags:
- pets
parameters:
- name: type
$ref: '#/components/parameters/PetType'
...
components:
schemas:
PetType:
maxLength: 20
type: string
enum:
- CAT
- DOG
- BIRD
description: Type of pet
parameters:
PetType:
name: petType
in: query
required: false
schema:
$ref: '#/components/schemas/PetType'
Code generated is as follows:
private void listPets(RoutingContext routingContext) {
logger.info("listPets()");
// Param extraction
..
PetType petType = requestParameters.queryParameter("petType") != null ? requestParameters.queryParameter("petType").getPetType() : null;
...
}
Notice how the .getPetType() is generated incorrectly. Java compiler error is:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project openapi-java-vertx-web-server: Compilation failure
[ERROR] /C:/ADF/ws/expt/epl-1/generated/build/petstore/src/main/java/com/petstore/verticle/PetsApiHandler.java:[68,124] cannot find symbol
[ERROR] symbol: method getPetType()
[ERROR] location: interface io.vertx.ext.web.validation.RequestParameter
This code needs manual fixing to following to compile:
PetType petType = requestParameters.queryParameter("petType") != null ? PetType.valueOf(requestParameters.queryParameter("petType").getString()) : null;
openapi-generator version
5.1.1 to 6.0.1
OpenAPI declaration file content or url
$ java -ea -Xms1G -Xmx1G -server -jar openapi-generator-cli-6.0.1.jar generate -i petstore.yaml --model-package com.petstore.model --api-package com.petstore.verticle -g java-vertx-web -o java-vertx-web-petstore-1
We also see a similar issue when we use date-time in parameters
parameters:
- name: fromDate
in: query
required: false
schema:
type: string
format: date-time
Generated code is:
OffsetDateTime fromDate = requestParameters.queryParameter("fromDate") != null ? requestParameters.queryParameter("fromDate").getOffsetDateTime() : null;
Where as it should be:
OffsetDateTime fromDate = requestParameters.queryParameter("fromDate") != null ? OffsetDateTime.parse(requestParameters.queryParameter("fromDate").getString()) : null;
I thought I'll include this here along with this case, instead of a new one. Looks like this may be a general problem with how some data types are handled in request parameter query extraction in the generated code.
If operationId is listPets, i.e. specified in camelCase, we don't run into this problem, but if it is in CapitalCase, like ListPets, then we have this issue.