OpenAPITools / OpenAPITools/openapi-generator
[BUG][java-vertx-web] Code generation issues with enum
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the supplied openapi-generator-cli 6.0.1 command with the Petstore YAML and the java-vertx-web generator. Inspect the generated PetsApiHandler.java parameter extraction and compare the enum handling with the expected PetType.valueOf(...getString()) form. Done means the generated project compiles without manually editing the handler.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100