diff --git a/docs/generators/groovy.md b/docs/generators/groovy.md index fdcc91016e8..999c199d2fc 100644 --- a/docs/generators/groovy.md +++ b/docs/generators/groovy.md @@ -41,4 +41,5 @@ sidebar_label: groovy |parentGroupId|parent groupId in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null| |parentArtifactId|parent artifactId in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null| |parentVersion|parent version in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null| +|snapshotVersion|Uses a SNAPSHOT version.| |null| |configPackage|configuration package for generated code| |null| diff --git a/docs/generators/java-inflector.md b/docs/generators/java-inflector.md index e251e5152c5..fcb4a01c169 100644 --- a/docs/generators/java-inflector.md +++ b/docs/generators/java-inflector.md @@ -41,3 +41,4 @@ sidebar_label: java-inflector |parentGroupId|parent groupId in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null| |parentArtifactId|parent artifactId in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null| |parentVersion|parent version in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null| +|snapshotVersion|Uses a SNAPSHOT version.| |null| diff --git a/docs/generators/java-msf4j.md b/docs/generators/java-msf4j.md index 781d29e6b9e..6a086d782b6 100644 --- a/docs/generators/java-msf4j.md +++ b/docs/generators/java-msf4j.md @@ -41,6 +41,7 @@ sidebar_label: java-msf4j |parentGroupId|parent groupId in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null| |parentArtifactId|parent artifactId in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null| |parentVersion|parent version in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null| +|snapshotVersion|Uses a SNAPSHOT version.| |null| |implFolder|folder for generated implementation code| |null| |title|a title describing the application| |null| |useBeanValidation|Use BeanValidation API annotations| |true| diff --git a/docs/generators/java-pkmst.md b/docs/generators/java-pkmst.md index 63933b001f3..b1df6a4337f 100644 --- a/docs/generators/java-pkmst.md +++ b/docs/generators/java-pkmst.md @@ -41,6 +41,7 @@ sidebar_label: java-pkmst |parentGroupId|parent groupId in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null| |parentArtifactId|parent artifactId in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null| |parentVersion|parent version in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null| +|snapshotVersion|Uses a SNAPSHOT version.| |null| |groupId|groupId in generated pom.xml| |null| |artifactId|artifactId in generated pom.xml| |null| |artifactVersion|artifact version in generated pom.xml| |null| diff --git a/docs/generators/java-play-framework.md b/docs/generators/java-play-framework.md index 16040d07eda..578daabb6f1 100644 --- a/docs/generators/java-play-framework.md +++ b/docs/generators/java-play-framework.md @@ -41,6 +41,7 @@ sidebar_label: java-play-framework |parentGroupId|parent groupId in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null| |parentArtifactId|parent artifactId in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null| |parentVersion|parent version in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null| +|snapshotVersion|Uses a SNAPSHOT version.| |null| |title|server title name or client service name| |null| |configPackage|configuration package for generated code| |null| |basePackage|base package for generated code| |null| diff --git a/docs/generators/java-undertow-server.md b/docs/generators/java-undertow-server.md index 50ac3cdec42..850323f1089 100644 --- a/docs/generators/java-undertow-server.md +++ b/docs/generators/java-undertow-server.md @@ -41,3 +41,4 @@ sidebar_label: java-undertow-server |parentGroupId|parent groupId in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null| |parentArtifactId|parent artifactId in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null| |parentVersion|parent version in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null| +|snapshotVersion|Uses a SNAPSHOT version.| |null| diff --git a/docs/generators/java-vertx.md b/docs/generators/java-vertx.md index c673118dc61..5e4e0c26263 100644 --- a/docs/generators/java-vertx.md +++ b/docs/generators/java-vertx.md @@ -41,5 +41,6 @@ sidebar_label: java-vertx |parentGroupId|parent groupId in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null| |parentArtifactId|parent artifactId in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null| |parentVersion|parent version in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null| +|snapshotVersion|Uses a SNAPSHOT version.| |null| |rxInterface|When specified, API interfaces are generated with RX and methods return Single<> and Comparable.| |false| |vertxSwaggerRouterVersion|Specify the version of the swagger router library| |null| diff --git a/docs/generators/java.md b/docs/generators/java.md index 6a9e3f790a8..328719d88d8 100644 --- a/docs/generators/java.md +++ b/docs/generators/java.md @@ -41,6 +41,7 @@ sidebar_label: java |parentGroupId|parent groupId in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null| |parentArtifactId|parent artifactId in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null| |parentVersion|parent version in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null| +|snapshotVersion|Uses a SNAPSHOT version.| |null| |useRxJava|Whether to use the RxJava adapter with the retrofit2 library.| |false| |useRxJava2|Whether to use the RxJava2 adapter with the retrofit2 library.| |false| |parcelableModel|Whether to generate models for Android that implement Parcelable with the okhttp-gson library.| |false| diff --git a/docs/generators/jaxrs-cxf-cdi.md b/docs/generators/jaxrs-cxf-cdi.md index 6a1d1254a34..7943e4d467e 100644 --- a/docs/generators/jaxrs-cxf-cdi.md +++ b/docs/generators/jaxrs-cxf-cdi.md @@ -41,6 +41,7 @@ sidebar_label: jaxrs-cxf-cdi |parentGroupId|parent groupId in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null| |parentArtifactId|parent artifactId in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null| |parentVersion|parent version in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null| +|snapshotVersion|Uses a SNAPSHOT version.| |null| |implFolder|folder for generated implementation code| |null| |title|a title describing the application| |null| |useBeanValidation|Use BeanValidation API annotations| |true| diff --git a/docs/generators/jaxrs-cxf-client.md b/docs/generators/jaxrs-cxf-client.md index cacf2a06d3f..b68f10c3a4a 100644 --- a/docs/generators/jaxrs-cxf-client.md +++ b/docs/generators/jaxrs-cxf-client.md @@ -41,6 +41,7 @@ sidebar_label: jaxrs-cxf-client |parentGroupId|parent groupId in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null| |parentArtifactId|parent artifactId in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null| |parentVersion|parent version in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null| +|snapshotVersion|Uses a SNAPSHOT version.| |null| |useBeanValidation|Use BeanValidation API annotations| |false| |useGzipFeatureForTests|Use Gzip Feature for tests| |false| |useLoggingFeatureForTests|Use Logging Feature for tests| |false| diff --git a/docs/generators/jaxrs-cxf.md b/docs/generators/jaxrs-cxf.md index ec847e1ee57..b4a67a46700 100644 --- a/docs/generators/jaxrs-cxf.md +++ b/docs/generators/jaxrs-cxf.md @@ -41,6 +41,7 @@ sidebar_label: jaxrs-cxf |parentGroupId|parent groupId in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null| |parentArtifactId|parent artifactId in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null| |parentVersion|parent version in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null| +|snapshotVersion|Uses a SNAPSHOT version.| |null| |implFolder|folder for generated implementation code| |null| |title|a title describing the application| |null| |useBeanValidation|Use BeanValidation API annotations| |true| diff --git a/docs/generators/jaxrs-jersey.md b/docs/generators/jaxrs-jersey.md index 38a8428b18f..ce951f5912b 100644 --- a/docs/generators/jaxrs-jersey.md +++ b/docs/generators/jaxrs-jersey.md @@ -41,6 +41,7 @@ sidebar_label: jaxrs-jersey |parentGroupId|parent groupId in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null| |parentArtifactId|parent artifactId in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null| |parentVersion|parent version in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null| +|snapshotVersion|Uses a SNAPSHOT version.| |null| |implFolder|folder for generated implementation code| |null| |title|a title describing the application| |null| |useBeanValidation|Use BeanValidation API annotations| |true| diff --git a/docs/generators/jaxrs-resteasy-eap.md b/docs/generators/jaxrs-resteasy-eap.md index da8f9383644..9b90e8f4ecc 100644 --- a/docs/generators/jaxrs-resteasy-eap.md +++ b/docs/generators/jaxrs-resteasy-eap.md @@ -41,6 +41,7 @@ sidebar_label: jaxrs-resteasy-eap |parentGroupId|parent groupId in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null| |parentArtifactId|parent artifactId in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null| |parentVersion|parent version in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null| +|snapshotVersion|Uses a SNAPSHOT version.| |null| |implFolder|folder for generated implementation code| |null| |title|a title describing the application| |null| |useBeanValidation|Use BeanValidation API annotations| |true| diff --git a/docs/generators/jaxrs-resteasy.md b/docs/generators/jaxrs-resteasy.md index 103d4b887a6..753e2817c35 100644 --- a/docs/generators/jaxrs-resteasy.md +++ b/docs/generators/jaxrs-resteasy.md @@ -41,6 +41,7 @@ sidebar_label: jaxrs-resteasy |parentGroupId|parent groupId in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null| |parentArtifactId|parent artifactId in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null| |parentVersion|parent version in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null| +|snapshotVersion|Uses a SNAPSHOT version.| |null| |implFolder|folder for generated implementation code| |null| |title|a title describing the application| |null| |useBeanValidation|Use BeanValidation API annotations| |true| diff --git a/docs/generators/jaxrs-spec.md b/docs/generators/jaxrs-spec.md index d816eac36ca..a95a6e40e44 100644 --- a/docs/generators/jaxrs-spec.md +++ b/docs/generators/jaxrs-spec.md @@ -41,6 +41,7 @@ sidebar_label: jaxrs-spec |parentGroupId|parent groupId in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null| |parentArtifactId|parent artifactId in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null| |parentVersion|parent version in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null| +|snapshotVersion|Uses a SNAPSHOT version.| |null| |implFolder|folder for generated implementation code| |null| |title|a title describing the application| |null| |useBeanValidation|Use BeanValidation API annotations| |true| diff --git a/docs/generators/spring.md b/docs/generators/spring.md index 87efe3cbe25..a2724f65963 100644 --- a/docs/generators/spring.md +++ b/docs/generators/spring.md @@ -41,6 +41,7 @@ sidebar_label: spring |parentGroupId|parent groupId in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null| |parentArtifactId|parent artifactId in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null| |parentVersion|parent version in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null| +|snapshotVersion|Uses a SNAPSHOT version.| |null| |title|server title name or client service name| |null| |configPackage|configuration package for generated code| |null| |basePackage|base package (invokerPackage) for generated code| |null| diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenConstants.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenConstants.java index 21f921fc655..c07e4c00728 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenConstants.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenConstants.java @@ -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."; + } \ No newline at end of file diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractJavaCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractJavaCodegen.java index 82542f0ca95..5f270f36410 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractJavaCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractJavaCodegen.java @@ -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; } diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/AbstractJavaCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/AbstractJavaCodegenTest.java index a9a6ba4f7dc..5a597ce2f22 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/AbstractJavaCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/AbstractJavaCodegenTest.java @@ -198,6 +198,52 @@ public class AbstractJavaCodegenTest { codegen.setOutputDir("/User/open.api.tools"); Assert.assertEquals(codegen.apiDocFileFolder(), "/User/open.api.tools/docs/".replace('/', File.separatorChar)); } + + @Test(description = "tests if API version specification is used if no version is provided in additional properties") + public void openApiversionTest() { + final P_AbstractJavaCodegen codegen = new P_AbstractJavaCodegen(); + + OpenAPI api = TestUtils.createOpenAPI(); + codegen.setOpenAPI(api); + + codegen.processOpts(); + + Assert.assertEquals(codegen.getArtifactVersion(), "1.0.7"); + } + + @Test(description = "tests if artifactVersion additional property is used") + public void additionalPropertyArtifactVersionTest() { + final P_AbstractJavaCodegen codegen = new P_AbstractJavaCodegen(); + + codegen.additionalProperties().put("artifactVersion", "1.1.1"); + + OpenAPI api = TestUtils.createOpenAPI(); + codegen.setOpenAPI(api); + + codegen.processOpts(); + + Assert.assertEquals(codegen.getArtifactVersion(), "1.1.1"); + } + + @Test(description = "tests if default version is used when neither OpenAPI version nor artifactVersion additional property has been provided") + public void defautlVersionTest() { + final P_AbstractJavaCodegen codegen = new P_AbstractJavaCodegen(); + + codegen.processOpts(); + + 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") + public void snapshotVersionTest() { + final P_AbstractJavaCodegen codegen = new P_AbstractJavaCodegen(); + + codegen.additionalProperties().put("snapshotVersion", "true"); + + codegen.processOpts(); + + Assert.assertEquals(codegen.getArtifactVersion(), "1.0.0-SNAPSHOT"); + } private static class P_AbstractJavaCodegen extends AbstractJavaCodegen { @Override @@ -214,5 +260,11 @@ public class AbstractJavaCodegenTest { public String getHelp() { return null; } + + /** + * Gets artifact version. + * Only for testing purposes. + */ + public String getArtifactVersion () { return this.artifactVersion; } } }