diff --git a/modules/swagger-parser-v2-converter/src/main/java/io/swagger/v3/parser/converter/SwaggerConverter.java b/modules/swagger-parser-v2-converter/src/main/java/io/swagger/v3/parser/converter/SwaggerConverter.java index 652d93da2b..55cb33c6f6 100644 --- a/modules/swagger-parser-v2-converter/src/main/java/io/swagger/v3/parser/converter/SwaggerConverter.java +++ b/modules/swagger-parser-v2-converter/src/main/java/io/swagger/v3/parser/converter/SwaggerConverter.java @@ -33,6 +33,7 @@ import io.swagger.parser.util.SwaggerDeserializationResult; import io.swagger.v3.core.util.Json; import io.swagger.v3.core.util.PrimitiveType; +import io.swagger.v3.core.util.Yaml; import io.swagger.v3.oas.models.Components; import io.swagger.v3.oas.models.ExternalDocumentation; import io.swagger.v3.oas.models.OpenAPI; @@ -60,6 +61,7 @@ import io.swagger.v3.oas.models.security.SecurityScheme; import io.swagger.v3.oas.models.servers.Server; import io.swagger.v3.oas.models.tags.Tag; +import io.swagger.v3.parser.OpenAPIV3Parser; import io.swagger.v3.parser.core.extensions.SwaggerParserExtension; import io.swagger.v3.parser.core.models.AuthorizationValue; import io.swagger.v3.parser.core.models.ParseOptions; @@ -107,7 +109,23 @@ public SwaggerParseResult readContents(String swaggerAsString, List convert(List auths) { diff --git a/modules/swagger-parser/src/test/java/io/swagger/parser/OpenAPIParserTest.java b/modules/swagger-parser/src/test/java/io/swagger/parser/OpenAPIParserTest.java index cfd976d33c..ee5fc4e588 100644 --- a/modules/swagger-parser/src/test/java/io/swagger/parser/OpenAPIParserTest.java +++ b/modules/swagger-parser/src/test/java/io/swagger/parser/OpenAPIParserTest.java @@ -133,6 +133,48 @@ public void test30Url() { assertEquals(result.getOpenAPI().getOpenapi(), "3.0.1"); } + @Test + public void testConverterWithFlatten() { + String yaml = "swagger: \"2.0\"\n" + + "info:\n" + + " description: \"Foo\"\n" + + " version: \"1.0.0\"\n" + + "host: \"something.com\"\n" + + "basePath: \"/\"\n" + + "schemes:\n" + + " - \"https\"\n" + + "consumes:\n" + + " - \"application/json\"\n" + + "produces:\n" + + " - \"application/json\"\n" + + "paths:\n" + + " /example:\n" + + " get:\n" + + " responses:\n" + + " 200:\n" + + " description: \"OK\"\n" + + " schema:\n" + + " $ref: \"#/definitions/Foo\"\n" + + " parameters: []\n" + + "definitions:\n" + + " Foo:\n" + + " type: \"object\"\n" + + " required:\n" + + " properties:\n" + + " nested:\n" + + " type: \"object\"\n" + + " properties:\n" + + " color:\n" + + " type: \"string\""; + + ParseOptions options = new ParseOptions(); + options.setResolve(true); + options.setFlatten(true); + SwaggerParseResult result = new OpenAPIParser().readContents(yaml, null, options); + OpenAPI openAPI = result.getOpenAPI(); + assertEquals(openAPI.getComponents().getSchemas().size(), 2); + } + @Test public void test30() { String json =