diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavascriptFlowtypedClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavascriptFlowtypedClientCodegen.java index 878fb31d47..879d04aaca 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavascriptFlowtypedClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavascriptFlowtypedClientCodegen.java @@ -164,7 +164,12 @@ public class JavascriptFlowtypedClientCodegen extends AbstractTypeScriptClientCo } if (additionalProperties.containsKey(SNAPSHOT) && Boolean.valueOf(additionalProperties.get(SNAPSHOT).toString())) { - this.setNpmVersion(npmVersion + "-SNAPSHOT." + SNAPSHOT_SUFFIX_FORMAT.format(new Date())); + if (npmVersion.toUpperCase(Locale.ROOT).matches("^.*-SNAPSHOT$")) { + this.setNpmVersion(npmVersion + "." + SNAPSHOT_SUFFIX_FORMAT.format(new Date())); + } + else { + this.setNpmVersion(npmVersion + "-SNAPSHOT." + SNAPSHOT_SUFFIX_FORMAT.format(new Date())); + } } additionalProperties.put(NPM_VERSION, npmVersion); diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptAngularClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptAngularClientCodegen.java index fb8d581ce4..a926369c1b 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptAngularClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptAngularClientCodegen.java @@ -26,7 +26,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.File; -import java.text.SimpleDateFormat; import java.util.*; import static org.openapitools.codegen.utils.StringUtils.*; @@ -208,9 +207,13 @@ public class TypeScriptAngularClientCodegen extends AbstractTypeScriptClientCode this.setNpmVersion(this.getVersionFromApi()); } - if (additionalProperties.containsKey(SNAPSHOT) - && Boolean.valueOf(additionalProperties.get(SNAPSHOT).toString())) { - this.setNpmVersion(npmVersion + "-SNAPSHOT." + SNAPSHOT_SUFFIX_FORMAT.format(new Date())); + if (additionalProperties.containsKey(SNAPSHOT) && Boolean.valueOf(additionalProperties.get(SNAPSHOT).toString())) { + if (npmVersion.toUpperCase(Locale.ROOT).matches("^.*-SNAPSHOT$")) { + this.setNpmVersion(npmVersion + "." + SNAPSHOT_SUFFIX_FORMAT.format(new Date())); + } + else { + this.setNpmVersion(npmVersion + "-SNAPSHOT." + SNAPSHOT_SUFFIX_FORMAT.format(new Date())); + } } additionalProperties.put(NPM_VERSION, npmVersion); @@ -445,9 +448,9 @@ public class TypeScriptAngularClientCodegen extends AbstractTypeScriptClientCode /** * Finds and returns a path parameter of an operation by its name * - * @param operation - * @param parameterName - * @return + * @param operation the operation + * @param parameterName the name of the parameter + * @return param */ private CodegenParameter findPathParameterByName(CodegenOperation operation, String parameterName) { for (CodegenParameter param : operation.pathParams) { @@ -564,6 +567,7 @@ public class TypeScriptAngularClientCodegen extends AbstractTypeScriptClientCode return toApiFilename(name); } + /* private String getModelnameFromModelFilename(String filename) { String name = filename.substring((modelPackage() + "/").length()); // Remove the file suffix and add the class suffix. @@ -574,6 +578,7 @@ public class TypeScriptAngularClientCodegen extends AbstractTypeScriptClientCode } return camelize(name) + modelSuffix; } + */ @Override public String toModelName(String name) { @@ -654,7 +659,7 @@ public class TypeScriptAngularClientCodegen extends AbstractTypeScriptClientCode /** * Returns version from OpenAPI info. * - * @return + * @return version */ private String getVersionFromApi() { if (this.openAPI != null && this.openAPI.getInfo() != null) { diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptAxiosClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptAxiosClientCodegen.java index 13f7edcbd8..c344e19f6d 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptAxiosClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptAxiosClientCodegen.java @@ -231,7 +231,12 @@ public class TypeScriptAxiosClientCodegen extends AbstractTypeScriptClientCodege } if (additionalProperties.containsKey(SNAPSHOT) && Boolean.valueOf(additionalProperties.get(SNAPSHOT).toString())) { - this.setNpmVersion(npmVersion + "-SNAPSHOT." + SNAPSHOT_SUFFIX_FORMAT.format(new Date())); + if (npmVersion.toUpperCase(Locale.ROOT).matches("^.*-SNAPSHOT$")) { + this.setNpmVersion(npmVersion + "." + SNAPSHOT_SUFFIX_FORMAT.format(new Date())); + } + else { + this.setNpmVersion(npmVersion + "-SNAPSHOT." + SNAPSHOT_SUFFIX_FORMAT.format(new Date())); + } } additionalProperties.put(NPM_VERSION, npmVersion); diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptFetchClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptFetchClientCodegen.java index a174ae4f4b..bc196ee7da 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptFetchClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptFetchClientCodegen.java @@ -194,7 +194,12 @@ public class TypeScriptFetchClientCodegen extends AbstractTypeScriptClientCodege } if (additionalProperties.containsKey(SNAPSHOT) && Boolean.valueOf(additionalProperties.get(SNAPSHOT).toString())) { - this.setNpmVersion(npmVersion + "-SNAPSHOT." + SNAPSHOT_SUFFIX_FORMAT.format(new Date())); + if (npmVersion.toUpperCase(Locale.ROOT).matches("^.*-SNAPSHOT$")) { + this.setNpmVersion(npmVersion + "." + SNAPSHOT_SUFFIX_FORMAT.format(new Date())); + } + else { + this.setNpmVersion(npmVersion + "-SNAPSHOT." + SNAPSHOT_SUFFIX_FORMAT.format(new Date())); + } } additionalProperties.put(NPM_VERSION, npmVersion); diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptInversifyClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptInversifyClientCodegen.java index 61bb8a5212..77d3050205 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptInversifyClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptInversifyClientCodegen.java @@ -129,9 +129,13 @@ public class TypeScriptInversifyClientCodegen extends AbstractTypeScriptClientCo this.setNpmVersion(additionalProperties.get(NPM_VERSION).toString()); } - if (additionalProperties.containsKey(SNAPSHOT) - && Boolean.valueOf(additionalProperties.get(SNAPSHOT).toString())) { - this.setNpmVersion(npmVersion + "-SNAPSHOT." + SNAPSHOT_SUFFIX_FORMAT.format(new Date())); + if (additionalProperties.containsKey(SNAPSHOT) && Boolean.valueOf(additionalProperties.get(SNAPSHOT).toString())) { + if (npmVersion.toUpperCase(Locale.ROOT).matches("^.*-SNAPSHOT$")) { + this.setNpmVersion(npmVersion + "." + SNAPSHOT_SUFFIX_FORMAT.format(new Date())); + } + else { + this.setNpmVersion(npmVersion + "-SNAPSHOT." + SNAPSHOT_SUFFIX_FORMAT.format(new Date())); + } } additionalProperties.put(NPM_VERSION, npmVersion); diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptJqueryClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptJqueryClientCodegen.java index 217f6ded90..379b2a0ee7 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptJqueryClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptJqueryClientCodegen.java @@ -181,7 +181,12 @@ public class TypeScriptJqueryClientCodegen extends AbstractTypeScriptClientCodeg } if (additionalProperties.containsKey(SNAPSHOT) && Boolean.valueOf(additionalProperties.get(SNAPSHOT).toString())) { - this.setNpmVersion(npmVersion + "-SNAPSHOT." + SNAPSHOT_SUFFIX_FORMAT.format(new Date())); + if (npmVersion.toUpperCase(Locale.ROOT).matches("^.*-SNAPSHOT$")) { + this.setNpmVersion(npmVersion + "." + SNAPSHOT_SUFFIX_FORMAT.format(new Date())); + } + else { + this.setNpmVersion(npmVersion + "-SNAPSHOT." + SNAPSHOT_SUFFIX_FORMAT.format(new Date())); + } } additionalProperties.put(NPM_VERSION, npmVersion); diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptNodeClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptNodeClientCodegen.java index 5735b09e47..bdd007d41b 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptNodeClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptNodeClientCodegen.java @@ -232,7 +232,12 @@ public class TypeScriptNodeClientCodegen extends AbstractTypeScriptClientCodegen } if (additionalProperties.containsKey(SNAPSHOT) && Boolean.valueOf(additionalProperties.get(SNAPSHOT).toString())) { - this.setNpmVersion(npmVersion + "-SNAPSHOT." + SNAPSHOT_SUFFIX_FORMAT.format(new Date())); + if (npmVersion.toUpperCase(Locale.ROOT).matches("^.*-SNAPSHOT$")) { + this.setNpmVersion(npmVersion + "." + SNAPSHOT_SUFFIX_FORMAT.format(new Date())); + } + else { + this.setNpmVersion(npmVersion + "-SNAPSHOT." + SNAPSHOT_SUFFIX_FORMAT.format(new Date())); + } } additionalProperties.put(NPM_VERSION, npmVersion); diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptRxjsClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptRxjsClientCodegen.java index 69332ff6bb..777ae409cf 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptRxjsClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptRxjsClientCodegen.java @@ -194,7 +194,12 @@ public class TypeScriptRxjsClientCodegen extends AbstractTypeScriptClientCodegen } if (additionalProperties.containsKey(SNAPSHOT) && Boolean.valueOf(additionalProperties.get(SNAPSHOT).toString())) { - this.setNpmVersion(npmVersion + "-SNAPSHOT." + SNAPSHOT_SUFFIX_FORMAT.format(new Date())); + if (npmVersion.toUpperCase(Locale.ROOT).matches("^.*-SNAPSHOT$")) { + this.setNpmVersion(npmVersion + "." + SNAPSHOT_SUFFIX_FORMAT.format(new Date())); + } + else { + this.setNpmVersion(npmVersion + "-SNAPSHOT." + SNAPSHOT_SUFFIX_FORMAT.format(new Date())); + } } additionalProperties.put(NPM_VERSION, npmVersion); diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/fetch/TypeScriptFetchClientCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/fetch/TypeScriptFetchClientCodegenTest.java new file mode 100644 index 0000000000..f0e4225945 --- /dev/null +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/fetch/TypeScriptFetchClientCodegenTest.java @@ -0,0 +1,49 @@ +package org.openapitools.codegen.typescript.fetch; + +import org.junit.Assert; +import org.junit.Test; +import org.openapitools.codegen.languages.TypeScriptFetchClientCodegen; + + +public class TypeScriptFetchClientCodegenTest { + @Test + public void testSnapshotVersion() { + TypeScriptFetchClientCodegen codegen = new TypeScriptFetchClientCodegen(); + codegen.additionalProperties().put("npmName", "@openapi/typescript-fetch-petstore"); + codegen.additionalProperties().put("snapshot", true); + codegen.additionalProperties().put("npmVersion", "1.0.0-SNAPSHOT"); + codegen.processOpts(); + + Assert.assertTrue(codegen.getNpmVersion().matches("^1.0.0-SNAPSHOT.[0-9]{12}$")); + + codegen = new TypeScriptFetchClientCodegen(); + codegen.additionalProperties().put("npmName", "@openapi/typescript-fetch-petstore"); + codegen.additionalProperties().put("snapshot", true); + codegen.additionalProperties().put("npmVersion", "3.0.0-M1"); + codegen.processOpts(); + + Assert.assertTrue(codegen.getNpmVersion().matches("^3.0.0-M1-SNAPSHOT.[0-9]{12}$")); + + } + + @Test + public void testWithoutSnapshotVersion() { + TypeScriptFetchClientCodegen codegen = new TypeScriptFetchClientCodegen(); + codegen.additionalProperties().put("npmName", "@openapi/typescript-fetch-petstore"); + codegen.additionalProperties().put("snapshot", false); + codegen.additionalProperties().put("npmVersion", "1.0.0-SNAPSHOT"); + codegen.processOpts(); + + Assert.assertTrue(codegen.getNpmVersion().matches("^1.0.0-SNAPSHOT$")); + + codegen = new TypeScriptFetchClientCodegen(); + codegen.additionalProperties().put("npmName", "@openapi/typescript-fetch-petstore"); + codegen.additionalProperties().put("snapshot", false); + codegen.additionalProperties().put("npmVersion", "3.0.0-M1"); + codegen.processOpts(); + + Assert.assertTrue(codegen.getNpmVersion().matches("^3.0.0-M1$")); + + } + +} diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/typescriptangular/TypeScriptAngularClientCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/typescriptangular/TypeScriptAngularClientCodegenTest.java index 256dd93b31..84df6b4f5f 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/typescriptangular/TypeScriptAngularClientCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/typescriptangular/TypeScriptAngularClientCodegenTest.java @@ -11,6 +11,7 @@ import io.swagger.v3.oas.models.PathItem; import io.swagger.v3.oas.models.responses.ApiResponse; import io.swagger.v3.oas.models.responses.ApiResponses; + public class TypeScriptAngularClientCodegenTest { @Test public void testModelFileSuffix() { @@ -19,7 +20,7 @@ public class TypeScriptAngularClientCodegenTest { codegen.additionalProperties().put("modelSuffix", "MySuffix"); codegen.processOpts(); - Assert.assertEquals(codegen.toModelFilename("testName"), "testNameMySuffix"); + Assert.assertEquals("testNameMySuffix", codegen.toModelFilename("testName")); } @Test @@ -35,4 +36,44 @@ public class TypeScriptAngularClientCodegenTest { } + @Test + public void testSnapshotVersion() { + TypeScriptAngularClientCodegen codegen = new TypeScriptAngularClientCodegen(); + codegen.additionalProperties().put("npmName", "@openapi/typescript-angular-petstore"); + codegen.additionalProperties().put("snapshot", true); + codegen.additionalProperties().put("npmVersion", "1.0.0-SNAPSHOT"); + codegen.processOpts(); + + Assert.assertTrue(codegen.getNpmVersion().matches("^1.0.0-SNAPSHOT.[0-9]{12}$")); + + codegen = new TypeScriptAngularClientCodegen(); + codegen.additionalProperties().put("npmName", "@openapi/typescript-angular-petstore"); + codegen.additionalProperties().put("snapshot", true); + codegen.additionalProperties().put("npmVersion", "3.0.0-M1"); + codegen.processOpts(); + + Assert.assertTrue(codegen.getNpmVersion().matches("^3.0.0-M1-SNAPSHOT.[0-9]{12}$")); + + } + + @Test + public void testWithoutSnapshotVersion() { + TypeScriptAngularClientCodegen codegen = new TypeScriptAngularClientCodegen(); + codegen.additionalProperties().put("npmName", "@openapi/typescript-angular-petstore"); + codegen.additionalProperties().put("snapshot", false); + codegen.additionalProperties().put("npmVersion", "1.0.0-SNAPSHOT"); + codegen.processOpts(); + + Assert.assertTrue(codegen.getNpmVersion().matches("^1.0.0-SNAPSHOT$")); + + codegen = new TypeScriptAngularClientCodegen(); + codegen.additionalProperties().put("npmName", "@openapi/typescript-angular-petstore"); + codegen.additionalProperties().put("snapshot", false); + codegen.additionalProperties().put("npmVersion", "3.0.0-M1"); + codegen.processOpts(); + + Assert.assertTrue(codegen.getNpmVersion().matches("^3.0.0-M1$")); + + } + } diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/typescriptnode/TypeScriptNodeClientCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/typescriptnode/TypeScriptNodeClientCodegenTest.java index 908249e27f..aa89ece6c9 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/typescriptnode/TypeScriptNodeClientCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/typescriptnode/TypeScriptNodeClientCodegenTest.java @@ -17,4 +17,45 @@ public class TypeScriptNodeClientCodegenTest { Assert.assertEquals(codegen.toVarName("user|name"), "userName"); Assert.assertEquals(codegen.toVarName("user !\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~name"), "user$Name"); } + + @Test + public void testSnapshotVersion() { + TypeScriptNodeClientCodegen codegen = new TypeScriptNodeClientCodegen(); + codegen.additionalProperties().put("npmName", "@openapi/typescript-angular-petstore"); + codegen.additionalProperties().put("snapshot", true); + codegen.additionalProperties().put("npmVersion", "1.0.0-SNAPSHOT"); + codegen.processOpts(); + + org.junit.Assert.assertTrue(codegen.getNpmVersion().matches("^1.0.0-SNAPSHOT.[0-9]{12}$")); + + codegen = new TypeScriptNodeClientCodegen(); + codegen.additionalProperties().put("npmName", "@openapi/typescript-angular-petstore"); + codegen.additionalProperties().put("snapshot", true); + codegen.additionalProperties().put("npmVersion", "3.0.0-M1"); + codegen.processOpts(); + + org.junit.Assert.assertTrue(codegen.getNpmVersion().matches("^3.0.0-M1-SNAPSHOT.[0-9]{12}$")); + + } + + @Test + public void testWithoutSnapshotVersion() { + TypeScriptNodeClientCodegen codegen = new TypeScriptNodeClientCodegen(); + codegen.additionalProperties().put("npmName", "@openapi/typescript-angular-petstore"); + codegen.additionalProperties().put("snapshot", false); + codegen.additionalProperties().put("npmVersion", "1.0.0-SNAPSHOT"); + codegen.processOpts(); + + org.junit.Assert.assertTrue(codegen.getNpmVersion().matches("^1.0.0-SNAPSHOT$")); + + codegen = new TypeScriptNodeClientCodegen(); + codegen.additionalProperties().put("npmName", "@openapi/typescript-angular-petstore"); + codegen.additionalProperties().put("snapshot", false); + codegen.additionalProperties().put("npmVersion", "3.0.0-M1"); + codegen.processOpts(); + + org.junit.Assert.assertTrue(codegen.getNpmVersion().matches("^3.0.0-M1$")); + + } + }