forked from loafle/openapi-generator-original
[TypeScript Client] fix npm version when snapshot is true and npmversion is snapshot too (#2401)
This commit is contained in:
parent
01e8c67da9
commit
d795c4e9d0
@ -164,7 +164,12 @@ public class JavascriptFlowtypedClientCodegen extends AbstractTypeScriptClientCo
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (additionalProperties.containsKey(SNAPSHOT) && Boolean.valueOf(additionalProperties.get(SNAPSHOT).toString())) {
|
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);
|
additionalProperties.put(NPM_VERSION, npmVersion);
|
||||||
|
|
||||||
|
@ -26,7 +26,6 @@ import org.slf4j.Logger;
|
|||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
import static org.openapitools.codegen.utils.StringUtils.*;
|
import static org.openapitools.codegen.utils.StringUtils.*;
|
||||||
@ -208,9 +207,13 @@ public class TypeScriptAngularClientCodegen extends AbstractTypeScriptClientCode
|
|||||||
this.setNpmVersion(this.getVersionFromApi());
|
this.setNpmVersion(this.getVersionFromApi());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (additionalProperties.containsKey(SNAPSHOT)
|
if (additionalProperties.containsKey(SNAPSHOT) && Boolean.valueOf(additionalProperties.get(SNAPSHOT).toString())) {
|
||||||
&& Boolean.valueOf(additionalProperties.get(SNAPSHOT).toString())) {
|
if (npmVersion.toUpperCase(Locale.ROOT).matches("^.*-SNAPSHOT$")) {
|
||||||
this.setNpmVersion(npmVersion + "-SNAPSHOT." + SNAPSHOT_SUFFIX_FORMAT.format(new Date()));
|
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);
|
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
|
* Finds and returns a path parameter of an operation by its name
|
||||||
*
|
*
|
||||||
* @param operation
|
* @param operation the operation
|
||||||
* @param parameterName
|
* @param parameterName the name of the parameter
|
||||||
* @return
|
* @return param
|
||||||
*/
|
*/
|
||||||
private CodegenParameter findPathParameterByName(CodegenOperation operation, String parameterName) {
|
private CodegenParameter findPathParameterByName(CodegenOperation operation, String parameterName) {
|
||||||
for (CodegenParameter param : operation.pathParams) {
|
for (CodegenParameter param : operation.pathParams) {
|
||||||
@ -564,6 +567,7 @@ public class TypeScriptAngularClientCodegen extends AbstractTypeScriptClientCode
|
|||||||
return toApiFilename(name);
|
return toApiFilename(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
private String getModelnameFromModelFilename(String filename) {
|
private String getModelnameFromModelFilename(String filename) {
|
||||||
String name = filename.substring((modelPackage() + "/").length());
|
String name = filename.substring((modelPackage() + "/").length());
|
||||||
// Remove the file suffix and add the class suffix.
|
// Remove the file suffix and add the class suffix.
|
||||||
@ -574,6 +578,7 @@ public class TypeScriptAngularClientCodegen extends AbstractTypeScriptClientCode
|
|||||||
}
|
}
|
||||||
return camelize(name) + modelSuffix;
|
return camelize(name) + modelSuffix;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toModelName(String name) {
|
public String toModelName(String name) {
|
||||||
@ -654,7 +659,7 @@ public class TypeScriptAngularClientCodegen extends AbstractTypeScriptClientCode
|
|||||||
/**
|
/**
|
||||||
* Returns version from OpenAPI info.
|
* Returns version from OpenAPI info.
|
||||||
*
|
*
|
||||||
* @return
|
* @return version
|
||||||
*/
|
*/
|
||||||
private String getVersionFromApi() {
|
private String getVersionFromApi() {
|
||||||
if (this.openAPI != null && this.openAPI.getInfo() != null) {
|
if (this.openAPI != null && this.openAPI.getInfo() != null) {
|
||||||
|
@ -231,7 +231,12 @@ public class TypeScriptAxiosClientCodegen extends AbstractTypeScriptClientCodege
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (additionalProperties.containsKey(SNAPSHOT) && Boolean.valueOf(additionalProperties.get(SNAPSHOT).toString())) {
|
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);
|
additionalProperties.put(NPM_VERSION, npmVersion);
|
||||||
|
|
||||||
|
@ -194,7 +194,12 @@ public class TypeScriptFetchClientCodegen extends AbstractTypeScriptClientCodege
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (additionalProperties.containsKey(SNAPSHOT) && Boolean.valueOf(additionalProperties.get(SNAPSHOT).toString())) {
|
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);
|
additionalProperties.put(NPM_VERSION, npmVersion);
|
||||||
|
|
||||||
|
@ -129,9 +129,13 @@ public class TypeScriptInversifyClientCodegen extends AbstractTypeScriptClientCo
|
|||||||
this.setNpmVersion(additionalProperties.get(NPM_VERSION).toString());
|
this.setNpmVersion(additionalProperties.get(NPM_VERSION).toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (additionalProperties.containsKey(SNAPSHOT)
|
if (additionalProperties.containsKey(SNAPSHOT) && Boolean.valueOf(additionalProperties.get(SNAPSHOT).toString())) {
|
||||||
&& Boolean.valueOf(additionalProperties.get(SNAPSHOT).toString())) {
|
if (npmVersion.toUpperCase(Locale.ROOT).matches("^.*-SNAPSHOT$")) {
|
||||||
this.setNpmVersion(npmVersion + "-SNAPSHOT." + SNAPSHOT_SUFFIX_FORMAT.format(new Date()));
|
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);
|
additionalProperties.put(NPM_VERSION, npmVersion);
|
||||||
|
|
||||||
|
@ -181,7 +181,12 @@ public class TypeScriptJqueryClientCodegen extends AbstractTypeScriptClientCodeg
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (additionalProperties.containsKey(SNAPSHOT) && Boolean.valueOf(additionalProperties.get(SNAPSHOT).toString())) {
|
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);
|
additionalProperties.put(NPM_VERSION, npmVersion);
|
||||||
|
|
||||||
|
@ -232,7 +232,12 @@ public class TypeScriptNodeClientCodegen extends AbstractTypeScriptClientCodegen
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (additionalProperties.containsKey(SNAPSHOT) && Boolean.valueOf(additionalProperties.get(SNAPSHOT).toString())) {
|
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);
|
additionalProperties.put(NPM_VERSION, npmVersion);
|
||||||
|
|
||||||
|
@ -194,7 +194,12 @@ public class TypeScriptRxjsClientCodegen extends AbstractTypeScriptClientCodegen
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (additionalProperties.containsKey(SNAPSHOT) && Boolean.valueOf(additionalProperties.get(SNAPSHOT).toString())) {
|
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);
|
additionalProperties.put(NPM_VERSION, npmVersion);
|
||||||
|
|
||||||
|
@ -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$"));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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.ApiResponse;
|
||||||
import io.swagger.v3.oas.models.responses.ApiResponses;
|
import io.swagger.v3.oas.models.responses.ApiResponses;
|
||||||
|
|
||||||
|
|
||||||
public class TypeScriptAngularClientCodegenTest {
|
public class TypeScriptAngularClientCodegenTest {
|
||||||
@Test
|
@Test
|
||||||
public void testModelFileSuffix() {
|
public void testModelFileSuffix() {
|
||||||
@ -19,7 +20,7 @@ public class TypeScriptAngularClientCodegenTest {
|
|||||||
codegen.additionalProperties().put("modelSuffix", "MySuffix");
|
codegen.additionalProperties().put("modelSuffix", "MySuffix");
|
||||||
codegen.processOpts();
|
codegen.processOpts();
|
||||||
|
|
||||||
Assert.assertEquals(codegen.toModelFilename("testName"), "testNameMySuffix");
|
Assert.assertEquals("testNameMySuffix", codegen.toModelFilename("testName"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@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$"));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -17,4 +17,45 @@ public class TypeScriptNodeClientCodegenTest {
|
|||||||
Assert.assertEquals(codegen.toVarName("user|name"), "userName");
|
Assert.assertEquals(codegen.toVarName("user|name"), "userName");
|
||||||
Assert.assertEquals(codegen.toVarName("user !\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~name"), "user$Name");
|
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$"));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user