From beb0391c7dc56f764321adef1f67df254feee1cc Mon Sep 17 00:00:00 2001 From: gracekarina Date: Wed, 30 Dec 2020 21:32:15 -0500 Subject: [PATCH 1/2] fixed unexpected invocation tests --- .../java/io/swagger/codegen/DefaultGenerator.java | 4 ---- .../java/io/swagger/codegen/InlineModelResolver.java | 9 +++++++++ .../swagger/codegen/config/CodegenConfigurator.java | 6 ++++-- .../java/io/swagger/codegen/DefaultGeneratorTest.java | 10 +++++++--- .../codegen/config/CodegenConfiguratorTest.java | 11 ++++++++++- 5 files changed, 30 insertions(+), 10 deletions(-) diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultGenerator.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultGenerator.java index 0283ba6096f..d26987aa419 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultGenerator.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultGenerator.java @@ -768,10 +768,6 @@ public List generate() { configureGeneratorProperties(); configureSwaggerInfo(); - // resolve inline models - InlineModelResolver inlineModelResolver = new InlineModelResolver(); - inlineModelResolver.flatten(swagger); - List files = new ArrayList(); // models List allModels = new ArrayList(); diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/InlineModelResolver.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/InlineModelResolver.java index 81917d2221b..5cac878003a 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/InlineModelResolver.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/InlineModelResolver.java @@ -14,6 +14,15 @@ import java.util.List; import java.util.Map; +/** + * @deprecated use instead the option flatten in SwaggerParser + */ +/* + * Use flatten option in Swagger parser like this: + * ParseOptions parseOptions = new ParseOptions(); + * parseOptions.setFlatten(true); + * Swagger swagger = new SwaggerParser().read(rootNode, new ArrayList<>(), parseOptions);*/ + public class InlineModelResolver { private Swagger swagger; private boolean skipMatches; diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/config/CodegenConfigurator.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/config/CodegenConfigurator.java index 0f01867c503..a4accc0929e 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/config/CodegenConfigurator.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/config/CodegenConfigurator.java @@ -12,6 +12,7 @@ import io.swagger.models.Swagger; import io.swagger.models.auth.AuthorizationValue; import io.swagger.parser.SwaggerParser; +import io.swagger.parser.util.ParseOptions; import io.swagger.util.Json; import org.apache.commons.lang3.Validate; import org.slf4j.Logger; @@ -433,8 +434,9 @@ public ClientOptInput toClientOptInput() { .config(config); final List authorizationValues = AuthParser.parse(auth); - - Swagger swagger = new SwaggerParser().read(inputSpec, authorizationValues, true); + ParseOptions parseOptions = new ParseOptions(); + parseOptions.setFlatten(true); + Swagger swagger = new SwaggerParser().read(inputSpec, authorizationValues, parseOptions); input.opts(new ClientOpts()) .swagger(swagger); diff --git a/modules/swagger-codegen/src/test/java/io/swagger/codegen/DefaultGeneratorTest.java b/modules/swagger-codegen/src/test/java/io/swagger/codegen/DefaultGeneratorTest.java index 9ef7b9d95ac..c4df4726b25 100644 --- a/modules/swagger-codegen/src/test/java/io/swagger/codegen/DefaultGeneratorTest.java +++ b/modules/swagger-codegen/src/test/java/io/swagger/codegen/DefaultGeneratorTest.java @@ -7,6 +7,7 @@ import io.swagger.models.Swagger; import io.swagger.models.Tag; import io.swagger.parser.SwaggerParser; +import io.swagger.parser.util.ParseOptions; import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.StringUtils; import org.junit.rules.TemporaryFolder; @@ -426,8 +427,10 @@ public void testIssue9132() throws Exception { @Test public void testIssue9725() throws Exception { final File output = folder.getRoot(); + ParseOptions parseOptions = new ParseOptions(); + parseOptions.setFlatten(true); - Swagger swagger = new SwaggerParser().read("src/test/resources/2_0/ticket-9725.json"); + Swagger swagger = new SwaggerParser().read("src/test/resources/2_0/ticket-9725.json",null, parseOptions); CodegenConfig codegenConfig = new SpringCodegen(); codegenConfig.setLibrary("spring-cloud"); codegenConfig.setOutputDir(output.getAbsolutePath()); @@ -444,8 +447,9 @@ public void testIssue9725() throws Exception { @Test public void testIssue9725Map() throws Exception { final File output = folder.getRoot(); - - Swagger swagger = new SwaggerParser().read("src/test/resources/2_0/ticket-9725-map.json"); + ParseOptions parseOptions = new ParseOptions(); + parseOptions.setFlatten(true); + Swagger swagger = new SwaggerParser().read("src/test/resources/2_0/ticket-9725-map.json",null, parseOptions); CodegenConfig codegenConfig = new SpringCodegen(); codegenConfig.setLibrary("spring-cloud"); codegenConfig.setOutputDir(output.getAbsolutePath()); diff --git a/modules/swagger-codegen/src/test/java/io/swagger/codegen/config/CodegenConfiguratorTest.java b/modules/swagger-codegen/src/test/java/io/swagger/codegen/config/CodegenConfiguratorTest.java index 5f5a3e644a3..ffca8f622df 100644 --- a/modules/swagger-codegen/src/test/java/io/swagger/codegen/config/CodegenConfiguratorTest.java +++ b/modules/swagger-codegen/src/test/java/io/swagger/codegen/config/CodegenConfiguratorTest.java @@ -9,6 +9,7 @@ import io.swagger.models.Swagger; import io.swagger.models.auth.AuthorizationValue; import io.swagger.parser.SwaggerParser; +import io.swagger.parser.util.ParseOptions; import mockit.Expectations; import mockit.FullVerifications; import mockit.Injectable; @@ -44,6 +45,9 @@ public class CodegenConfiguratorTest { @Injectable List authorizationValues; + @Mocked + ParseOptions options; + @Tested CodegenConfigurator configurator; @@ -351,11 +355,16 @@ private void setupStandardExpectations(final String spec, final String languageN AuthParser.parse(auth); times=1; result = authorizationValues; + new ParseOptions(); + times = 1; + result = options; + options.setFlatten(true); + new SwaggerParser(); times = 1; result = parser; - parser.read(spec, authorizationValues, true); + parser.read(spec, authorizationValues, options); times = 1; result = swagger; From 17afd977efcde7e56e2ae70b789e27ddd0132c93 Mon Sep 17 00:00:00 2001 From: gracekarina Date: Wed, 6 Jan 2021 15:28:54 -0500 Subject: [PATCH 2/2] fix relative ref tests, unexpected invocation tests --- .../main/java/io/swagger/codegen/config/CodegenConfigurator.java | 1 + .../java/io/swagger/codegen/config/CodegenConfiguratorTest.java | 1 + 2 files changed, 2 insertions(+) diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/config/CodegenConfigurator.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/config/CodegenConfigurator.java index a4accc0929e..e22833d0f00 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/config/CodegenConfigurator.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/config/CodegenConfigurator.java @@ -435,6 +435,7 @@ public ClientOptInput toClientOptInput() { final List authorizationValues = AuthParser.parse(auth); ParseOptions parseOptions = new ParseOptions(); + parseOptions.setResolve(true); parseOptions.setFlatten(true); Swagger swagger = new SwaggerParser().read(inputSpec, authorizationValues, parseOptions); diff --git a/modules/swagger-codegen/src/test/java/io/swagger/codegen/config/CodegenConfiguratorTest.java b/modules/swagger-codegen/src/test/java/io/swagger/codegen/config/CodegenConfiguratorTest.java index ffca8f622df..9e927f0f0ad 100644 --- a/modules/swagger-codegen/src/test/java/io/swagger/codegen/config/CodegenConfiguratorTest.java +++ b/modules/swagger-codegen/src/test/java/io/swagger/codegen/config/CodegenConfiguratorTest.java @@ -358,6 +358,7 @@ private void setupStandardExpectations(final String spec, final String languageN new ParseOptions(); times = 1; result = options; + options.setResolve(true); options.setFlatten(true); new SwaggerParser();