OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
20.74k stars 6.32k forks source link

[BUG] Java Generation of empty object #2182

Open laurent-thiebaud-gisaia opened 5 years ago

laurent-thiebaud-gisaia commented 5 years ago

Bug Report Checklist

Description
openapi-generator version
OpenAPI declaration file content or url
Command line used for generation
Steps to reproduce
Related issues/PRs
Suggest a fix
laurent-thiebaud-gisaia commented 5 years ago

In a OAS V3 schema, having the Component:

Input:
      description: |
        Process execution input payload (compliant with process.input json
        schema).
      type: object
      format: application/json

With the Maven configuration:

<plugin>
        <groupId>org.openapitools</groupId>
        <artifactId>openapi-generator-maven-plugin</artifactId>
        <version>3.3.4</version>
        <executions>
          <execution>
            <goals>
              <goal>generate</goal>
            </goals>
            <configuration>
              <inputSpec>commons/src/main/resources/oasv3.yaml</inputSpec>
              <generatorName>spring</generatorName>
              <configOptions>
                <basePackage>com.my.project</basePackage>
                <apiPackage> com.my.project.api</apiPackage>
                <modelPackage> com.my.project.model.api</modelPackage>
                <configPackage> com.my.project.api.config</configPackage>
                <java8>true</java8>
                <interfaceOnly>true</interfaceOnly>
              </configOptions>
            </configuration>
          </execution>
        </executions>
      </plugin>

The generated class is:

public class Input   {

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

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

  @Override
  public String toString() {
    StringBuilder sb = new StringBuilder();
    sb.append("class Input {\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    ");
  }
}

It has no property to get the content of the object, even the toString is wrong. With swagger-codegen-maven-plugin, it used to generate no class related to Input, this was just a simple object.

If I change the component to:

Input:
      description: |
        Process execution input payload (compliant with process.input json
        schema).
      type: object
      format: application/json
      required:
        - input
      properties:
        input:
          description: The content
          type: object

Then the generated object has indeed an inner object:

public class Input   {
  @JsonProperty("input")
  private Object input = null;

  public Input input(Object input) {
    this.input = input;
    return this;
  }

But we don't want a property to manager the object.

With openapi-generator-maven-plugin we should have least have a way to get the content of the Input object.

andriewski commented 7 months ago

Any news reguarding the issue? :)