Skip to content
Open
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
7 changes: 5 additions & 2 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,8 @@ SYNOPSIS
[--model-name-suffix <model name suffix>]
[--model-package <model package>]
[(-o <output directory> | --output <output directory>)] [(-p <additional properties> | --additional-properties <additional properties>)...]
[--package-name <package name>] [--release-note <release note>]
[--remove-operation-id-prefix]
[--package-name <package name>] [(-q | --quiet)]
[--release-note <release note>] [--remove-operation-id-prefix]
[--reserved-words-mappings <reserved word mappings>...]
[(-s | --skip-overwrite)] [--server-variables <server variables>...]
[--skip-operation-example] [--skip-validate-spec]
Expand Down Expand Up @@ -464,6 +464,9 @@ OPTIONS
--package-name <package name>
package for generated classes (where supported)

-q, --quiet
quiet mode

--release-note <release note>
Release note, default to 'Minor update'.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ public class Generate extends OpenApiGeneratorCommand {
@Option(name = {"-v", "--verbose"}, description = "verbose mode")
private Boolean verbose;

@Option(name = {"-q", "--quiet"}, description = "quiet mode")
private Boolean quiet;

@Option(name = {"-g", "--generator-name"}, title = "generator name",
description = "generator to use (see list command for list)")
private String generatorName;
Expand Down Expand Up @@ -376,6 +379,10 @@ public void execute() {
configurator.setVerbose(verbose);
}

if (quiet != null) {
configurator.setQuiet(quiet);
}

if (skipOverwrite != null) {
configurator.setSkipOverwrite(skipOverwrite);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,24 @@ public void testVerboseShort() {
verifyNoMoreInteractions(configurator);
}

@Test
public void testQuietLong() {
setupAndRunGenericTest("--quiet");
verify(configurator).setQuiet(true);
verify(configurator).toClientOptInput();
verify(configurator).toContext();
verifyNoMoreInteractions(configurator);
}

@Test
public void testQuietShort() {
setupAndRunGenericTest("-q");
verify(configurator).setQuiet(true);
verify(configurator).toClientOptInput();
verify(configurator).toContext();
verifyNoMoreInteractions(configurator);
}

/**
* This test ensures that when the
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class WorkflowSettings {
public static final boolean DEFAULT_VALIDATE_SPEC = true;
public static final boolean DEFAULT_ENABLE_POST_PROCESS_FILE = false;
public static final boolean DEFAULT_ENABLE_MINIMAL_UPDATE = false;
public static final boolean DEFAULT_QUIET = false;
public static final boolean DEFAULT_STRICT_SPEC_BEHAVIOR = true;
public static final boolean DEFAULT_GENERATE_ALIAS_AS_MODEL = false;
public static final String DEFAULT_TEMPLATING_ENGINE_NAME = null; // this is set by the generator
Expand All @@ -59,6 +60,7 @@ public class WorkflowSettings {
private boolean validateSpec = DEFAULT_VALIDATE_SPEC;
private boolean enablePostProcessFile = DEFAULT_ENABLE_POST_PROCESS_FILE;
private boolean enableMinimalUpdate = DEFAULT_ENABLE_MINIMAL_UPDATE;
private boolean quiet = DEFAULT_QUIET;
private boolean strictSpecBehavior = DEFAULT_STRICT_SPEC_BEHAVIOR;
private boolean generateAliasAsModel = DEFAULT_GENERATE_ALIAS_AS_MODEL;
private String templateDir;
Expand All @@ -77,6 +79,7 @@ private WorkflowSettings(Builder builder) {
this.validateSpec = builder.validateSpec;
this.enablePostProcessFile = builder.enablePostProcessFile;
this.enableMinimalUpdate = builder.enableMinimalUpdate;
this.quiet = builder.quiet;
this.strictSpecBehavior = builder.strictSpecBehavior;
this.templateDir = builder.templateDir;
this.templatingEngineName = builder.templatingEngineName;
Expand Down Expand Up @@ -109,6 +112,7 @@ public static Builder newBuilder(WorkflowSettings copy) {
builder.validateSpec = copy.isValidateSpec();
builder.enablePostProcessFile = copy.isEnablePostProcessFile();
builder.enableMinimalUpdate = copy.isEnableMinimalUpdate();
builder.quiet = copy.isQuiet();
builder.generateAliasAsModel = copy.isGenerateAliasAsModel();
builder.strictSpecBehavior = copy.isStrictSpecBehavior();
builder.templatingEngineName = copy.getTemplatingEngineName();
Expand Down Expand Up @@ -227,6 +231,15 @@ public boolean isEnableMinimalUpdate() {
return enableMinimalUpdate;
}

/**
* Indicates whether or not generation should run in quiet mode.
*
* @return <code>true</code> if quiet mode is enabled, otherwise <code>false</code>.
*/
public boolean isQuiet() {
return quiet;
}

/**
* Indicates whether or not the generation should convert aliases (primitives defined as schema for use within documents) as models.
*
Expand Down Expand Up @@ -307,6 +320,7 @@ public static final class Builder {
private Boolean validateSpec = DEFAULT_VALIDATE_SPEC;
private Boolean enablePostProcessFile = DEFAULT_ENABLE_POST_PROCESS_FILE;
private Boolean enableMinimalUpdate = DEFAULT_ENABLE_MINIMAL_UPDATE;
private Boolean quiet = DEFAULT_QUIET;
private Boolean strictSpecBehavior = DEFAULT_STRICT_SPEC_BEHAVIOR;
private Boolean generateAliasAsModel = DEFAULT_GENERATE_ALIAS_AS_MODEL;
private String templateDir;
Expand Down Expand Up @@ -436,6 +450,17 @@ public Builder withEnableMinimalUpdate(Boolean enableMinimalUpdate) {
return this;
}

/**
* Sets the {@code quiet} and returns a reference to this Builder so that the methods can be chained together.
*
* @param quiet the {@code quiet} to set
* @return a reference to this Builder
*/
public Builder withQuiet(Boolean quiet) {
this.quiet = quiet != null ? quiet : Boolean.valueOf(DEFAULT_QUIET);
return this;
}

/**
* Sets the {@code strictSpecBehavior} and returns a reference to this Builder so that the methods can be chained together.
*
Expand Down Expand Up @@ -580,6 +605,7 @@ public String toString() {
", validateSpec=" + validateSpec +
", enablePostProcessFile=" + enablePostProcessFile +
", enableMinimalUpdate=" + enableMinimalUpdate +
", quiet=" + quiet +
", strictSpecBehavior=" + strictSpecBehavior +
", templateDir='" + templateDir + '\'' +
", templatingEngineName='" + templatingEngineName + '\'' +
Expand All @@ -602,6 +628,7 @@ public boolean equals(Object o) {
isValidateSpec() == that.isValidateSpec() &&
isEnablePostProcessFile() == that.isEnablePostProcessFile() &&
isEnableMinimalUpdate() == that.isEnableMinimalUpdate() &&
isQuiet() == that.isQuiet() &&
isStrictSpecBehavior() == that.isStrictSpecBehavior() &&
isGenerateAliasAsModel() == that.isGenerateAliasAsModel() &&
Objects.equals(getInputSpec(), that.getInputSpec()) &&
Expand All @@ -626,6 +653,7 @@ public int hashCode() {
isGenerateAliasAsModel(),
isEnablePostProcessFile(),
isEnableMinimalUpdate(),
isQuiet(),
isStrictSpecBehavior(),
getTemplateDir(),
getTemplatingEngineName(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public void defaultValuesNotOverriddenByNulls() {
.withValidateSpec(null)
.withEnablePostProcessFile(null)
.withEnableMinimalUpdate(null)
.withQuiet(null)
.withStrictSpecBehavior(null)
.build();

Expand All @@ -46,6 +47,7 @@ public void defaultValuesNotOverriddenByNulls() {
assertTrue(settings.isValidateSpec());
assertFalse(settings.isEnablePostProcessFile());
assertFalse(settings.isEnableMinimalUpdate());
assertFalse(settings.isQuiet());
assertTrue(settings.isStrictSpecBehavior());
}

Expand Down Expand Up @@ -78,6 +80,7 @@ private void assertOnChangesToDefaults(WorkflowSettings defaultSettings) {
.withValidateSpec(false)
.withEnablePostProcessFile(true)
.withEnableMinimalUpdate(true)
.withQuiet(true)
.withStrictSpecBehavior(false)
.build();

Expand Down Expand Up @@ -105,6 +108,9 @@ private void assertOnChangesToDefaults(WorkflowSettings defaultSettings) {
assertNotEquals(defaultSettings.isEnableMinimalUpdate(), newSettings.isEnableMinimalUpdate());
assertTrue(newSettings.isEnableMinimalUpdate());

assertNotEquals(defaultSettings.isQuiet(), newSettings.isQuiet());
assertTrue(newSettings.isQuiet());

assertNotEquals(defaultSettings.isStrictSpecBehavior(), newSettings.isStrictSpecBehavior());
assertFalse(newSettings.isStrictSpecBehavior());
}
Expand Down
4 changes: 4 additions & 0 deletions modules/openapi-generator-gradle-plugin/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,10 @@ apply plugin: 'org.openapi.generator'
|false
|To write all log messages (not just errors) to STDOUT

|quiet
|Boolean / Provider<Boolean>
|false
|Whether generation should run in quiet mode.
|enablePostProcessFile
|Boolean / Provider<Boolean>
|false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ class OpenApiGeneratorPlugin : Plugin<Project> {
"Generate code via Open API Tools Generator for Open API 2.0 or 3.x specification documents."

verbose.set(generate.verbose)
quiet.set(generate.quiet)
validateSpec.set(generate.validateSpec)
generatorName.set(generate.generatorName)
outputDir.set(generate.outputDir)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ open class OpenApiGeneratorGenerateExtension(private val project: Project) {
*/
val verbose = project.objects.property<Boolean>()

/**
* Whether generation should run in quiet mode.
*/
val quiet = project.objects.property<Boolean>()

/**
* Whether an input specification should be validated upon generation.
*/
Expand Down Expand Up @@ -448,6 +453,7 @@ open class OpenApiGeneratorGenerateExtension(private val project: Project) {
generateApiDocumentation.convention(true)
configOptions.convention(mapOf())
validateSpec.convention(true)
quiet.convention(false)
logToStderr.convention(false)
enablePostProcessFile.convention(false)
skipValidateSpec.convention(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ interface OpenApiWorkParameters : WorkParameters {
val outputDir: DirectoryProperty
val configFile: RegularFileProperty
val verbose: Property<Boolean>
val quiet: Property<Boolean>
val validateSpec: Property<Boolean>
val generatorName: Property<String>
val auth: Property<String>
Expand Down Expand Up @@ -159,6 +160,7 @@ abstract class OpenApiWorkAction : WorkAction<OpenApiWorkParameters> {
params.resolvedInputSpec.orNull?.let { configurator.setInputSpec(it) }
params.outputDir.orNull?.let { configurator.setOutputDir(it.asFile.absolutePath) }
params.verbose.orNull?.let { configurator.setVerbose(it) }
params.quiet.orNull?.let { configurator.setQuiet(it) }
params.validateSpec.orNull?.let { configurator.setValidateSpec(it) }
params.skipOverwrite.orNull?.let { configurator.setSkipOverwrite(it) }
params.generatorName.orNull?.let { configurator.setGeneratorName(it) }
Expand Down Expand Up @@ -316,6 +318,13 @@ abstract class GenerateTask : DefaultTask() {
@get:Input
abstract val verbose: Property<Boolean>

/**
* Whether generation should run in quiet mode.
*/
@get:Optional
@get:Input
abstract val quiet: Property<Boolean>

/**
* Whether an input specification should be validated upon generation.
*/
Expand Down Expand Up @@ -928,6 +937,7 @@ abstract class GenerateTask : DefaultTask() {
parameters.outputDir.set(outputDir)
parameters.configFile.set(configFile)
parameters.verbose.set(verbose)
parameters.quiet.set(quiet)
parameters.validateSpec.set(validateSpec)
parameters.generatorName.set(generatorName)
parameters.auth.set(auth)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,49 @@ class GenerateTaskDslTest : TestBase() {
)
}

@Test(dataProvider = "property_format_provider")
fun `openApiGenerate should suppress promo banner in quiet mode`(format: String) {
val propertyFormat = PropertyFormat.valueOf(format)
val projectFiles = mapOf(
"spec.yaml" to javaClass.classLoader.getResourceAsStream("specs/petstore-v3.0.yaml")
)
withProject(
"""
plugins {
id 'org.openapi.generator'
}
openApiGenerate {
generatorName = "kotlin"
inputSpec = ${"spec.yaml".toPropertyReference(propertyFormat)}
outputDir = ${"build/kotlin".toPropertyReference(propertyFormat)}
apiPackage = "org.openapitools.example.api"
invokerPackage = "org.openapitools.example.invoker"
modelPackage = "org.openapitools.example.model"
quiet = true
configOptions = [
dateLibrary: "java8"
]
}
""".trimIndent(),
projectFiles
)

val result = GradleRunner.create()
.withProjectDir(temp)
.withArguments("openApiGenerate")
.withPluginClasspath()
.build()

assertFalse(
result.output.contains("# Thanks for using OpenAPI Generator."),
"Promo banner is shown even when quiet mode is enabled."
)
assertEquals(
TaskOutcome.SUCCESS, result.task(":openApiGenerate")?.outcome,
"Expected a successful run, but found ${result.task(":openApiGenerate")?.outcome}"
)
}

@Test(dataProvider = "property_format_provider")
fun `openApiGenerate should cleanup outputDir`(format: String) {
val propertyFormat = PropertyFormat.valueOf(format)
Expand Down
1 change: 1 addition & 0 deletions modules/openapi-generator-maven-plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ mvn clean compile
| Option | Property | Description |
|--------|----------|-------------|
| `verbose` | `openapi.generator.maven.plugin.verbose` | verbose mode (`false` by default)
| `quiet` | `openapi.generator.maven.plugin.quiet` | quiet mode (`false` by default)
| `inputSpec` | `openapi.generator.maven.plugin.inputSpec` | OpenAPI Spec file path
| `inputSpecRootDirectory` | `openapi.generator.maven.plugin.inputSpecRootDirectory` | Local root folder with spec file(s)
| `mergedFileName` | `openapi.generator.maven.plugin.mergedFileName` | Name of the file that will contain all merged specs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ public class CodeGenMojo extends AbstractMojo {
@Parameter(name = "verbose", defaultValue = "false")
private boolean verbose;

@Parameter(name = "quiet", property = "openapi.generator.maven.plugin.quiet", defaultValue = "false")
private boolean quiet;

/**
* The name of the generator to use.
*/
Expand Down Expand Up @@ -647,6 +650,7 @@ public void execute() throws MojoExecutionException {
}

configurator.setVerbose(verbose);
configurator.setQuiet(quiet);

if (skipOverwrite != null) {
configurator.setSkipOverwrite(skipOverwrite);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ private void testCommonConfiguration(String profile) throws Exception {
assertEquals("remote.org.openapitools.client.api", getVariableValueFromObject(mojo, "apiPackage"));
assertEquals("remote.org.openapitools.client.model", getVariableValueFromObject(mojo, "modelPackage"));
assertEquals("remote.org.openapitools.client", getVariableValueFromObject(mojo, "invokerPackage"));
assertEquals(Boolean.TRUE, getVariableValueFromObject(mojo, "quiet"));

Map<String, Object> configOptions = (Map<String, Object>) getVariableValueFromObject(mojo, "configOptions");
assertNotNull(configOptions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
<apiPackage>remote.org.openapitools.client.api</apiPackage>
<modelPackage>remote.org.openapitools.client.model</modelPackage>
<invokerPackage>remote.org.openapitools.client</invokerPackage>
<quiet>true</quiet>
<collapsedSpec>petstore-full-spec</collapsedSpec>
<includeCollapsedSpecInArtifacts>true</includeCollapsedSpecInArtifacts>
</configuration>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1011,11 +1011,17 @@ public void setOpenAPI(OpenAPI openAPI) {
@Override
@SuppressWarnings("static-method")
public void postProcess() {
System.out.println("############################################################################################");
System.out.println("# Thanks for using OpenAPI Generator. #");
System.out.println("# We appreciate your support! Please consider donation to help us maintain this project. #");
System.out.println("# https://opencollective.com/openapi_generator/donate #");
System.out.println("############################################################################################");
if (!isQuietMode()) {
System.out.println("############################################################################################");
System.out.println("# Thanks for using OpenAPI Generator. #");
System.out.println("# We appreciate your support! Please consider donation to help us maintain this project. #");
System.out.println("# https://opencollective.com/openapi_generator/donate #");
System.out.println("############################################################################################");
}
}

protected boolean isQuietMode() {
return Boolean.parseBoolean(GlobalSettings.getProperty("quiet", "false"));
}

// override with any special post-processing
Expand Down
Loading
Loading