swagger-api / swagger-api/swagger-codegen

[java] incorrect generation of java Object

Open
#2,619 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Client: Java help wanted Issue: Bug
Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

version: 2.1.6

swagger specs:

"Attributes" : {
  "type" : "object"
},

instead of mapping it to java object, it create new class

package com.macomp;
import java.util.Objects;
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2016-04-14T08:31:30.310-07:00")
public class Attributes   {

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

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

  @Override
  public String toString() {
    StringBuilder sb = new StringBuilder();
   sb.append("class Attributes {\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(Object o) {
    if (o == null) {
      return "null";
    }
    return o.toString().replace("\n", "\n    ");
  }
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Java generation path for version 2.1.6 and reproduce the report using the supplied Swagger definition where Attributes has type object. Compare the generated Attributes class with the intended Java object mapping; done means the definition no longer produces the incorrect empty class.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.