Skip to content

[JAVA] Error generating models using array of enums in parent definition  #3147

Closed

Description

@fabriziofortino
Description

When a parent definition contains an array of enums the generated models don't compile.

Swagger-codegen version

Latest version from master.

Swagger declaration file content or url
    swagger: '2.0'
    info:
      description: 'My Service'
      version: 1.0.0
      title: My Service
    schemes:
      - http
    paths:
      /templates:
        get:
          summary: Returns all
          description: ''
          operationId: getAll
          produces:
            - application/json
          responses:
            '200':
              description: successful operation
              schema:
                type: array
                items:
                  $ref: '#/definitions/Parent'
    definitions:
      Parent:
        discriminator: id
        properties:
          id:
            type: string
          status:
            type: array
            items:
              type: string
              enum:
                - active
                - inactive
                - pending
        required:
          - id
      Child:
        allOf:
          - $ref: "#/definitions/Parent"
          - type: object
            properties:
              subProperty:
                type: string
Command line used for generation
java -Dmodels -Dapis -DsupportingFiles=pom.xml,README.md,build.gradle,settings.gradle,gradle.properties,AndroidManifest.xml -jar /home/third-parties/swagger-codegen/modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate -l java -o java 
Steps to reproduce

Generate the model.
Compile with gradle compileJava.

Here is the compilation error I get.

Child.java:65: error: name clash: status(List<Child.StatusEnum>) in Child and status(List<Parent.StatusEnum>) in Parent have the same erasure, yet neither overrides the other
  public Child status(List<StatusEnum> status) {
               ^
Child.java:72: error: getStatus() in Child cannot override getStatus() in Parent
  public List<StatusEnum> getStatus() {
                          ^
  return type List<Child.StatusEnum> is not compatible with List<Parent.StatusEnum>
Child.java:75: error: name clash: setStatus(List<Child.StatusEnum>) in Child and setStatus(List<Parent.StatusEnum>) in Parent have the same erasure, yet neither overrides the other
  public void setStatus(List<StatusEnum> status) {
              ^
3 errors
:compileJava FAILED
Suggest a Fix

IMHO subclasses should not redefine inherited properties, getters and setters.

Activity

  1. added this to the v2.2.0 milestone on Jun 22, 2016
  2. modified the milestones: v2.2.0, v2.3.0 on Jul 7, 2016
  3. wing328 commented on Jul 19, 2016

    @wing328
    Contributor

    @cbornet PR (#3393) has been merged into master. Please pull the latest to give it a try.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions