openapi-generator
openapi-generator copied to clipboard
[BUG] Wrong yaml generation when using `anyOf`
Bug Report Checklist
- [x] Have you provided a full/minimal spec to reproduce the issue?
- [x] Have you validated the input using an OpenAPI validator (example)?
- [x] Have you tested with the latest master to confirm the issue still exists?
- [x] 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
It better to add tag that will clarify that this issue is related to go generator and add [Go] to the name of the issue so it will be easier to find it, or filter it out.