OpenAPITools / OpenAPITools/openapi-generator

[BUG] Description

Open
#19,814 3 comments 0 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)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

The problem is produced when trying to generate java source code with a string parameter type that includes an allOf -pattern structure.

In such case, a new type is created, which seems unusable.

In the example, the erroneous generated class is: Ipv6Addr.

The expected behevior was the attribute to be a String, as the ipv4Addr attribute

openapi-generator version

The openapi generator used is version 7.7

OpenAPI declaration file content or url

The open api yaml comes from 5g specifications.
A reduced yaml has been created to minimally reproduce the issue.

yaml content

Generation Details

the config.json file used for the generation is the following:

{
  "title": "5G Receiver API",
  "apiPackage": "com.nchf.rel16_15_0.openapi.api",
  "modelPackage": "com.nchf.rel16_15_0.openapi.model",
  "containerDefaultToNull": true,
  "openApiNullable": false,
  "generateBuilders": true,
  "generateConstructorWithAllArgs": true
}

openapi-generator-cli.jar is the v7.7 version openapi generation binary

The command line invocation sentence is the following:

java -jar ./openapi-generator-cli.jar generate \
            -i ./TS32291_Nchf_ConvergedCharging.lite.yaml \
            -g jaxrs-jersey \
            -o generated/. \
            -c ./config.json \
            --additional-properties hideGenerationTimestamp=false,browserClient=false \
            --verbose
Steps to reproduce

After having generated the java sources with the above instructions, we can see the class with the issue at file:

generated/src/gen/java/com/nchf/rel16_15_0/openapi/model/Ipv6Addr.java

Which is a class that has no attributes.

we can see that at the class at:

generated/src/gen/java/com/nchf/rel16_15_0/openapi/model/ChargingDataRequest.java

We have two attributes:

  public static final String JSON_PROPERTY_IPV4_ADDR = "ipv4Addr";
  @JsonProperty(JSON_PROPERTY_IPV4_ADDR)
  private String ipv4Addr;

That was a String, as expected

and the wrong one:

  public static final String JSON_PROPERTY_IPV6_ADDR = "ipv6Addr";
  @JsonProperty(JSON_PROPERTY_IPV6_ADDR)
  private Ipv6Addr ipv6Addr;

Which is of type: Ipv6Addr, the unusable one.

It was expected to be a String as ipv4Addr attribute

Related issues/PRs
Suggest a fix

The issue is probably produced by the fact that Ipv6Addr type has two patterns

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

Run the provided openapi-generator-cli command with the linked reduced YAML and config.json, then inspect generated/src/gen/java/com/nchf/rel16_15_0/openapi/model/Ipv6Addr.java and ChargingDataRequest.java. Compare the ipv6Addr output with ipv4Addr; done means the allOf-pattern string parameter is generated as String rather than an empty Ipv6Addr type.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi
Domain
api
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.