Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
wing328 committed Apr 16, 2024
1 parent ef50215 commit f362ff1
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,4 @@ public interface CodegenConfig {
boolean getUseOpenapiNormalizer();

Set<String> getOpenapiGeneratorIgnoreList();

void setApplyCamelizeFix(boolean applyCamelizeFix);

}
Original file line number Diff line number Diff line change
Expand Up @@ -316,9 +316,6 @@ apiTemplateFiles are for API outputs only (controllers/handlers).
// 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;
}
Expand Down Expand Up @@ -6185,30 +6182,13 @@ public String removeNonNameElementToCamelCase(String name) {
* @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
Expand Down Expand Up @@ -8552,8 +8532,6 @@ public void setAutosetConstants(boolean autosetConstants) {
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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -262,7 +261,6 @@ void configureGeneratorProperties() {
if (config.additionalProperties().containsKey("applyCamelizeFix")) {
org.openapitools.codegen.utils.StringUtils.applyCamelizeFix =
Boolean.parseBoolean(String.valueOf(config.additionalProperties().get("applyCamelizeFix")));
config.setApplyCamelizeFix(true);
}

config.processOpts();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand All @@ -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]+)");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4915,6 +4915,7 @@ public void testWebhooks() throws IOException {

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);
Expand Down

0 comments on commit f362ff1

Please sign in to comment.