From 4c79270d8680c77f5b1b12229af3701f9519b359 Mon Sep 17 00:00:00 2001 From: "Ethan D. Twardy" Date: Wed, 8 Nov 2023 20:54:11 -0600 Subject: [PATCH] Implement a test for swagger-api/swagger-parser#1961 --- .../parser/test/ResolverCacheTestCircular.java | 16 ++++++++++++++++ .../src/test/resources/issue-1961/Bar.yaml | 13 +++++++++++++ .../src/test/resources/issue-1961/Foo.yaml | 17 +++++++++++++++++ 3 files changed, 46 insertions(+) create mode 100644 modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/test/ResolverCacheTestCircular.java create mode 100644 modules/swagger-parser-v3/src/test/resources/issue-1961/Bar.yaml create mode 100644 modules/swagger-parser-v3/src/test/resources/issue-1961/Foo.yaml diff --git a/modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/test/ResolverCacheTestCircular.java b/modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/test/ResolverCacheTestCircular.java new file mode 100644 index 0000000000..0a4c2a20c1 --- /dev/null +++ b/modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/test/ResolverCacheTestCircular.java @@ -0,0 +1,16 @@ +import io.swagger.v3.parser.OpenAPIV3Parser; +import io.swagger.v3.parser.core.models.ParseOptions; +import io.swagger.v3.parser.core.models.SwaggerParseResult; +import org.testng.annotations.Test; + +import static org.testng.Assert.assertFalse; + +public class ResolverCacheTestCircular { + @Test + public void testIssue1961_DuplicateSchemas_ABA() { + ParseOptions parseOptions = new ParseOptions(); + parseOptions.setResolve(true); + SwaggerParseResult result = new OpenAPIV3Parser().readLocation("src/test/resources/issue-1961/Foo.yaml", null, parseOptions); + assertFalse(result.getOpenAPI().getComponents().getSchemas().containsKey("TestCase_1")); + } +} \ No newline at end of file diff --git a/modules/swagger-parser-v3/src/test/resources/issue-1961/Bar.yaml b/modules/swagger-parser-v3/src/test/resources/issue-1961/Bar.yaml new file mode 100644 index 0000000000..8c84b60281 --- /dev/null +++ b/modules/swagger-parser-v3/src/test/resources/issue-1961/Bar.yaml @@ -0,0 +1,13 @@ +components: + schemas: + Bar: + anyOf: + - $ref: ./Foo.yaml#/components/schemas/FooBar + BarType: + enum: + - All + - OEM + type: string +info: + title: '#Issue1961.Bar' +openapi: 3.0.1 \ No newline at end of file diff --git a/modules/swagger-parser-v3/src/test/resources/issue-1961/Foo.yaml b/modules/swagger-parser-v3/src/test/resources/issue-1961/Foo.yaml new file mode 100644 index 0000000000..c283724fc6 --- /dev/null +++ b/modules/swagger-parser-v3/src/test/resources/issue-1961/Foo.yaml @@ -0,0 +1,17 @@ +components: + schemas: + FooBar: + properties: + BypassTypes: + items: + $ref: ./Bar.yaml#/components/schemas/BarType + type: array + type: object + Foo: + properties: + MFABypass: + $ref: ./Bar.yaml#/components/schemas/Bar + type: object +info: + title: '#Issue1961.Foo' +openapi: 3.0.1 \ No newline at end of file