Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Openapi generator cannot generate query param with enum

I'm trying to generate a service that has enum as query parameter, but it keeps generating it wrong. Here's the part of yaml:

      name: language
      in: query
      description: language
      schema:
        type: string
        enum:
        - en
        - de

and I'm using it in parameters:

        - $ref: '#/components/parameters/language'

The error that I get is:

[ERROR] .../api/TestApi.java:[110,65] illegal start of type
[ERROR] .../api/TestApi.java:[110,66] ')' expected
[ERROR] .../api/TestApi.java:[110,82] ';' expected

Here's what the code looks like:

public Response getByLanguage( @PathParam("id") Long id, , allowableValues="en, de" @QueryParam("language") String language

And here's my plugin:

                <plugin>
                    <groupId>org.openapitools</groupId>
                    <artifactId>openapi-generator-maven-plugin</artifactId>
                    <version>5.0.1</version>
                    <configuration>
                        <inputSpec>${basedir}/src/main/resources/openapi.yaml</inputSpec>
                        <output>${project.build.directory}/generated-sources/java</output>
                        <generatorName>jaxrs-resteasy-eap</generatorName>
                        <modelPackage>com.openapi.example.model</modelPackage>
                        <apiPackage>com.openapi.example.api</apiPackage>
                        <generateSupportingFiles>false</generateSupportingFiles>
                        <configOptions>
                            <sourceFolder>openapi</sourceFolder>
                            <dateLibrary>java8</dateLibrary>
                            <interfaceOnly>true</interfaceOnly>
                            <java8>true</java8>
                            <serializableModel>true</serializableModel>
                            <useTags>true</useTags>
                            <performBeanValidation>true</performBeanValidation>
                            <useBeanValidation>true</useBeanValidation>
                        </configOptions>
                    </configuration>
                    <executions>
                        <execution>
                            <phase>generate-resources</phase>
                            <id>generate</id>
                            <goals>
                                <goal>generate</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>

The only way I've managed to get it to work is to make it as an array of enum values, but that's not what I need here.

EDIT: dependencies I have defined in the project:

        <dependency>
            <groupId>org.apache.maven.shared</groupId>
            <artifactId>maven-dependency-analyzer</artifactId>
            <version>1.11.1</version>
        </dependency>
        <dependency>
            <groupId>io.swagger</groupId>
            <artifactId>swagger-jaxrs</artifactId>
            <version>1.5.8</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>io.swagger.core.v3</groupId>
            <artifactId>swagger-annotations</artifactId>
            <version>2.1.5</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.datatype</groupId>
            <artifactId>jackson-datatype-jsr310</artifactId>
            <version>2.11.3</version>
        </dependency>
like image 373
StopTheRain Avatar asked Sep 08 '26 18:09

StopTheRain


2 Answers

This works for me:

...
paths:
...
        - name: semesterType
          in: query
          required: true
          schema:
            $ref: '#/components/schemas/SemesterType'
...
components:
  schemas:
    SemesterType:
      type: string
      enum:
        - SOMMERSEMESTER
        - WINTERSEMESTER
like image 95
Thorsten Hilker Avatar answered Sep 10 '26 07:09

Thorsten Hilker


Multiple long standing enum bugs exist in the generators (for all languages as far as I can tell).

For example https://github.com/OpenAPITools/openapi-generator/issues/4300

But also .. https://github.com/OpenAPITools/openapi-generator/issues/2645

like image 29
johnlon Avatar answered Sep 10 '26 07:09

johnlon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!