Skip to content
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

[java] Incorrect code being generated with oneOf #912

Open
mukulb90 opened this issue Aug 27, 2018 · 1 comment
Open

[java] Incorrect code being generated with oneOf #912

mukulb90 opened this issue Aug 27, 2018 · 1 comment

Comments

@mukulb90
Copy link

mukulb90 commented Aug 27, 2018

Description

[JAVA] Incorrect code generation when subtypes are involved.

openapi-generator version

openapi-generator-cli-3.2.3

OpenAPI declaration file content or url
{
  "openapi": "3.0.1",
  "info": {
    "title": "Mukul",
    "version": "2.0"
  },
  "paths": {
    "/catalog/{id}": {
      "get": {
        "operationId": "getCatalogItem",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "default": {
            "description": "default response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CatalogEntity"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "CatalogEntity": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "entityType": {
            "type": "string"
          }
        },
        "discriminator": {
          "propertyName": "entityType",
          "mapping": {
            "folder": "#/components/schemas/Folder",
            "source": "#/components/schemas/Source"
          }
        },
        "oneOf": [
          {
            "$ref": "#/components/schemas/Folder"
          },
          {
            "$ref": "#/components/schemas/Source"
          }
        ]
      },
      "Folder": {
        "type": "object",
        "properties": {
          "path": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "tag": {
            "type": "string"
          },
          "children": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/CatalogItem"
            }
          }
        },
        "allOf": [
          {
            "$ref": "#/components/schemas/CatalogEntity"
          }
        ]
      },
      "Source": {
        "type": "object",
        "properties": {
          "tag": {
            "type": "string"
          },
          "type": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "description": {
            "type": "string"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "children": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/CatalogItem"
            }
          }
        },
        "allOf": [
          {
            "$ref": "#/components/schemas/CatalogEntity"
          }
        ]
      }
    }
  }
}
Command line used for generation

java -jar openapi-generator-cli-3.2.3-20180824.092221-7.jar generate -i openapi-apiresource.json -o ./gen -g java

Expectation: Generated classes Space and Source java should extend CatalogEntity and should have properties declared in the json.

Output: It generates classes Spaces and Source and they do extend CatalogEntity but all the props are missing.

For example:-

@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", date = "2018-08-27T11:13:31.931-07:00[America/Los_Angeles]")
public class Space extends CatalogEntity {

  @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(super.hashCode());
  }


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

}
@jmini jmini changed the title Incorrect code being generated [java] [java] Incorrect code being generated with oneOf Aug 28, 2018
@jmini
Copy link
Member

jmini commented Aug 28, 2018

Thank you for your report.oneOf is not supported yet. See #15.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants