mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2026-03-18 01:59:07 +00:00
[Java] adds snapshotVersion CLI option and uses API version as artifactVersion by default (#2033)
* [Java]: adds snapshotVersion CLI option and uses API version as artifactVersion by default * fix some typos * fix naming diff between branches * ensure-up-to-date * update samples
This commit is contained in:
committed by
William Cheng
parent
8d5b600277
commit
ad8aa7dc0e
@@ -283,10 +283,14 @@ public class CodegenConstants {
|
||||
public static final String ENABLE_POST_PROCESS_FILE_DESC = "Enable post-processing file using environment variables.";
|
||||
|
||||
public static final String OPEN_API_SPEC_NAME = "openAPISpecName";
|
||||
|
||||
|
||||
public static final String GENERATE_ALIAS_AS_MODEL = "generateAliasAsModel";
|
||||
public static final String GENERATE_ALIAS_AS_MODEL_DESC = "Generate alias to map, array as models";
|
||||
|
||||
public static final String USE_COMPARE_NET_OBJECTS = "useCompareNetObjects";
|
||||
public static final String USE_COMPARE_NET_OBJECTS_DESC = "Use KellermanSoftware.CompareNetObjects for deep recursive object comparison. WARNING: this option incurs potential performance impact.";
|
||||
|
||||
public static final String SNAPSHOT_VERSION = "snapshotVersion";
|
||||
public static final String SNAPSHOT_VERSION_DESC = "Uses a SNAPSHOT version.";
|
||||
|
||||
}
|
||||
@@ -191,6 +191,7 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
cliOptions.add(CliOption.newString(CodegenConstants.PARENT_GROUP_ID, CodegenConstants.PARENT_GROUP_ID_DESC));
|
||||
cliOptions.add(CliOption.newString(CodegenConstants.PARENT_ARTIFACT_ID, CodegenConstants.PARENT_ARTIFACT_ID_DESC));
|
||||
cliOptions.add(CliOption.newString(CodegenConstants.PARENT_VERSION, CodegenConstants.PARENT_VERSION_DESC));
|
||||
cliOptions.add(CliOption.newString(CodegenConstants.SNAPSHOT_VERSION, CodegenConstants.SNAPSHOT_VERSION_DESC));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -264,11 +265,21 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.ARTIFACT_VERSION)) {
|
||||
this.setArtifactVersion((String) additionalProperties.get(CodegenConstants.ARTIFACT_VERSION));
|
||||
} else if (this.getVersionFromSpecification() != null) {
|
||||
this.setArtifactVersion(this.getVersionFromSpecification());
|
||||
} else {
|
||||
//not set, use to be passed to template
|
||||
additionalProperties.put(CodegenConstants.ARTIFACT_VERSION, artifactVersion);
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.SNAPSHOT_VERSION)) {
|
||||
Boolean useSnapshotVersion = Boolean.valueOf((String) additionalProperties.get(CodegenConstants.SNAPSHOT_VERSION));
|
||||
|
||||
if (useSnapshotVersion) {
|
||||
this.setArtifactVersion(this.buildSnapshotVersion(this.artifactVersion));
|
||||
}
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.ARTIFACT_URL)) {
|
||||
this.setArtifactUrl((String) additionalProperties.get(CodegenConstants.ARTIFACT_URL));
|
||||
} else {
|
||||
@@ -1340,6 +1351,29 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets version from API specification.
|
||||
*
|
||||
* @return API version
|
||||
*/
|
||||
private String getVersionFromSpecification () {
|
||||
if (this.openAPI != null && this.openAPI.getInfo() != null) {
|
||||
return this.openAPI.getInfo().getVersion();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a SNAPSHOT version from a given version.
|
||||
*
|
||||
* @param version
|
||||
* @return SNAPSHOT version
|
||||
*/
|
||||
private String buildSnapshotVersion (String version) {
|
||||
return version + "-" + "SNAPSHOT";
|
||||
}
|
||||
|
||||
public void setSupportJava6(boolean value) {
|
||||
this.supportJava6 = value;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user