Skip to content

Commit 1de79da

Browse files
authored
Merge pull request #9672 from hlyakhovich/issue-4883
swagger-codegen#4883: Expose skipInlineModelMatches flag in Maven plugin
2 parents 4df553e + e9e35bc commit 1de79da

File tree

3 files changed

+36
-10
lines changed

3 files changed

+36
-10
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.
@@ -368,6 +374,8 @@ protected void execute_() throws MojoExecutionException {
368374

369375
configurator.setOutputDir(output.getAbsolutePath());
370376

377+
configurator.setSkipInlineModelMatches(skipInlineModelMatches);
378+
371379
if (isNotEmpty(auth)) {
372380
configurator.setAuth(auth);
373381
}

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

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ public class CodegenConfigurator implements Serializable {
6161
private boolean verbose;
6262
private boolean skipOverwrite;
6363
private boolean removeOperationIdPrefix;
64+
private boolean skipInlineModelMatches;
6465
private String templateDir;
6566
private String templateVersion;
6667
private String auth;
@@ -175,6 +176,15 @@ public CodegenConfigurator setRemoveOperationIdPrefix(boolean removeOperationIdP
175176
return this;
176177
}
177178

179+
public boolean getSkipInlineModelMatches() {
180+
return skipInlineModelMatches;
181+
}
182+
183+
public CodegenConfigurator setSkipInlineModelMatches(boolean skipInlineModelMatches) {
184+
this.skipInlineModelMatches = skipInlineModelMatches;
185+
return this;
186+
}
187+
178188
public String getModelNameSuffix() {
179189
return modelNameSuffix;
180190
}
@@ -561,11 +571,10 @@ public ClientOptInput toClientOptInput() {
561571

562572
if (!StringUtils.isBlank(inputSpec)) {
563573
config.setInputSpec(inputSpec);
564-
ParseOptions options = new ParseOptions();
565-
options.setResolve(true);
566-
options.setResolveFully(resolveFully);
567-
options.setFlatten(true);
568-
options.setFlattenComposedSchemas(flattenInlineSchema);
574+
575+
ParseOptions options = buildParseOptions();
576+
577+
569578
SwaggerParseResult result = new OpenAPIParser().readContents(inputSpec, authorizationValues, options);
570579
OpenAPI openAPI = result.getOpenAPI();
571580
if (config.needsUnflattenedSpec()) {
@@ -597,13 +606,11 @@ public ClientOptInput toClientOptInput() {
597606
throw new IllegalArgumentException(msg);
598607
}
599608
config.setInputSpec(specContent);
609+
600610
config.setInputURL(sanitizedSpecificationUrl);
601-
ParseOptions options = new ParseOptions();
602-
options.setResolve(true);
603-
options.setResolveFully(resolveFully);
604-
options.setFlatten(true);
605-
options.setFlattenComposedSchemas(flattenInlineSchema);
611+
ParseOptions options = buildParseOptions();
606612
SwaggerParseResult result = new OpenAPIParser().readLocation(sanitizedSpecificationUrl, authorizationValues, options);
613+
607614
OpenAPI openAPI = result.getOpenAPI();
608615
LOGGER.debug("getClientOptInput - parsed inputSpecURL " + sanitizedSpecificationUrl);
609616
input.opts(new ClientOpts())
@@ -660,6 +667,16 @@ public ClientOptInput toClientOptInput() {
660667
return input;
661668
}
662669

670+
private ParseOptions buildParseOptions() {
671+
ParseOptions options = new ParseOptions();
672+
options.setResolve(true);
673+
options.setResolveFully(resolveFully);
674+
options.setFlatten(true);
675+
options.setFlattenComposedSchemas(flattenInlineSchema);
676+
options.setSkipMatches(this.skipInlineModelMatches);
677+
return options;
678+
}
679+
663680
@JsonAnySetter
664681
public CodegenConfigurator addDynamicProperty(String name, Object value) {
665682
dynamicProperties.put(name, value);

0 commit comments

Comments
 (0)