OpenAPITools / OpenAPITools/openapi-generator

[BUG][Java] Empty looking object is generated for anyOf type

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

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

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

While generating the TS29573_N32_Handshake.yaml to create java client, the java class SecurityCapability is generated with no relevant methods and it looks empty (there are no method to be able to passing values inside). However in yaml file the object is defined in the following way:

    SecurityCapability:
      anyOf:
        - type: string
          enum:
            - TLS
            - PRINS
        - type: string
openapi-generator version

5.0.0-SNAPSHOT

OpenAPI declaration file content or url

https://github.com/jdegre/5GC_APIs/blob/master/TS29573_N32_Handshake.yaml

Command line used for generation

Generated by openapi-generator-maven-plugin by using following options:

	<plugins>
            <plugin>
                <groupId>org.openapitools</groupId>
                <artifactId>openapi-generator-maven-plugin</artifactId>
                <version>5.0.0-SNAPSHOT</version>
                
                <configuration>
                    <generatorName>java</generatorName>
                    <output>${project.build.directory}/generated-sources</output>
                    <configOptions>
                    </configOptions>
               </configuration>
               
               <executions>
                   <execution>
                        <id>65</id>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>                      
                            <inputSpec>${project.basedir}/src/main/resources/TS29573_N32_Handshake.yaml</inputSpec>
                            <modelPackage>com.h21lab.TS29573_N32_Handshake.handler</modelPackage>
                            <apiPackage>com.h21lab.TS29573_N32_Handshake.model</apiPackage>
                            <invokerPackage>com.h21lab.TS29573_N32_Handshake.handler</invokerPackage>
                        </configuration>
                    </execution>
           	</executions>
            </plugin>
    	<plugins>
Steps to reproduce

Generator will produce the following class with no relevant methods or variables:

/*
 * N32 Handshake API
 * N32-c Handshake Service.  © 2020, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TSDSI, TTA, TTC).  All rights reserved. 
 *
 * The version of the OpenAPI document: 1.1.0.alpha-3
 * 
 *
 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
 * https://openapi-generator.tech
 * Do not edit the class manually.
 */


package com.h21lab.TS29573_N32_Handshake.handler;

import java.util.Objects;
import java.util.Arrays;

/**
 * SecurityCapability
 */
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", date = "2020-05-29T11:08:32.406367+02:00[Europe/Vienna]")
public class SecurityCapability {

  @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 SecurityCapability {\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    ");
  }

}


Related issues/PRs
Suggest a fix

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 TS29573_N32_Handshake.yaml and reproduce generation through the openapi-generator-maven-plugin using the Java generator. Inspect how the anyOf definition for SecurityCapability is turned into the generated Java class, especially the empty output shown in the issue. Done means the generated class represents the anyOf string values and provides a way to pass values into it.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi
Domain
backend-api-design, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.