Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -1040,19 +1040,19 @@ public void preprocessOpenAPI(OpenAPI openAPI) {
}
}

// TODO: Setting additionalProperties is not the responsibility of this method. These side-effects should be moved elsewhere to prevent unexpected behaviors.
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)) {
if (additionalProperties.containsKey(CodegenConstants.ARTIFACT_VERSION) && additionalProperties.get(CodegenConstants.ARTIFACT_VERSION) != null) {
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);
}
additionalProperties.put(CodegenConstants.ARTIFACT_VERSION, artifactVersion);

if (additionalProperties.containsKey(CodegenConstants.SNAPSHOT_VERSION)) {
if (convertPropertyToBooleanAndWriteBack(CodegenConstants.SNAPSHOT_VERSION)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ public void additionalPropertyArtifactSnapShotVersionTest() {
@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();
codegen.setArtifactVersion(null);

OpenAPI api = TestUtils.createOpenAPI();
api.getInfo().setVersion(null);
Expand Down Expand Up @@ -340,6 +341,55 @@ public void snapshotVersionOpenAPITest() {
Assert.assertEquals(codegen.getArtifactVersion(), "2.0-SNAPSHOT");
}

@Test(description = "tests if setting an artifact version programmatically persists to additional properties, when openapi version is null")
public void allowsProgrammaticallySettingArtifactVersionWithNullOpenApiVersion() {
final P_AbstractJavaCodegen codegen = new P_AbstractJavaCodegen();
final String version = "9.8.7-rc1";
codegen.setArtifactVersion(version);

OpenAPI api = TestUtils.createOpenAPI();
api.getInfo().setVersion(null);
codegen.processOpts();
codegen.preprocessOpenAPI(api);

Assert.assertEquals(codegen.getArtifactVersion(), version);
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.ARTIFACT_VERSION), version);
}

@Test(description = "tests if setting an artifact version programmatically persists to additional properties, even when openapi version is specified")
public void allowsProgrammaticallySettingArtifactVersionWithSpecifiedOpenApiVersion() {
final P_AbstractJavaCodegen codegen = new P_AbstractJavaCodegen();
final String version = "9.8.7-rc1";
codegen.setArtifactVersion(version);

OpenAPI api = TestUtils.createOpenAPI();
api.getInfo().setVersion("1.2.3-SNAPSHOT");
codegen.processOpts();
codegen.preprocessOpenAPI(api);

Assert.assertEquals(codegen.getArtifactVersion(), version);
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.ARTIFACT_VERSION), version);
}

@Test(description = "tests if a null in addition properties artifactVersion results in default version")
public void usesDefaultVersionWhenAdditionalPropertiesVersionIsNull() {
final P_AbstractJavaCodegen codegen = new P_AbstractJavaCodegen();
final String version = "1.0.0";

OpenAPI api = TestUtils.createOpenAPI();
api.getInfo().setVersion(null);
codegen.setArtifactVersion(null);
codegen.additionalProperties().put(CodegenConstants.ARTIFACT_VERSION, null);

codegen.processOpts();
codegen.preprocessOpenAPI(api);

Assert.assertEquals(codegen.getArtifactVersion(), version);
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.ARTIFACT_VERSION), version);
}



@Test(description = "tests if default version with snapshot is used when setArtifactVersion is used")
public void snapshotVersionAlreadySnapshotTest() {
final P_AbstractJavaCodegen codegen = new P_AbstractJavaCodegen();
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.0.0-SNAPSHOT
4.2.2-SNAPSHOT
2 changes: 1 addition & 1 deletion samples/server/petstore/java-pkmst/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@
<dependency>
<groupId>org.threeten</groupId>
<artifactId>threetenbp</artifactId>
<version>1.3.6</version>
<version>1.4.0</version>
</dependency>
</dependencies>
<dependencyManagement>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) (4.0.0-SNAPSHOT).
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) (4.2.2-SNAPSHOT).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) (4.0.0-SNAPSHOT).
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) (4.2.2-SNAPSHOT).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) (4.0.0-SNAPSHOT).
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) (4.2.2-SNAPSHOT).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class Pet {
private Long id;

@JsonProperty("category")
private Category category = null;
private Category category;

@JsonProperty("name")
private String name;
Expand Down