OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
20.6k stars 6.29k forks source link

[BUG] [GROOVY] Enums are generated as empty classes #14420

Open mnisius opened 1 year ago

mnisius commented 1 year ago
Description

I'm trying to generate a groovy model from an openapi spec. Sadly enums are always generated es an empty class. If I use the java generator I get a correct enum with all the defined values inside. So my guess is there is a bug in the groovy generator.

My schema looks like this:

    GreetingType:
      type: string
      enum:
      - FRIENDLY
      - FORMAL

and the generated groovy code looks sadly like this:

@Canonical
class GreetingType {
}

I was expecting something like:

enum GreetingType {
  FRIENDLY, 
  FORMAL
}
openapi-generator version

6.2.1

OpenAPI declaration file content or url
openapi: 3.0.1
info:
  title: test-bas
  version: 1.0.0-SNAPSHOT
servers:
- url: http://localhost:8080/
  description: Generated server url
paths:
  /rest/greet/{name}:
    get:
      tags:
      - rest-service-app
      operationId: greet
      parameters:
      - name: name
        in: path
        required: true
        schema:
          type: string
      responses:
        "200":
          description: OK
          content:
            '*/*':
              schema:
                $ref: '#/components/schemas/Greeting'
components:
  schemas:
    Greeting:
      type: object
      properties:
        type:
          $ref: '#/components/schemas/GreetingType'
        text:
          type: string
    GreetingType:
      type: string
      enum:
      - FRIENDLY
      - FORMAL
Generation Details

I use the maven plugin. These are my settings:

         <plugin>
                <groupId>org.openapitools</groupId>
                <artifactId>openapi-generator-maven-plugin</artifactId>
                <version>6.2.1</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <inputSpec>${project.basedir}/resources/openapi.yml</inputSpec>
                            <generatorName>groovy</generatorName>
                            <generateApis>false</generateApis>
                            <generateSupportingFiles>false</generateSupportingFiles>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
Steps to reproduce

Use the groovy generator to generate models from an openapi spec with enums

Related issues/PRs

I could not find any...

Suggest a fix

Usable enums please 🙂

wing328 commented 1 year ago

@mnisius thanks for reporting the issue. May I know if you've time to contribute a fix?

I can show you some good starting points.

PM me via Slack (https://join.slack.com/t/openapi-generator/shared_invite/zt-12jxxd7p2-XUeQM~4pzsU9x~eGLQqX2g) to discuss further.