Skip to content

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

Open

Description

@vinodchitrali

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

Activity

  1. gracekarina commented on May 5, 2019

    @gracekarina
    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!

  2. vinodchitrali commented on May 6, 2019

    @vinodchitrali
    Author

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

  3. gracekarina commented on May 6, 2019

    @gracekarina
    Contributor

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

  4. ackintosh commented on May 13, 2019

    @ackintosh
    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.

  5. ackintosh commented on May 13, 2019

    @ackintosh
    Contributor

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

  6. tomasz-zablocki commented on Aug 27, 2019

    @tomasz-zablocki

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions