OpenAPITools / OpenAPITools/openapi-generator

[BUG] Wrong yaml generation when using `anyOf`

Open
#12,972 1 comment 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

We use this 5g official swagger spec to generate our api https://raw.githubusercontent.com/jdegre/5GC_APIs/master/TS29522_TrafficInfluence.yaml

That spec has lots of references with enum.One of them is DnaiChangeType that can be found here https://jdegre.github.io/editor/?url=https://raw.githubusercontent.com/jdegre/5GC_APIs/master/TS29571_CommonData.yaml

That object looks like

    DnaiChangeType:
      anyOf:
      - type: string
        enum:
          - EARLY
          - EARLY_LATE
          - LATE
      - type: string
        description: >
          This string provides forward-compatibility with future
          extensions to the enumeration but is not used to encode
          content defined in the present version of this API. 

When running the following command

java  -jar openapi-generator-cli-7.0.0-20220719.043604-2.jar generate -i https://raw.githubusercontent.com/jdegre/5GC_APIs/master/TS29522_TrafficInfluence.yaml  -g go -o generated

it generates this:

    DnaiChangeType:
      anyOf:
      - $ref: '#/components/schemas/DnaiChangeType_anyOf'
      - description: "This string provides forward-compatibility with future extensions\
          \ to the enumeration but is not used to encode content defined in the present\
          \ version of this API. \n"
        type: string
      description: "Possible values are:\n- EARLY: Early notification of UP path reconfiguration.\n\
        - EARLY_LATE: Early and late notification of UP path reconfiguration. This\
        \ value shall only be present in the subscription to the DNAI change event.\n\
        - LATE: Late notification of UP path reconfiguration. \n"    

It looks like that object is not imported properly into the main api file (the one at api folder). In that case for some reason openapi-generator creates a new object called DnaiChangeType_anyOf.That seems to be confusing since it is generating a new object that didnt exist on the original

Not only that, but the top object DnaiChangeType on the golang autogenerated code does not reference to DnaiChangeType_anyOf, so the previous object is unusuable

openapi-generator version

openapi-generator-cli-7.0.0-20220719.043604-2

OpenAPI declaration file content or url
Generation Details
java  -jar openapi-generator-cli-7.0.0-20220719.043604-2.jar generate -i https://raw.githubusercontent.com/jdegre/5GC_APIs/master/TS29522_TrafficInfluence.yaml  -g go -o generated
Steps to reproduce

generate the file and check for those objects.

Also if you do gofmt -s -w . you will see other issues.

Related issues/PRs
Suggest a fix

support for any of and others modifiers

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 by running the reported Java CLI command against TS29522_TrafficInfluence.yaml and inspect the generated Go API files around DnaiChangeType and DnaiChangeType_anyOf. Compare the output with the DnaiChangeType definition in TS29571_CommonData.yaml and trace how anyOf schemas are handled. Done means the generated model preserves the anyOf relationship without introducing an unusable schema.

Written by the indexing model from the issue text.

Assessment

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