Skip to content

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

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

Closed
fabriziofortino opened this issue Jun 15, 2016 · 1 comment

Comments

@fabriziofortino
Copy link

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.

@wing328
Copy link
Contributor

wing328 commented Jul 19, 2016

@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
Projects
None yet
Development

No branches or pull requests

2 participants