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
  • #5238
Closed
Open
Issue created Feb 07, 2020 by Administrator@rootContributor5 of 6 checklist items completed5/6 checklist items

[BUG] java-inflector templates do not generate proper hashCode

Created by: Salexy

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?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
Description

JavaInflector/pojo.mustache generates hashCode whican can't be compiled if there are allOf and properties sections

openapi-generator version

org.openapitools:openapi-generator-gradle-plugin:4.2.3

OpenAPI declaration file content or url

Yaml file

openapi: 3.0.1
info:
  title: Test
  version: 1.0.0
servers:
  - url: https://aaa.dd.com
tags:
  - name: Test
    description: Test
paths:
  /test:
    get:
      tags:
        - Test
      summary: test
      parameters:
        - name: fff
          in: query
          description: ffff
          required: true
          allowEmptyValue: true
          schema:
            type: string
      responses:
        405:
          description: invalid
          content: {}
components:
  schemas:            
    Test2:
      description: Standard action object for all items
      required:
        - type
      properties:
        type:
          type: string
          description: this 
          $ref: '#/components/schemas/Test1'
 
    Image:
      description: Standard image object
      allOf:
        - $ref: '#/components/schemas/Test1'
        - type: object
      properties:
        actions:
          type: array
          items:
            $ref: '#/components/schemas/Test2'
    Test1:
      required:
        - cccc
      properties:
        cccc:
          description: test3
          type: string
Command line used for generation
task buildApiSdk(type: org.openapitools.generator.gradle.plugin.tasks.GenerateTask) {
    generatorName = "java"
    inputSpec = "$rootDir/app/yaml/swagger1.yaml"
    apiPackage = "test.api"
    invokerPackage = "test.invoker"
    modelPackage = "test.model"
    additionalProperties = [
            useRxJava2: "true"
    ]
    outputDir = "$rootDir/apitest".toString()
    configOptions = [
            "java8"         : "true",
            "dateLibrary" : "java8-localdatetime",
            "library"       : "retrofit2",
            "useGzipFeature": "true"
    ]
}
Steps to reproduce

after patch

public class Image extends Test1 {
  public static final String SERIALIZED_NAME_ACTIONS = "actions";
  @SerializedName(SERIALIZED_NAME_ACTIONS)
  private List<Test2> actions = null;


  public Image actions(List<Test2> actions) {
    
    this.actions = actions;
    return this;
  }

  public Image addActionsItem(Test2 actionsItem) {
    if (this.actions == null) {
      this.actions = new ArrayList<>();
    }
    this.actions.add(actionsItem);
    return this;
  }

   /**
   * Get actions
   * @return actions
  **/
  @javax.annotation.Nullable
  @ApiModelProperty(value = "")

  public List<Test2> getActions() {
    return actions;
  }


  public void setActions(List<Test2> actions) {
    this.actions = actions;
  }


  @Override
  public boolean equals(java.lang.Object o) {
    if (this == o) {
      return true;
    }
    if (o == null || getClass() != o.getClass()) {
      return false;
    }
    return super.equals(o);
  }

  @Override
  public int hashCode() {
    return Objects.hash(actionssuper.hashCode());
  }


  @Override
  public String toString() {
    StringBuilder sb = new StringBuilder();
    sb.append("class Image {\n");
    sb.append("    ").append(toIndentedString(super.toString())).append("\n");
    sb.append("    actions: ").append(toIndentedString(actions)).append("\n");
    sb.append("}");
    return sb.toString();
  }

  /**
   * Convert the given object to string with each line indented by 4 spaces
   * (except the first line).
   */
  private String toIndentedString(java.lang.Object o) {
    if (o == null) {
      return "null";
    }
    return o.toString().replace("\n", "\n    ");
  }

}

public int hashCode() { return Objects.hash(actionssuper.hashCode()); }

Should be

public int hashCode() { return Objects.hash(actions, super.hashCode()); }

Related issues/PRs
Suggest a fix
Assignee
Assign to
Time tracking