mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2026-03-23 21:19:08 +00:00
[java] allow to use setArtifactVersion() programmatically (#3907)
* [java] allow to use setArtifactVersion() programmatically * Fix default value in the docs and cli help
This commit is contained in:
committed by
William Cheng
parent
af74f3443f
commit
078d7a38c0
@@ -43,6 +43,8 @@ import static org.openapitools.codegen.utils.StringUtils.*;
|
||||
public abstract class AbstractJavaCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(AbstractJavaCodegen.class);
|
||||
private static final String ARTIFACT_VERSION_DEFAULT_VALUE = "1.0.0";
|
||||
|
||||
public static final String FULL_JAVA_UTIL = "fullJavaUtil";
|
||||
public static final String DEFAULT_LIBRARY = "<default>";
|
||||
public static final String DATE_LIBRARY = "dateLibrary";
|
||||
@@ -60,7 +62,7 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
protected String invokerPackage = "org.openapitools";
|
||||
protected String groupId = "org.openapitools";
|
||||
protected String artifactId = "openapi-java";
|
||||
protected String artifactVersion = "1.0.0";
|
||||
protected String artifactVersion = null;
|
||||
protected String artifactUrl = "https://github.com/openapitools/openapi-generator";
|
||||
protected String artifactDescription = "OpenAPI Java";
|
||||
protected String developerName = "OpenAPI-Generator Contributors";
|
||||
@@ -144,7 +146,7 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
cliOptions.add(new CliOption(CodegenConstants.INVOKER_PACKAGE, CodegenConstants.INVOKER_PACKAGE_DESC).defaultValue(this.getInvokerPackage()));
|
||||
cliOptions.add(new CliOption(CodegenConstants.GROUP_ID, CodegenConstants.GROUP_ID_DESC).defaultValue(this.getGroupId()));
|
||||
cliOptions.add(new CliOption(CodegenConstants.ARTIFACT_ID, CodegenConstants.ARTIFACT_ID_DESC).defaultValue(this.getArtifactId()));
|
||||
cliOptions.add(new CliOption(CodegenConstants.ARTIFACT_VERSION, CodegenConstants.ARTIFACT_VERSION_DESC).defaultValue(this.getArtifactVersion()));
|
||||
cliOptions.add(new CliOption(CodegenConstants.ARTIFACT_VERSION, CodegenConstants.ARTIFACT_VERSION_DESC).defaultValue(ARTIFACT_VERSION_DEFAULT_VALUE));
|
||||
cliOptions.add(new CliOption(CodegenConstants.ARTIFACT_URL, CodegenConstants.ARTIFACT_URL_DESC).defaultValue(this.getArtifactUrl()));
|
||||
cliOptions.add(new CliOption(CodegenConstants.ARTIFACT_DESCRIPTION, CodegenConstants.ARTIFACT_DESCRIPTION_DESC).defaultValue(this.getArtifactDescription()));
|
||||
cliOptions.add(new CliOption(CodegenConstants.SCM_CONNECTION, CodegenConstants.SCM_CONNECTION_DESC).defaultValue(this.getScmConnection()));
|
||||
@@ -1038,12 +1040,18 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
}
|
||||
}
|
||||
|
||||
// If no artifactVersion is provided in additional properties, version from API specification is used.
|
||||
// If none of them is provided then fallbacks to default version
|
||||
if (additionalProperties.containsKey(CodegenConstants.ARTIFACT_VERSION)) {
|
||||
this.setArtifactVersion((String) additionalProperties.get(CodegenConstants.ARTIFACT_VERSION));
|
||||
} else if (openAPI.getInfo() != null && openAPI.getInfo().getVersion() != null) {
|
||||
this.setArtifactVersion(openAPI.getInfo().getVersion());
|
||||
if(artifactVersion == null) {
|
||||
// If no artifactVersion is provided in additional properties, version from API specification is used.
|
||||
// If none of them is provided then fallbacks to default version
|
||||
if (additionalProperties.containsKey(CodegenConstants.ARTIFACT_VERSION)) {
|
||||
this.setArtifactVersion((String) additionalProperties.get(CodegenConstants.ARTIFACT_VERSION));
|
||||
} else if (openAPI.getInfo() != null && openAPI.getInfo().getVersion() != null) {
|
||||
this.setArtifactVersion(openAPI.getInfo().getVersion());
|
||||
} else {
|
||||
this.setArtifactVersion(ARTIFACT_VERSION_DEFAULT_VALUE);
|
||||
}
|
||||
} else {
|
||||
additionalProperties.put(CodegenConstants.ARTIFACT_VERSION, artifactVersion);
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.SNAPSHOT_VERSION)) {
|
||||
@@ -1433,7 +1441,10 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
* @return SNAPSHOT version
|
||||
*/
|
||||
private String buildSnapshotVersion(String version) {
|
||||
return version + "-" + "SNAPSHOT";
|
||||
if(version.endsWith("-SNAPSHOT")) {
|
||||
return version;
|
||||
}
|
||||
return version + "-SNAPSHOT";
|
||||
}
|
||||
|
||||
public void setSupportJava6(boolean value) {
|
||||
|
||||
Reference in New Issue
Block a user