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

Deprecate InlineModelResolver #10841

Merged
merged 3 commits into from
Jan 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -768,10 +768,6 @@ public List<File> generate() {
configureGeneratorProperties();
configureSwaggerInfo();

// resolve inline models
InlineModelResolver inlineModelResolver = new InlineModelResolver();
inlineModelResolver.flatten(swagger);

List<File> files = new ArrayList<File>();
// models
List<Object> allModels = new ArrayList<Object>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -433,8 +434,10 @@ public ClientOptInput toClientOptInput() {
.config(config);

final List<AuthorizationValue> authorizationValues = AuthParser.parse(auth);

Swagger swagger = new SwaggerParser().read(inputSpec, authorizationValues, true);
ParseOptions parseOptions = new ParseOptions();
parseOptions.setResolve(true);
parseOptions.setFlatten(true);
Swagger swagger = new SwaggerParser().read(inputSpec, authorizationValues, parseOptions);

input.opts(new ClientOpts())
.swagger(swagger);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand All @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -44,6 +45,9 @@ public class CodegenConfiguratorTest {
@Injectable
List<AuthorizationValue> authorizationValues;

@Mocked
ParseOptions options;

@Tested
CodegenConfigurator configurator;

Expand Down Expand Up @@ -351,11 +355,17 @@ private void setupStandardExpectations(final String spec, final String languageN

AuthParser.parse(auth); times=1; result = authorizationValues;

new ParseOptions();
times = 1;
result = options;
options.setResolve(true);
options.setFlatten(true);

new SwaggerParser();
times = 1;
result = parser;

parser.read(spec, authorizationValues, true);
parser.read(spec, authorizationValues, options);
times = 1;
result = swagger;

Expand Down