Skip to content

Commit c8acf90

Browse files
committed
swagger-codegen#4883: Expose skipInlineModelMatches flag in Maven plugin
1 parent c903ae1 commit c8acf90

File tree

3 files changed

+29
-6
lines changed

3 files changed

+29
-6
lines changed

modules/swagger-codegen-maven-plugin/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ mvn clean compile
6060
- `generateSupportingFiles` - generate the supporting files (`true` by default)
6161
- `supportingFilesToGenerate` - A comma separated list of supporting files to generate. All files is the default.
6262
- `skip` - skip code generation (`false` by default. Can also be set globally through the `codegen.skip` property)
63+
- `skipInlineModelMatches` - when processing inline models, generate unique classes for models with the same content (`false` by default, causes reusing)
6364

6465
### Custom Generator
6566

modules/swagger-codegen-maven-plugin/src/main/java/io/swagger/codegen/v3/maven/plugin/CodeGenMojo.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,12 @@ public class CodeGenMojo extends AbstractMojo {
288288
@Parameter(name = "skip", property = "codegen.skip", required = false, defaultValue = "false")
289289
private Boolean skip;
290290

291+
/**
292+
* Skip matches
293+
*/
294+
@Parameter(name = "skipInlineModelMatches", required = false)
295+
private Boolean skipInlineModelMatches = false;
296+
291297
/**
292298
* Add the output directory to the project as a source root, so that the generated java types
293299
* are compiled and included in the project artifact.
@@ -361,6 +367,8 @@ public void execute() throws MojoExecutionException {
361367

362368
configurator.setOutputDir(output.getAbsolutePath());
363369

370+
configurator.setSkipInlineModelMatches(skipInlineModelMatches);
371+
364372
if (isNotEmpty(auth)) {
365373
configurator.setAuth(auth);
366374
}

modules/swagger-codegen/src/main/java/io/swagger/codegen/v3/config/CodegenConfigurator.java

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ public class CodegenConfigurator implements Serializable {
5757
private boolean verbose;
5858
private boolean skipOverwrite;
5959
private boolean removeOperationIdPrefix;
60+
private boolean skipInlineModelMatches;
6061
private String templateDir;
6162
private String templateVersion;
6263
private String auth;
@@ -150,6 +151,15 @@ public CodegenConfigurator setRemoveOperationIdPrefix(boolean removeOperationIdP
150151
return this;
151152
}
152153

154+
public boolean getSkipInlineModelMatches() {
155+
return skipInlineModelMatches;
156+
}
157+
158+
public CodegenConfigurator setSkipInlineModelMatches(boolean skipInlineModelMatches) {
159+
this.skipInlineModelMatches = skipInlineModelMatches;
160+
return this;
161+
}
162+
153163
public String getModelNameSuffix() {
154164
return modelNameSuffix;
155165
}
@@ -462,9 +472,7 @@ public ClientOptInput toClientOptInput() {
462472

463473
if (!StringUtils.isBlank(inputSpec)) {
464474
config.setInputSpec(inputSpec);
465-
ParseOptions options = new ParseOptions();
466-
options.setResolve(true);
467-
options.setFlatten(true);
475+
ParseOptions options = buildParseOptions();
468476
SwaggerParseResult result = new OpenAPIParser().readContents(inputSpec, authorizationValues, options);
469477
OpenAPI openAPI = result.getOpenAPI();
470478

@@ -489,9 +497,7 @@ public ClientOptInput toClientOptInput() {
489497
}
490498
config.setInputSpec(specContent);
491499
config.setInputURL(inputSpecURL);
492-
ParseOptions options = new ParseOptions();
493-
options.setResolve(true);
494-
options.setFlatten(true);
500+
ParseOptions options = buildParseOptions();
495501
SwaggerParseResult result = new OpenAPIParser().readLocation(inputSpecURL, authorizationValues, options);
496502
OpenAPI openAPI = result.getOpenAPI();
497503
LOGGER.debug("getClientOptInput - parsed inputSpecURL " + inputSpecURL);
@@ -539,6 +545,14 @@ public ClientOptInput toClientOptInput() {
539545
return input;
540546
}
541547

548+
private ParseOptions buildParseOptions() {
549+
ParseOptions options = new ParseOptions();
550+
options.setResolve(true);
551+
options.setFlatten(true);
552+
options.setSkipMatches(this.skipInlineModelMatches);
553+
return options;
554+
}
555+
542556
@JsonAnySetter
543557
public CodegenConfigurator addDynamicProperty(String name, Object value) {
544558
dynamicProperties.put(name, value);

0 commit comments

Comments
 (0)