You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG] Schema $ref with same name is not producing models properly #2729
My schema definition are spread across multiple files and they are cross reference(using $ref). In these files there is one schema with same name. I have 5 such instances
When i run code generator, Only 2 models are produced. Rest are ignored. Some of the $ref are pointing to wrong model.
changed the title [-][BUG] Schema $ref with same name is not is not producing models properly[/-][+][BUG] Schema $ref with same name is not producing models properly[/+]on Apr 24, 2019
Well, I can, but i have 1000+ such instances. Its tedious job.
Also, I get these schema from different sources. I combined in my custom schema by adding external ref($ref: http:///schemas/v1/.yaml.
@vinodchitrali, just note that openapi-generator is using its own branch/fork and not the one from swagger-api account. they are not always in sync.
Seems to already exist some opened issues related to schema collision there.
I've faced a similar problem of yours. And as I was without time I've used speccy to merge external models into one model.
//We add a number at the end of the definition name
int i = 2;
for (String name : schemas.keySet()) {
if (name.equals(possiblyConflictingDefinitionName)) {
tryName = possiblyConflictingDefinitionName + "_" + i;
existingModel = schemas.get(tryName);
i++;
}
In above code, possiblyConflictingDefinitionName remains same through out the loop. If possiblyConflictingDefinitionName = "model" then the outcome of the loop is always tryName = "model_2".
I am hitting same issue.
So above code should be
//We add a number at the end of the definition name
int i = 2;
tryName = possiblyConflictingDefinitionName;
for (String name : schemas.keySet()) {
if (name.equals(tryName)) {
tryName = possiblyConflictingDefinitionName+ "_" + i;
existingModel = schemas.get(tryName);
i++;
}
Can some one help me to validate this code ? Also help to build org.openapitools.swagger.parser(2.0.11-OpenAPITools.org-1)
@jmini , I see that u have done recent pom update for 2.0.11. Can check above code and help to build swagger parser for OpenAPI tools
@vinodchitrali , do you know how Git and Maven works ? without that knowledge it will be a kind complicated for you...
Btw, you just need to clone the swagger-parser repository and do a mvn clean install.
Then clone the openapi-generator repository and change its main pom properties to work with the version that you wanted to use:
If you produce a patch for Swagger-Parser (including the test case proposed by @ackintosh (if he agree) -- maybe you can adapt it), please file a PR to fix it.
@vinodchitrali, this is because the upstream team has not applied the PR provided by openapi-generator's team branch and vice-versa.
What I did was to create my own local branch and I'm trying to keep the commits from upstream and openapi-generator in synch... at least I was able to workaround my problems for now.
@jmini , I know and you are doing a great job!.
But the specific fix for this issue related to $ref was only released on version 2.0.12.
I could see that the latest released version of your branch is based on version 2.0.11, though...
This custom 2.0.13-OpenAPITools.org-1 release of Swagger-Parser is: io.swagger.parser.v3:swagger-parser:2.0.12 + 3 additional fixes (see the release notes).
swagger-api/swagger-parser#1089 seems still to be open, you need to provide a patch there. For the moment the PR in the issue there only references a test case and no fix.
Activity
auto-labeler commentedon Apr 24, 2019
👍 Thanks for opening this issue!
🏷 I have applied any labels matching special text in your issue.
The team will review the labels and make any necessary changes.
[-][BUG] Schema $ref with same name is not is not producing models properly[/-][+][BUG] Schema $ref with same name is not producing models properly[/+]cvgaviao commentedon Apr 24, 2019
Wouldn't be better just to change those names to avoid duplication ?
vinodchitrali commentedon Apr 24, 2019
@cvgaviao , thanks for look into the issue
Well, I can, but i have 1000+ such instances. Its tedious job.
Also, I get these schema from different sources. I combined in my custom schema by adding external ref($ref: http:///schemas/v1/.yaml.
Any change in the external schema is nightmare.
vinodchitrali commentedon Apr 24, 2019
I was debugging the issue, i figured out that the issue is https://github.com/swagger-api/swagger-parser
Possibly
https://github.com/swagger-api/swagger-parser/blob/master/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/processors/SchemaProcessor.java
The schema duplication is limited to
2.cvgaviao commentedon Apr 24, 2019
@vinodchitrali, just note that openapi-generator is using its own branch/fork and not the one from swagger-api account. they are not always in sync.
Seems to already exist some opened issues related to schema collision there.
I've faced a similar problem of yours. And as I was without time I've used speccy to merge external models into one model.
vinodchitrali commentedon Apr 24, 2019
Thanks @cvgaviao, Any possible fix available ?
vinodchitrali commentedon Apr 27, 2019
I see some issue in the following code.
https://github.com/swagger-api/swagger-parser/blob/master/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/processors/ExternalRefProcessor.java#L87
In above code,
possiblyConflictingDefinitionNameremains same through out the loop. IfpossiblyConflictingDefinitionName = "model"then the outcome of the loop is alwaystryName = "model_2".I am hitting same issue.
So above code should be
Can some one help me to validate this code ? Also help to build
org.openapitools.swagger.parser(2.0.11-OpenAPITools.org-1)@jmini , I see that u have done recent pom update for 2.0.11. Can check above code and help to build swagger parser for OpenAPI tools
vinodchitrali commentedon Apr 28, 2019
[email protected] help me build swagger parser
vinodchitrali commentedon Apr 29, 2019
@wing328 @jimschubert @cbornet @ackintosh , can some one help to build swagger parser for generator ?
Add test case to reproduce the issue OpenAPITools/openapi-generator#2729
vinodchitrali commentedon Apr 30, 2019
@ackintosh , Thanks for adding test case.
Can you help me to build locally swagger-parser for Openapi generator
cvgaviao commentedon Apr 30, 2019
@vinodchitrali , do you know how Git and Maven works ? without that knowledge it will be a kind complicated for you...
Btw, you just need to clone the swagger-parser repository and do a
mvn clean install.Then clone the openapi-generator repository and change its main pom properties to work with the version that you wanted to use:
In order to build openapi-generator with a snapshot version you need to use this:
jmini commentedon Apr 30, 2019
@vinodchitrali: can you please file an issue in the upstream project:
https://github.com/swagger-api/swagger-parser/issues
If you produce a patch for Swagger-Parser (including the test case proposed by @ackintosh (if he agree) -- maybe you can adapt it), please file a PR to fix it.
vinodchitrali commentedon Apr 30, 2019
@jmini , I have already filed issue.
swagger-api/swagger-parser#1089
vinodchitrali commentedon Apr 30, 2019
@cvgaviao , i am able to build from upstream clone. only thing it is breaking lots of test cases, also getting some exception while building
cvgaviao commentedon Apr 30, 2019
@vinodchitrali, this is because the upstream team has not applied the PR provided by openapi-generator's team branch and vice-versa.
What I did was to create my own local branch and I'm trying to keep the commits from upstream and openapi-generator in synch... at least I was able to workaround my problems for now.
jmini commentedon Apr 30, 2019
@cvgaviao in the swagger-parser fork we maintain on branch
2.0-OpenAPIToolsin https://github.com/OpenAPITools/swagger-parser/, we are almost in sync with themasterbranch of https://github.com/swagger-api/swagger-parserWe have one addition to convert a Swagger-v2 Operation name to an OpenAPI-v3 vendor extension
x-codegen-request-body-name.cvgaviao commentedon Apr 30, 2019
@jmini , I know and you are doing a great job!.
But the specific fix for this issue related to $ref was only released on version 2.0.12.
I could see that the latest released version of your branch is based on version 2.0.11, though...
jmini commentedon May 1, 2019
I have prepared PR #2775 to update Swagger-Parser
jmini commentedon May 7, 2019
I have updated Swagger-Parser.
Can you check the latest
4.0.0-SNAPSHOTversion of OpenAPI Generator?vinodchitrali commentedon May 7, 2019
@jmini is it up streamed ?
jmini commentedon May 7, 2019
@vinodchitrali: sorry I do not get your question.
If you now use a recent
4.0.0-SNAPSHOTversion of "OpenAPI-Generator", this version now rely onorg.openapitools.swagger.parser:swagger-parser:2.0.13-OpenAPITools.org-1instead oforg.openapitools.swagger.parser:swagger-parser:2.0.11-OpenAPITools.org-1as it was previously the case.This custom
2.0.13-OpenAPITools.org-1release of Swagger-Parser is:io.swagger.parser.v3:swagger-parser:2.0.12+ 3 additional fixes (see the release notes).jmini commentedon Aug 24, 2019
swagger-api/swagger-parser#1089 seems still to be open, you need to provide a patch there. For the moment the PR in the issue there only references a test case and no fix.