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
21.5k stars 6.51k forks source link

[Java][jaxrs-resteasy] generated class without attribute #1050

Open tnmtechnologies opened 6 years ago

tnmtechnologies commented 6 years ago
Description

The yaml definitions are available in the OpenAPI declaration file content or url paragraph. The generated source code for the EpsBearerId type is the following one:

package org.openapitools.model;

import java.util.Objects;
import java.util.ArrayList;
import javax.validation.constraints.*;
import io.swagger.annotations.*;

@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaResteasyServerCodegen", date = "2018-09-17T10:07:39.336420400+02:00[Europe/Paris]")
public class EpsBearerId   {

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

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

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

The issue is that it holds no attribute.

openapi-generator version

3.2.3

OpenAPI declaration file content or url

Here are the following definitions that lead to the issue in the generated source code. In file TS29518_Namf_Communication.yaml we have the following definitions:

# line 139
/ue-contexts/{ueContextId}/assignEbi:
    post:
      summary: Namf_Communication EBI Assignment service Operation
      tags:
        - EBI Assignment
      operationId: EBIAssignment
      parameters:
        - name: ueContextId
          in: path
          description: UE Context Identifier
          required: true
          schema:
            type: string
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AssignEbi'
        required: true

# line 778
    AssignEbi:
      type: object
      properties:
        pduSessionId:
          $ref: './TS29571_CommonData.yaml#/components/schemas/PduSessionId'
        arps:
          type: array
          items:
            $ref: './TS29571_CommonData.yaml#/components/schemas/Arp'
          minItems: 1
        releasedEbiList:
          type: array
          items:
            $ref: '#/components/schemas/EpsBearerId'
          minItems: 0
      required:
        - pduSessionId

# line 1461
    EpsBearerId:
      $ref: './TS29571_CommonData.yaml#/components/schemas/Uinteger'

Uinteger is defined in file TS29571_CommonData.yaml

# line 61
    Uinteger:
      type: integer
      minimum: 0
Command line used for generation
java -jar ./openapi-generator-cli-3.2.3.jar generate -i TS29518_Namf_Communication.yaml -g jaxrs-resteasy -o generated-files
Steps to reproduce

Please unzip the attached file and type the command (see above) in the directory where files are stored. The generated files are stored in the generated-files directory. issue.zip

A copy of the generated source files is available under the generated-files.sav folder.

Related issues/PRs
Suggest a fix/enhancement
macjohnny commented 6 years ago

@tnmtechnologies I think your definition is wrong, you are defining a model EpsBearerId, which in turn simply is a primitive type integer it looks like it is possible to use primitives as a model, see https://swagger.io/specification/#schemaObject so this should be fixed. maybe @jmini has an idea how to fix it?

As a workaround, you could either define EpsBearerId as an object

EpsBearerId:
  type: object
  properties:
    id:
      $ref: './TS29571_CommonData.yaml#/components/schemas/Uinteger'

or use

    AssignEbi:
      type: object
      properties:
        ...
        releasedEbiList:
          type: array
          items:
            $ref: './TS29571_CommonData.yaml#/components/schemas/Uinteger'
          minItems: 0

@tnmtechnologies would you like to give it a try and provide a fix for this issue?

tnmtechnologies commented 6 years ago

@macjohnny thank you for your workaround proposal. The second one works. The first one adds an id attribute not required. The EpsBearerId definition is significant at the yaml level as some other ones too. They are business models.