Skip to content
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

Schema $ref with same name is not producing models properly #1089

Open
vinodchitrali opened this issue Apr 28, 2019 · 6 comments
Open

Schema $ref with same name is not producing models properly #1089

vinodchitrali opened this issue Apr 28, 2019 · 6 comments

Comments

@vinodchitrali
Copy link

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.


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

            //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 = tryName + "_" + i;
                    existingModel = schemas.get(tryName);
                    i++;
                }

Can some one help me to validate this code

@gracekarina
Copy link
Contributor

@vinodchitrali In other to check the code, can you please send us a failing PR so we can add a test to parser and try this out? Thanks!

@vinodchitrali
Copy link
Author

@gracekarina , I dont have failing PR.
@ackintosh added test case in openapi-generator ackintosh@102c704

@gracekarina
Copy link
Contributor

Hi @vinodchitrali please bring the test case here please, so I can review.

@ackintosh
Copy link
Contributor

@vinodchitrali Thank your for your mention about the test case I added.

I'll file a PR which add the test case so that it could be reviewed.

@ackintosh
Copy link
Contributor

@gracekarina I've added the test case #1097 .

@tomasz-zablocki
Copy link

Any progress on this one ?

Facing the same problem as well which basically forces a single-file-spec approach, which is quite problematic for large specs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants