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

Component schemas with same name are ignored after the second one #1501

Closed
BabisK opened this issue Dec 2, 2020 · 0 comments · Fixed by #1502
Closed

Component schemas with same name are ignored after the second one #1501

BabisK opened this issue Dec 2, 2020 · 0 comments · Fixed by #1502

Comments

@BabisK
Copy link
Contributor

BabisK commented Dec 2, 2020

When several referenced schemas have the same name but different definitions, only the first two are created in components/schemas, the rest are ignored.

base.yaml

openapi: 3.0.0
paths:
  /endpoint:
    post:
      summary: test summary
      description: test desc
      requestBody:
        required: true
        content:
          application/json:
            schema:
              oneOf:
                - $ref: 'config.yaml#/POST.type1/body'
                - $ref: 'config.yaml#/POST.type2/body'
                - $ref: 'config.yaml#/POST.type3/body'
                - $ref: 'config.yaml#/POST.type4/body'
      responses:
        '200':
          description: OK

config.yaml

POST.type1:
  body:
    type: object
    additionalProperties: false
    properties:
      prop1:
        description: prop1
        type: boolean
POST.type2:
  body:
    type: object
    additionalProperties: false
    properties:
      prop2:
        description: prop2
        type: boolean
POST.type3:
  body:
    type: object
    additionalProperties: false
    properties:
      prop3:
        description: prop3
        type: boolean
POST.type4:
  body:
    type: object
    additionalProperties: false
    properties:
      prop3:
        description: prop3
        type: boolean

main.java

import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.parser.core.models.ParseOptions;

public class Main {

    public static void main(String[] args) {
        ParseOptions options = new ParseOptions();
        options.setResolve(true);
        OpenAPI openAPI = new OpenAPIV3Parser().read("base.yaml", null, options);
        System.out.println(openAPI.getComponents().getSchemas().keySet());
    }
}

Result

[body, body_2]

Expected result

[body, body_1, body_2]

Note: In this case 3 schemas are expected since POST.type3.body and POST.type4.body have the same definition.

BabisK added a commit to BabisK/swagger-parser that referenced this issue Dec 2, 2020
BabisK added a commit to BabisK/swagger-parser that referenced this issue Dec 2, 2020
BabisK added a commit to BabisK/swagger-parser that referenced this issue Dec 3, 2020
gracekarina added a commit that referenced this issue Dec 3, 2020
…lculation-fixed

Fix issue #1501: External schema name is correctly constructed
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

Successfully merging a pull request may close this issue.

1 participant