-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Duplicate classes / Models are generated if ( $ref) referenced externally. #2701
Comments
👍 Thanks for opening this issue! The team will review the labels and make any necessary changes. |
Thanks for reporting this issue! I'll investigate this. 👀 |
(It's under investigation...)
Lines 605 to 606 in 9c7d407
|
I've reported the issue in swagger-parser (swagger-api/swagger-parser#1081) |
waiting for a feedback from swagger-parser team. |
Any update would be grateful. Thanks |
UPDATE: I've filed a PR to add a failing test case which reproduce the issue. |
Hi Any news about this issue? |
This may be related to this issue. In my case duplicate models are generated even without cyclic references. The generator version I'm using is the Dockerized 4.2.3-SNAPSHOT. I have the following layout:
You can see the reproducible example here: https://github.com/binaryunary/openapi-duplicate-models.
You can see it contains duplicate models like |
I was able to use a shared file in multiple specifications (which are merged into one later on) without duplicating a model. I think this is the same problem as what is posted here, except my situation has no cyclic deps in the files. Edit: This is with 4.2.3 in https://github.com/moov-io/go-client |
After playing around with external refs for a bit I discovered that swagger-parser will do some normalization on them, but it seems to happen lazily. If you have a ref like
then it will become
inside the parser after the first time this ref is resolved. Prefixing relative paths with |
Good news, the issue is resolved in the Swagger-Parser (swagger-api/swagger-parser#1081 (comment), swagger-api/swagger-parser#1292). We must only wait for the next release, to use it in the generator |
Any updates? |
I've been on 4.3.x without this issue. See how I did it above: #2701 (comment) |
@adamdecaf
Than I have two classes from main.yml file, that referenced in But if I change it to next scheme, everything okey.
will provide examples to reproduce latter Bytheway. Is there way to eliminate cycle dependency for classes with discriminators located in different files? |
What is referenced from |
We're using the latest versions of swagger-core, swagger-parser, and swagger-codegen: io.swagger.codegen.v3:swagger-codegen-cli:3.0.23 But we still have this problem. I'd happily preprocess our schema files if there's some way to munge them into a format that won't cause this. What would the munged format need to look like? |
When we fixed this locally in a fork, the fix looked like this:
That's not quite what the latest commit to ExternalRefProcessor in your github is doing. |
This may be the work-around for this case. |
I can see that the issue as been fixed in swagger-parser 2.0.19, and that the openapi-generation has updated the version used but this issue in present in both 5.0.1 and 5.1.0. Strangely, downgrading to either 5.0.0 or 4.3.1 fixes the issue for me. Any further updates of this? |
It is happening with the newest (5.1.1) version as well. Downgrading to 5.0.0 or 4.3.2 didn't help. Any updates of this? |
@wing328 any news on this? Thanks |
Having the same problem, is this going to be fixed? |
There are multiple problems related to external refs. I provided reproducible cases in swagger-api/swagger-parser#1518 |
Has been fixed in swagger-api/swagger-parser#1566, no duplicate classes are generated anymore when using version 2.0.26. |
Has it been tested with the reproducible cases in swagger-api/swagger-parser#1518 ? The history of this problem has been that a fix goes in for one symptom and that causes other symptoms to show up. It's never been completely addressed. |
any news? |
Is there a workaround for this issue? |
nnanda2016, see the workaround I posted above on Dec 7, 2020 (sorry about the weird formatting). |
This seems to be a very serious issue and a complete show-stopper for the generator. (just bumped into it and it seems there is no workaround either, unless you fork it and fix the error yourself) |
Bumping this. Same issue in typescript generator as well. |
Same problem here. Duplicated classes get generated once another yaml $ref another yaml's component. |
. |
any workaround for this? |
As a workaround, you may want to give https://github.com/apiture/api-ref-resolver a try to consolidate multiple OpenAPI spec files into a single one. |
#2701 (comment) |
Duplicate model classes even referring internal $ref. Any solution yet? |
Hi all, After this modification I was able to remove duplicity ;) |
What worked for us:
This seems to be an issue of generating duplicate classes due to the normalization of URLs and the resulting references being different. Would resolving the URLs into absolute paths not help in this case? |
Flattening was the first thing I tried. It didn't help in our case. |
Same issue here. This bug is annoying. |
Workaround that worked for me: I have "directory up" paths in my $ref in the OAS YAML like this: When generating server code with the openapi-generator, making use of the |
Thanks for the workaround! To anyone else who can't get it working at first: the trick is to find the correct internal name OpenAPI uses for your particular object that may not be the same as it appears in your programming language (in our case we had to use You can see the actual names in the log output when running the generator, or as the contents of And I have to say I would appreciate at least a warning from OpenAPI generator when I'm telling it to remap a type that then doesn't actually exist 😇 |
Description
If Schemas are referenced in cyclic manner, the Models are generated twice. In below code,the Model
ProblemDetails
is generated twice asProblemDetails.java
ProblemDetails2.java
Is the correct way to reference? If Not why? and How to fix the above case?
openapi-generator version
openapi-generator-cli-4.0.0-beta3
OpenAPI declaration file content or url
Command line used for generation
java -jar openapi-generator-cli-4.0.0-beta3.jar generate -i openapi.yaml -g spring -o ./temp
The text was updated successfully, but these errors were encountered: