Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Java] An array of enums is not generated correctly #12352

Open
Tamarpe opened this issue Mar 7, 2024 · 0 comments
Open

[Java] An array of enums is not generated correctly #12352

Tamarpe opened this issue Mar 7, 2024 · 0 comments

Comments

@Tamarpe
Copy link

Tamarpe commented Mar 7, 2024

Description

When the YAML file contains a field with an array of enums, the API Java code generates the field as a single-option select list instead of a multi-select list.

It appears as:

image

Instead of:
image

Swagger-codegen version

swagger-codegen-maven-plugin 3.0.54

Swagger declaration file content or url
        - name: testfield
          in: query
          required: false
          schema:
            type: array
            items:
              type: integer
              enum:
                - '0'
                - '1'
                - '2'
                - '3'
                - '4'
Command line used for generation

mvn clean install

Steps to reproduce

Maven:

               <plugin>
                    <groupId>io.swagger.codegen.v3</groupId>
                    <artifactId>swagger-codegen-maven-plugin</artifactId>
                    <version>${swagger-codegen-plugin.version}</version>
                    <executions>
                        <execution>
                            <id>java-model-generation</id>
                            <phase>generate-sources</phase>
                            <goals>
                                <goal>generate</goal>
                            </goals>
                            <configuration>
                                <language>spring</language>
                                <library>spring-cloud</library>
                                <generateApis>true</generateApis>
                                <generateModels>true</generateModels>
                                <generateSupportingFiles>true</generateSupportingFiles>
                                <inputSpec>${project.basedir}/src/main/resources/${openapi.file.name}</inputSpec>
                                <output>${project.build.directory}/generated-sources/swagger</output>
                                <modelPackage>${openapi.model.package}</modelPackage>
                                <apiPackage>${openapi.client.package}</apiPackage>
                                <invokerPackage>${openapi.invoker.package}</invokerPackage>
                            <configOptions>
                                <java8>false</java8>
                                <jdk8>false</jdk8>
                                <defaultInterfaces>false</defaultInterfaces>
                                <interfaceOnly>true</interfaceOnly>
                                <dateLibrary>java8</dateLibrary>
                                <useTags>true</useTags>
                                <defaultInterfaces>false</defaultInterfaces>
                                <jakarta>true</jakarta>
                                <notNullJacksonAnnotation>true</notNullJacksonAnnotation>
                            </configOptions>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>

Suggest a fix/enhancement

When generating an array of enums, the parameter should be annotated with "@ArraySchema" instead of "@Schema". Now it is being generated as:

@parameter(schema=@Schema(allowableValues={ "0", "1", "2", "3", "4" }))
@Valid @RequestParam(value = "testfield", required = false) List testfield

Instead of:
@parameter(array = @ArraySchema(schema = @Schema(allowableValues = {"0", "1", "2", "3", "4"})))
@Valid @RequestParam(value = "testfield", required = false) List testfield

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant