forked from loafle/openapi-generator-original
[JAVA] fix artifactVersion overriding snapshot parameter when set (#2891)
This commit is contained in:
parent
1ad6701f02
commit
d5e24f0111
@ -266,14 +266,6 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
additionalProperties.put(CodegenConstants.ARTIFACT_ID, artifactId);
|
||||
}
|
||||
|
||||
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 {
|
||||
@ -1047,12 +1039,16 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
this.setArtifactVersion((String) additionalProperties.get(CodegenConstants.ARTIFACT_VERSION));
|
||||
} else if (openAPI.getInfo() != null && openAPI.getInfo().getVersion() != null) {
|
||||
this.setArtifactVersion(openAPI.getInfo().getVersion());
|
||||
additionalProperties.put(CodegenConstants.ARTIFACT_VERSION, artifactVersion);
|
||||
} 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.getArtifactVersion()));
|
||||
}
|
||||
}
|
||||
additionalProperties.put(CodegenConstants.ARTIFACT_VERSION, artifactVersion);
|
||||
|
||||
}
|
||||
|
||||
private static String getAccept(OpenAPI openAPI, Operation operation) {
|
||||
|
@ -225,6 +225,19 @@ public class AbstractJavaCodegenTest {
|
||||
Assert.assertEquals(codegen.getArtifactVersion(), "1.0.7");
|
||||
}
|
||||
|
||||
@Test(description = "tests if API version specification is used if no version is provided in additional properties with snapshot version")
|
||||
public void openApiSnapShotVersionTest() {
|
||||
final P_AbstractJavaCodegen codegen = new P_AbstractJavaCodegen();
|
||||
|
||||
codegen.additionalProperties().put("snapshotVersion", "true");
|
||||
|
||||
OpenAPI api = TestUtils.createOpenAPI();
|
||||
codegen.processOpts();
|
||||
codegen.preprocessOpenAPI(api);
|
||||
|
||||
Assert.assertEquals(codegen.getArtifactVersion(), "1.0.7-SNAPSHOT");
|
||||
}
|
||||
|
||||
@Test(description = "tests if artifactVersion additional property is used")
|
||||
public void additionalPropertyArtifactVersionTest() {
|
||||
final P_AbstractJavaCodegen codegen = new P_AbstractJavaCodegen();
|
||||
@ -238,22 +251,42 @@ public class AbstractJavaCodegenTest {
|
||||
Assert.assertEquals(codegen.getArtifactVersion(), "1.1.1");
|
||||
}
|
||||
|
||||
@Test(description = "tests if artifactVersion additional property is used with snapshot parameter")
|
||||
public void additionalPropertyArtifactSnapShotVersionTest() {
|
||||
final P_AbstractJavaCodegen codegen = new P_AbstractJavaCodegen();
|
||||
|
||||
codegen.additionalProperties().put("artifactVersion", "1.1.1");
|
||||
codegen.additionalProperties().put("snapshotVersion", "true");
|
||||
|
||||
OpenAPI api = TestUtils.createOpenAPI();
|
||||
codegen.processOpts();
|
||||
codegen.preprocessOpenAPI(api);
|
||||
|
||||
Assert.assertEquals(codegen.getArtifactVersion(), "1.1.1-SNAPSHOT");
|
||||
}
|
||||
|
||||
@Test(description = "tests if default version is used when neither OpenAPI version nor artifactVersion additional property has been provided")
|
||||
public void defaultVersionTest() {
|
||||
final P_AbstractJavaCodegen codegen = new P_AbstractJavaCodegen();
|
||||
|
||||
OpenAPI api = TestUtils.createOpenAPI();
|
||||
api.getInfo().setVersion(null);
|
||||
codegen.processOpts();
|
||||
codegen.preprocessOpenAPI(api);
|
||||
|
||||
Assert.assertEquals(codegen.getArtifactVersion(), "1.0.0");
|
||||
}
|
||||
|
||||
@Test(description = "tests if default version is used when neither OpenAPI version nor artifactVersion additional property has been provided")
|
||||
@Test(description = "tests if default version with snapshot is used when neither OpenAPI version nor artifactVersion additional property has been provided")
|
||||
public void snapshotVersionTest() {
|
||||
final P_AbstractJavaCodegen codegen = new P_AbstractJavaCodegen();
|
||||
|
||||
codegen.additionalProperties().put("snapshotVersion", "true");
|
||||
|
||||
OpenAPI api = TestUtils.createOpenAPI();
|
||||
api.getInfo().setVersion(null);
|
||||
codegen.processOpts();
|
||||
codegen.preprocessOpenAPI(api);
|
||||
|
||||
Assert.assertEquals(codegen.getArtifactVersion(), "1.0.0-SNAPSHOT");
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user