forked from loafle/openapi-generator-original
[cli][gradle] Adds package name as a global option (#2557)
* [cli] Support packageName as global option CLI supports other package-related options (--api-package, --model-package, --invoker-package). This aligns those options with --package-name to avoid confusion about how to configure these options where those are supported. This intentionally does not apply a packageName getter/setter to DefaultCodegen to reduce the footprint of this change. * [gradle] Add packagName as global option This makes packageName available as a global option, beside apiPackage, modelPackage, and invokerPackage to reduce potential confusion about how to configure the four of these options by generators which support them.
This commit is contained in:
committed by
William Cheng
parent
a5235f25b4
commit
5ea4391af5
@@ -438,12 +438,13 @@ SYNOPSIS
|
||||
[--instantiation-types <instantiation types>...]
|
||||
[--invoker-package <invoker package>]
|
||||
[--language-specific-primitives <language specific primitives>...]
|
||||
[--library <library>] [--log-to-stderr]
|
||||
[--library <library>] [--log-to-stderr] [--minimal-update]
|
||||
[--model-name-prefix <model name prefix>]
|
||||
[--model-name-suffix <model name suffix>]
|
||||
[--model-package <model package>]
|
||||
[(-o <output directory> | --output <output directory>)]
|
||||
[--release-note <release note>] [--remove-operation-id-prefix]
|
||||
[--package-name <package name>] [--release-note <release note>]
|
||||
[--remove-operation-id-prefix]
|
||||
[--reserved-words-mappings <reserved word mappings>...]
|
||||
[(-s | --skip-overwrite)] [--skip-validate-spec]
|
||||
[(-t <template directory> | --template-dir <template directory>)]
|
||||
|
||||
@@ -241,20 +241,22 @@ SYNOPSIS
|
||||
[(-c <configuration file> | --config <configuration file>)]
|
||||
[-D <system properties>...] [--enable-post-process-file]
|
||||
[(-g <generator name> | --generator-name <generator name>)]
|
||||
[--git-repo-id <git repo id>] [--git-user-id <git user id>]
|
||||
[--group-id <group id>] [--http-user-agent <http user agent>]
|
||||
[--generate-alias-as-model] [--git-repo-id <git repo id>]
|
||||
[--git-user-id <git user id>] [--group-id <group id>]
|
||||
[--http-user-agent <http user agent>]
|
||||
(-i <spec file> | --input-spec <spec file>)
|
||||
[--ignore-file-override <ignore file override location>]
|
||||
[--import-mappings <import mappings>...]
|
||||
[--instantiation-types <instantiation types>...]
|
||||
[--invoker-package <invoker package>]
|
||||
[--language-specific-primitives <language specific primitives>...]
|
||||
[--library <library>] [--log-to-stderr]
|
||||
[--library <library>] [--log-to-stderr] [--minimal-update]
|
||||
[--model-name-prefix <model name prefix>]
|
||||
[--model-name-suffix <model name suffix>]
|
||||
[--model-package <model package>]
|
||||
[(-o <output directory> | --output <output directory>)]
|
||||
[--release-note <release note>] [--remove-operation-id-prefix]
|
||||
[--package-name <package name>] [--release-note <release note>]
|
||||
[--remove-operation-id-prefix]
|
||||
[--reserved-words-mappings <reserved word mappings>...]
|
||||
[(-s | --skip-overwrite)] [--skip-validate-spec]
|
||||
[(-t <template directory> | --template-dir <template directory>)]
|
||||
|
||||
@@ -102,6 +102,11 @@ public class Generate implements Runnable {
|
||||
+ "overwritten during the generation.")
|
||||
private Boolean skipOverwrite;
|
||||
|
||||
|
||||
@Option(name = {"--package-name"}, title = "package name",
|
||||
description = CodegenConstants.PACKAGE_NAME_DESC)
|
||||
private String packageName;
|
||||
|
||||
@Option(name = {"--api-package"}, title = "api package",
|
||||
description = CodegenConstants.API_PACKAGE_DESC)
|
||||
private String apiPackage;
|
||||
@@ -288,6 +293,10 @@ public class Generate implements Runnable {
|
||||
configurator.setTemplateDir(templateDir);
|
||||
}
|
||||
|
||||
if (isNotEmpty(packageName)) {
|
||||
configurator.setPackageName(packageName);
|
||||
}
|
||||
|
||||
if (isNotEmpty(templatingEngine)) {
|
||||
configurator.setTemplatingEngineName(templatingEngine);
|
||||
}
|
||||
|
||||
@@ -277,6 +277,19 @@ public class GenerateTest {
|
||||
};
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPackageName() throws Exception {
|
||||
final String value = "io.foo.bar.baz";
|
||||
setupAndRunGenericTest("--package-name", value);
|
||||
|
||||
new FullVerifications() {
|
||||
{
|
||||
configurator.setPackageName(value);
|
||||
times = 1;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testApiPackage() throws Exception {
|
||||
final String value = "io.foo.bar.api";
|
||||
|
||||
@@ -118,6 +118,11 @@ The gradle plugin is not currently published to https://plugins.gradle.org/m2/.
|
||||
|false
|
||||
|Specifies if the existing files should be overwritten during the generation.
|
||||
|
||||
|packageName
|
||||
|String
|
||||
|(generator specific)
|
||||
|Package for generated classes (where supported).
|
||||
|
||||
|apiPackage
|
||||
|String
|
||||
|(generator specific)
|
||||
|
||||
@@ -91,6 +91,7 @@ class OpenApiGeneratorPlugin : Plugin<Project> {
|
||||
systemProperties.set(generate.systemProperties)
|
||||
configFile.set(generate.configFile)
|
||||
skipOverwrite.set(generate.skipOverwrite)
|
||||
packageName.set(generate.packageName)
|
||||
apiPackage.set(generate.apiPackage)
|
||||
modelPackage.set(generate.modelPackage)
|
||||
modelNamePrefix.set(generate.modelNamePrefix)
|
||||
|
||||
@@ -80,6 +80,11 @@ open class OpenApiGeneratorGenerateExtension(project: Project) {
|
||||
*/
|
||||
val skipOverwrite = project.objects.property<Boolean?>()
|
||||
|
||||
/**
|
||||
* Package for generated classes (where supported)
|
||||
*/
|
||||
val packageName = project.objects.property<String>()
|
||||
|
||||
/**
|
||||
* Package for generated api classes
|
||||
*/
|
||||
|
||||
@@ -105,6 +105,12 @@ open class GenerateTask : DefaultTask() {
|
||||
@get:Internal
|
||||
val skipOverwrite = project.objects.property<Boolean?>()
|
||||
|
||||
/**
|
||||
* Package for generated classes (where supported)
|
||||
*/
|
||||
@get:Internal
|
||||
val packageName = project.objects.property<String>()
|
||||
|
||||
/**
|
||||
* Package for generated api classes
|
||||
*/
|
||||
@@ -456,6 +462,10 @@ open class GenerateTask : DefaultTask() {
|
||||
configurator.templateDir = value
|
||||
}
|
||||
|
||||
packageName.ifNotEmpty { value ->
|
||||
configurator.packageName = value
|
||||
}
|
||||
|
||||
apiPackage.ifNotEmpty { value ->
|
||||
configurator.apiPackage = value
|
||||
}
|
||||
|
||||
@@ -137,6 +137,8 @@ public class CodegenConstants {
|
||||
|
||||
public static final String PROJECT_NAME = "projectName";
|
||||
public static final String PACKAGE_NAME = "packageName";
|
||||
public static final String PACKAGE_NAME_DESC = "package for generated classes (where supported)";
|
||||
|
||||
public static final String PACKAGE_VERSION = "packageVersion";
|
||||
|
||||
public static final String PACKAGE_TITLE = "packageTitle";
|
||||
|
||||
Reference in New Issue
Block a user