This commit is contained in:
William Cheng 2024-04-16 14:05:37 +08:00
parent ef50215438
commit f362ff1e88
5 changed files with 7 additions and 37 deletions

View File

@ -361,7 +361,4 @@ public interface CodegenConfig {
boolean getUseOpenapiNormalizer();
Set<String> getOpenapiGeneratorIgnoreList();
void setApplyCamelizeFix(boolean applyCamelizeFix);
}

View File

@ -316,9 +316,6 @@ public class DefaultCodegen implements CodegenConfig {
// Whether to automatically hardcode params that are considered Constants by OpenAPI Spec
protected boolean autosetConstants = false;
// when set to true, apply camelization fix
protected boolean applyCamelizeFix = false;
public boolean getAddSuffixToDuplicateOperationNicknames() {
return addSuffixToDuplicateOperationNicknames;
}
@ -6185,30 +6182,13 @@ public class DefaultCodegen implements CodegenConfig {
* @return camelized string
*/
protected String removeNonNameElementToCamelCase(final String name, final String nonNameElementPattern) {
if (Boolean.parseBoolean(System.getProperty("openapi.generator.fix.camelize"))) {
// new behaviour with fix
String[] splitString = name.split(nonNameElementPattern);
if (splitString.length > 0) {
splitString[0] = camelize(splitString[0], CamelizeOption.LOWERCASE_FIRST_CHAR);
}
String result = Arrays.stream(splitString)
.map(StringUtils::capitalize)
.collect(Collectors.joining(""));
if (result.length() > 0) {
result = result.substring(0, 1).toLowerCase(Locale.ROOT) + result.substring(1);
}
return result;
} else { // old behaviour with bug
String result = Arrays.stream(name.split(nonNameElementPattern))
.map(StringUtils::capitalize)
.collect(Collectors.joining(""));
if (result.length() > 0) {
result = result.substring(0, 1).toLowerCase(Locale.ROOT) + result.substring(1);
}
return result;
String result = Arrays.stream(name.split(nonNameElementPattern))
.map(StringUtils::capitalize)
.collect(Collectors.joining(""));
if (result.length() > 0) {
result = result.substring(0, 1).toLowerCase(Locale.ROOT) + result.substring(1);
}
return result;
}
@Override
@ -8552,8 +8532,6 @@ public class DefaultCodegen implements CodegenConfig {
this.autosetConstants = autosetConstants;
}
public void setApplyCamelizeFix(boolean applyCamelizeFix) { this.applyCamelizeFix = applyCamelizeFix; }
/**
* This method removes all constant Query, Header and Cookie Params from allParams and sets them as constantParams in the CodegenOperation.
* The definition of constant is single valued required enum params.

View File

@ -17,7 +17,6 @@
package org.openapitools.codegen;
import com.fasterxml.jackson.databind.annotation.JsonAppend;
import io.swagger.v3.core.util.Json;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.Operation;
@ -262,7 +261,6 @@ public class DefaultGenerator implements Generator {
if (config.additionalProperties().containsKey("applyCamelizeFix")) {
org.openapitools.codegen.utils.StringUtils.applyCamelizeFix =
Boolean.parseBoolean(String.valueOf(config.additionalProperties().get("applyCamelizeFix")));
config.setApplyCamelizeFix(true);
}
config.processOpts();

View File

@ -41,9 +41,6 @@ public class StringUtils {
// A cache of escaped words, used to optimize the performance of the escape() method.
private static Cache<EscapedNameOptions, String> escapedWordsCache;
static {
int cacheSize = Integer.parseInt(GlobalSettings.getProperty(NAME_CACHE_SIZE_PROPERTY, "200"));
int cacheExpiry = Integer.parseInt(GlobalSettings.getProperty(NAME_CACHE_EXPIRY_PROPERTY, "5"));
@ -64,7 +61,6 @@ public class StringUtils {
.expireAfterAccess(cacheExpiry, TimeUnit.SECONDS)
.ticker(Ticker.systemTicker())
.build();
}
private static Pattern capitalLetterPattern = Pattern.compile("([A-Z]+)([A-Z][a-z][a-z]+)");

View File

@ -4915,6 +4915,7 @@ public class DefaultCodegenTest {
public void testRemoveNonNameElementToCamelCase() {
final DefaultCodegen codegen = new DefaultCodegen();
Assert.assertFalse(org.openapitools.codegen.utils.StringUtils.applyCamelizeFix);
final String alreadyCamelCase = "aVATRate";
Assert.assertEquals(codegen.removeNonNameElementToCamelCase(alreadyCamelCase), alreadyCamelCase);