Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #1981
Closed
Open
Issue created Jan 25, 2019 by Administrator@rootContributor5 of 6 checklist items completed5/6 checklist items

[BUG][JavaSpring] Enum default value is only set if defined inline in schema

Created by: ajdergute

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What's the version of OpenAPI Generator used? (3.3.4)
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
Description

Depending if an enum is specified inline or not a the specified default value is assigned (or not). If defined inline (first case) a default value is assigned, as expected. If the enum is referenced via $ref, then 'null' is assigned, which should be changed.

openapi-generator version

As far as i know it's not a regression and I use OpenAPI Generator Version 3.2.3 and 3.3.4.

OpenAPI declaration file content or url

in both cases:

paths:
  /testenum:
    post:
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/TestObject'

works:

components:
  schemas:
    TestObject:
      type: object
      properties:
        myEnum:
          type: string
          default: FIRSTVALUE
          enum:
            - FIRSTVALUE
            - SECONDVALUE

and produces:

public class TestObjectDto {
  @JsonProperty("myEnum")
  private MyEnumEnum myEnum = MyEnumEnum.FIRSTVALUE;
}

doesn't work:

components:
  schemas:
    TestObject:
      type: object
      properties:
        myEnum:
          $ref: '#/components/schemas/MyEnum'
...
    MyEnum:
      type: string
      default: FIRSTVALUE
      enum:
      - FIRSTVALUE
      - SECONDVALUE

and produces:

public class TestObjectDto {
  @JsonProperty("myEnum")
  private MyEnumDto myEnum = null;
}
Command line used for generation

I used the maven generator plugin as follows:

            <plugin>
                <groupId>org.openapitools</groupId>
                <artifactId>openapi-generator-maven-plugin</artifactId>
                <version>3.3.4</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <phase>generate-sources</phase>
                        <configuration>
                            <inputSpec>src/main/resources/swagger/api.yaml</inputSpec>
                            <generatorName>spring</generatorName>
                            <invokerPackage>${project.groupId}.service</invokerPackage>
                            <apiPackage>${project.groupId}.service.api</apiPackage>
                            <modelPackage>${project.groupId}.service.model</modelPackage>
                            <modelNameSuffix>Dto</modelNameSuffix>
                            <configOptions>
                                <sourceFolder>src/main/java</sourceFolder>
                                <library>spring-boot</library>
                                <java8>true</java8>
                                <dateLibrary>java8</dateLibrary>
                                <useTags>true</useTags>
                                <interfaceOnly>true</interfaceOnly>
                                <delegatePattern>true</delegatePattern>
                                <swaggerDocketConfig>false</swaggerDocketConfig>
                                <configPackage>${project.groupId}.config</configPackage>
                            </configOptions>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
Steps to reproduce

Create an enum as described and see if default value is assigned.

Related issues/PRs
Suggest a fix

The expected behaviour in second case should be an default value assigment of the enum class like so: private MyEnumDto myEnum = MyEnumDto.FIRSTVALUE;

Assignee
Assign to
Time tracking