Skip to content

Commit 9c20050

Browse files
authored
Add an option to skip operation examples (#8731)
* add flag to skip operation examples * reset to false
1 parent ba4aae5 commit 9c20050

12 files changed

Lines changed: 106 additions & 8 deletions

File tree

modules/openapi-generator-cli/src/main/java/org/openapitools/codegen/cmd/Generate.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,10 @@ public class Generate extends OpenApiGeneratorCommand {
217217
description = CodegenConstants.REMOVE_OPERATION_ID_PREFIX_DESC)
218218
private Boolean removeOperationIdPrefix;
219219

220+
@Option(name = {"--skip-operation-example"}, title = "skip examples defined in the operation",
221+
description = CodegenConstants.SKIP_OPERATION_EXAMPLE_DESC)
222+
private Boolean skipOperationExample;
223+
220224
@Option(name = {"--skip-validate-spec"},
221225
title = "skip spec validation",
222226
description = "Skips the default behavior of validating an input specification.")
@@ -393,6 +397,10 @@ public void execute() {
393397
configurator.setRemoveOperationIdPrefix(removeOperationIdPrefix);
394398
}
395399

400+
if (skipOperationExample != null) {
401+
configurator.setSkipOperationExample(skipOperationExample);
402+
}
403+
396404
if (enablePostProcessFile != null) {
397405
configurator.setEnablePostProcessFile(enablePostProcessFile);
398406
}

modules/openapi-generator-core/src/main/java/org/openapitools/codegen/config/WorkflowSettings.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public class WorkflowSettings {
4242
public static final boolean DEFAULT_VERBOSE = false;
4343
public static final boolean DEFAULT_SKIP_OVERWRITE = false;
4444
public static final boolean DEFAULT_REMOVE_OPERATION_ID_PREFIX = false;
45+
public static final boolean DEFAULT_SKIP_OPERATION_EXAMPLE = false;
4546
public static final boolean DEFAULT_LOG_TO_STDERR = false;
4647
public static final boolean DEFAULT_VALIDATE_SPEC = true;
4748
public static final boolean DEFAULT_ENABLE_POST_PROCESS_FILE = false;
@@ -56,6 +57,7 @@ public class WorkflowSettings {
5657
private boolean verbose = DEFAULT_VERBOSE;
5758
private boolean skipOverwrite = DEFAULT_SKIP_OVERWRITE;
5859
private boolean removeOperationIdPrefix = DEFAULT_REMOVE_OPERATION_ID_PREFIX;
60+
private boolean skipOperationExample = DEFAULT_SKIP_OPERATION_EXAMPLE;
5961
private boolean logToStderr = DEFAULT_LOG_TO_STDERR;
6062
private boolean validateSpec = DEFAULT_VALIDATE_SPEC;
6163
private boolean enablePostProcessFile = DEFAULT_ENABLE_POST_PROCESS_FILE;
@@ -104,6 +106,7 @@ public static Builder newBuilder(WorkflowSettings copy) {
104106
builder.verbose = copy.isVerbose();
105107
builder.skipOverwrite = copy.isSkipOverwrite();
106108
builder.removeOperationIdPrefix = copy.isRemoveOperationIdPrefix();
109+
builder.skipOperationExample = copy.isSkipOperationExample();
107110
builder.logToStderr = copy.isLogToStderr();
108111
builder.validateSpec = copy.isValidateSpec();
109112
builder.enablePostProcessFile = copy.isEnablePostProcessFile();
@@ -169,6 +172,15 @@ public boolean isRemoveOperationIdPrefix() {
169172
return removeOperationIdPrefix;
170173
}
171174

175+
/**
176+
* Indicates whether or not to skip examples defined in the operation.
177+
*
178+
* @return <code>true</code> if the examples defined in the operation should be skipped.
179+
*/
180+
public boolean isSkipOperationExample() {
181+
return skipOperationExample;
182+
}
183+
172184
/**
173185
* Indicates whether or not the generator's executor will write all log messages (not just errors) to STDOUT. Useful for
174186
* piping the JSON output of debug options (e.g. <code>-DdebugOperations</code>) to an external parser directly while testing a generator.
@@ -284,6 +296,7 @@ public static final class Builder {
284296
private Boolean verbose = DEFAULT_VERBOSE;
285297
private Boolean skipOverwrite = DEFAULT_SKIP_OVERWRITE;
286298
private Boolean removeOperationIdPrefix = DEFAULT_REMOVE_OPERATION_ID_PREFIX;
299+
private Boolean skipOperationExample = DEFAULT_SKIP_OPERATION_EXAMPLE;
287300
private Boolean logToStderr = DEFAULT_LOG_TO_STDERR;
288301
private Boolean validateSpec = DEFAULT_VALIDATE_SPEC;
289302
private Boolean enablePostProcessFile = DEFAULT_ENABLE_POST_PROCESS_FILE;
@@ -362,6 +375,17 @@ public Builder withRemoveOperationIdPrefix(Boolean removeOperationIdPrefix) {
362375
return this;
363376
}
364377

378+
/**
379+
* Sets the {@code skipOperationExample} and returns a reference to this Builder so that the methods can be chained together.
380+
*
381+
* @param skipOperationExample the {@code skipOperationExample} to set
382+
* @return a reference to this Builder
383+
*/
384+
public Builder withSkipOperationExample(Boolean skipOperationExample) {
385+
this.skipOperationExample = skipOperationExample != null ? skipOperationExample : Boolean.valueOf(DEFAULT_REMOVE_OPERATION_ID_PREFIX);
386+
return this;
387+
}
388+
365389
/**
366390
* Sets the {@code logToStderr} and returns a reference to this Builder so that the methods can be chained together.
367391
*
@@ -568,6 +592,7 @@ public boolean equals(Object o) {
568592
return isVerbose() == that.isVerbose() &&
569593
isSkipOverwrite() == that.isSkipOverwrite() &&
570594
isRemoveOperationIdPrefix() == that.isRemoveOperationIdPrefix() &&
595+
isSkipOperationExample() == that.isSkipOperationExample() &&
571596
isLogToStderr() == that.isLogToStderr() &&
572597
isValidateSpec() == that.isValidateSpec() &&
573598
isEnablePostProcessFile() == that.isEnablePostProcessFile() &&
@@ -590,6 +615,7 @@ public int hashCode() {
590615
isVerbose(),
591616
isSkipOverwrite(),
592617
isRemoveOperationIdPrefix(),
618+
isSkipOperationExample(),
593619
isLogToStderr(),
594620
isValidateSpec(),
595621
isGenerateAliasAsModel(),

modules/openapi-generator-gradle-plugin/README.adoc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,11 @@ apply plugin: 'org.openapi.generator'
294294
|false
295295
|Remove prefix of operationId, e.g. config_getId => getId.
296296

297+
|skipOperationExample
298+
|Boolean
299+
|false
300+
|Skip examples defined in the operation
301+
297302
|apiFilesConstrainedTo
298303
|List(String)
299304
|None

modules/openapi-generator-gradle-plugin/src/main/kotlin/org/openapitools/generator/gradle/plugin/OpenApiGeneratorPlugin.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ class OpenApiGeneratorPlugin : Plugin<Project> {
125125
reservedWordsMappings.set(generate.reservedWordsMappings)
126126
ignoreFileOverride.set(generate.ignoreFileOverride)
127127
removeOperationIdPrefix.set(generate.removeOperationIdPrefix)
128+
skipOperationExample.set(generate.skipOperationExample)
128129
apiFilesConstrainedTo.set(generate.apiFilesConstrainedTo)
129130
modelFilesConstrainedTo.set(generate.modelFilesConstrainedTo)
130131
supportingFilesConstrainedTo.set(generate.supportingFilesConstrainedTo)

modules/openapi-generator-gradle-plugin/src/main/kotlin/org/openapitools/generator/gradle/plugin/extensions/OpenApiGeneratorGenerateExtension.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,11 @@ open class OpenApiGeneratorGenerateExtension(project: Project) {
201201
*/
202202
val removeOperationIdPrefix = project.objects.property<Boolean?>()
203203

204+
/**
205+
* Skip examples defined in the operation
206+
*/
207+
val skipOperationExample = project.objects.property<Boolean?>()
208+
204209
/**
205210
* Defines which API-related files should be generated. This allows you to create a subset of generated files (or none at all).
206211
*
@@ -333,4 +338,4 @@ open class OpenApiGeneratorGenerateExtension(project: Project) {
333338
skipValidateSpec.set(false)
334339
generateAliasAsModel.set(false)
335340
}
336-
}
341+
}

modules/openapi-generator-gradle-plugin/src/main/kotlin/org/openapitools/generator/gradle/plugin/tasks/GenerateTask.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,13 @@ open class GenerateTask : DefaultTask() {
304304
@Input
305305
val removeOperationIdPrefix = project.objects.property<Boolean?>()
306306

307+
/**
308+
* Remove examples defined in the operation
309+
*/
310+
@Optional
311+
@Input
312+
val skipOperationExample = project.objects.property<Boolean?>()
313+
307314
/**
308315
* Defines which API-related files should be generated. This allows you to create a subset of generated files (or none at all).
309316
*
@@ -615,6 +622,10 @@ open class GenerateTask : DefaultTask() {
615622
configurator.setRemoveOperationIdPrefix(value!!)
616623
}
617624

625+
skipOperationExample.ifNotEmpty { value ->
626+
configurator.setSkipOperationExample(value!!)
627+
}
628+
618629
logToStderr.ifNotEmpty { value ->
619630
configurator.setLogToStderr(value)
620631
}

modules/openapi-generator-maven-plugin/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ mvn clean compile
7070
| `ignoreFileOverride` | `openapi.generator.maven.plugin.ignoreFileOverride` | specifies the full path to a `.openapi-generator-ignore` used for pattern based overrides of generated outputs
7171
| `httpUserAgent` | `openapi.generator.maven.plugin.httpUserAgent` | Sets custom User-Agent header value
7272
| `removeOperationIdPrefix` | `openapi.generator.maven.plugin.removeOperationIdPrefix` | remove operationId prefix (e.g. user_getName => getName)
73+
| `skipOperationExample` | `openapi.generator.maven.plugin.skipOperationExample` | skip examples defined in the operation
7374
| `logToStderr` | `openapi.generator.maven.plugin.logToStderr` | write all log messages (not just errors) to STDOUT
7475
| `enablePostProcessFile` | `openapi.generator.maven.plugin.` | enable file post-processing hook
7576
| `skipValidateSpec` | `openapi.generator.maven.plugin.skipValidateSpec` | Whether or not to skip validating the input spec prior to generation. By default, invalid specifications will result in an error.

modules/openapi-generator-maven-plugin/src/main/java/org/openapitools/codegen/plugin/CodeGenMojo.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,12 @@ public class CodeGenMojo extends AbstractMojo {
237237
@Parameter(name = "removeOperationIdPrefix", property = "openapi.generator.maven.plugin.removeOperationIdPrefix")
238238
private Boolean removeOperationIdPrefix;
239239

240+
/**
241+
* To skip examples defined in the operation
242+
*/
243+
@Parameter(name = "skipOperationExample", property = "openapi.generator.maven.plugin.skipOperationExample")
244+
private Boolean skipOperationExample;
245+
240246
/**
241247
* To write all log messages (not just errors) to STDOUT
242248
*/
@@ -485,6 +491,10 @@ public void execute() throws MojoExecutionException {
485491
configurator.setRemoveOperationIdPrefix(removeOperationIdPrefix);
486492
}
487493

494+
if (skipOperationExample != null) {
495+
configurator.setSkipOperationExample(skipOperationExample);
496+
}
497+
488498
if (isNotEmpty(inputSpec)) {
489499
configurator.setInputSpec(inputSpec);
490500
}
@@ -888,4 +898,4 @@ private void adjustAdditionalProperties(final CodegenConfig config) {
888898
}
889899
}
890900
}
891-
}
901+
}

modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenConfig.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,10 @@ public interface CodegenConfig {
214214

215215
void setRemoveOperationIdPrefix(boolean removeOperationIdPrefix);
216216

217+
boolean isSkipOperationExample();
218+
219+
void setSkipOperationExample(boolean skipOperationExample);
220+
217221
public boolean isHideGenerationTimestamp();
218222

219223
public void setHideGenerationTimestamp(boolean hideGenerationTimestamp);

modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenConstants.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,9 @@ public static enum ENUM_PROPERTY_NAMING_TYPE {camelCase, PascalCase, snake_case,
309309
public static final String REMOVE_OPERATION_ID_PREFIX = "removeOperationIdPrefix";
310310
public static final String REMOVE_OPERATION_ID_PREFIX_DESC = "Remove prefix of operationId, e.g. config_getId => getId";
311311

312+
public static final String SKIP_OPERATION_EXAMPLE = "skipOperationExample";
313+
public static final String SKIP_OPERATION_EXAMPLE_DESC = "Skip examples defined in operations to avoid out of memory errors.";
314+
312315
public static final String STRIP_PACKAGE_NAME = "stripPackageName";
313316
public static final String STRIP_PACKAGE_NAME_DESC = "Whether to strip leading dot-separated packages from generated model classes";
314317

0 commit comments

Comments
 (0)