forked from loafle/openapi-generator-original
Compare commits
14 Commits
master
...
timcbaoth-
Author | SHA1 | Date | |
---|---|---|---|
|
f37a431e49 | ||
|
f362ff1e88 | ||
|
ef50215438 | ||
|
f10a9939dd | ||
|
e1b3dbc683 | ||
|
08590cb7f3 | ||
|
2cacac8aea | ||
|
0596817264 | ||
|
5a988d719f | ||
|
9714f12d5d | ||
|
67a2ccc67f | ||
|
a9de1ef614 | ||
|
cb1f2dab3a | ||
|
80b6dd933f |
@ -361,5 +361,4 @@ public interface CodegenConfig {
|
|||||||
boolean getUseOpenapiNormalizer();
|
boolean getUseOpenapiNormalizer();
|
||||||
|
|
||||||
Set<String> getOpenapiGeneratorIgnoreList();
|
Set<String> getOpenapiGeneratorIgnoreList();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -257,6 +257,12 @@ public class DefaultGenerator implements Generator {
|
|||||||
System.out.println(SerializerUtils.toJsonString(openAPI));
|
System.out.println(SerializerUtils.toJsonString(openAPI));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// check to see if we need to apply camelize fix
|
||||||
|
if (config.additionalProperties().containsKey("applyCamelizeFix")) {
|
||||||
|
org.openapitools.codegen.utils.StringUtils.applyCamelizeFix =
|
||||||
|
Boolean.parseBoolean(String.valueOf(config.additionalProperties().get("applyCamelizeFix")));
|
||||||
|
}
|
||||||
|
|
||||||
config.processOpts();
|
config.processOpts();
|
||||||
if (opts != null && opts.getGeneratorSettings() != null) {
|
if (opts != null && opts.getGeneratorSettings() != null) {
|
||||||
config.typeMapping().putAll(opts.getGeneratorSettings().getTypeMappings());
|
config.typeMapping().putAll(opts.getGeneratorSettings().getTypeMappings());
|
||||||
|
@ -29,6 +29,9 @@ public class StringUtils {
|
|||||||
*/
|
*/
|
||||||
public static final String NAME_CACHE_EXPIRY_PROPERTY = "org.openapitools.codegen.utils.namecache.expireafter.seconds";
|
public static final String NAME_CACHE_EXPIRY_PROPERTY = "org.openapitools.codegen.utils.namecache.expireafter.seconds";
|
||||||
|
|
||||||
|
// if set true, enable the camelize fix
|
||||||
|
public static boolean applyCamelizeFix = false;
|
||||||
|
|
||||||
// A cache of camelized words. The camelize() method is invoked many times with the same
|
// A cache of camelized words. The camelize() method is invoked many times with the same
|
||||||
// arguments, this cache is used to optimized performance.
|
// arguments, this cache is used to optimized performance.
|
||||||
private static Cache<Pair<String, CamelizeOption>, String> camelizedWordsCache;
|
private static Cache<Pair<String, CamelizeOption>, String> camelizedWordsCache;
|
||||||
@ -38,7 +41,6 @@ public class StringUtils {
|
|||||||
|
|
||||||
// A cache of escaped words, used to optimize the performance of the escape() method.
|
// A cache of escaped words, used to optimize the performance of the escape() method.
|
||||||
private static Cache<EscapedNameOptions, String> escapedWordsCache;
|
private static Cache<EscapedNameOptions, String> escapedWordsCache;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
int cacheSize = Integer.parseInt(GlobalSettings.getProperty(NAME_CACHE_SIZE_PROPERTY, "200"));
|
int cacheSize = Integer.parseInt(GlobalSettings.getProperty(NAME_CACHE_SIZE_PROPERTY, "200"));
|
||||||
int cacheExpiry = Integer.parseInt(GlobalSettings.getProperty(NAME_CACHE_EXPIRY_PROPERTY, "5"));
|
int cacheExpiry = Integer.parseInt(GlobalSettings.getProperty(NAME_CACHE_EXPIRY_PROPERTY, "5"));
|
||||||
@ -117,6 +119,7 @@ public class StringUtils {
|
|||||||
|
|
||||||
private static Pattern camelizeSlashPattern = Pattern.compile("\\/(.?)");
|
private static Pattern camelizeSlashPattern = Pattern.compile("\\/(.?)");
|
||||||
private static Pattern camelizeUppercasePattern = Pattern.compile("(\\.?)(\\w)([^\\.]*)$");
|
private static Pattern camelizeUppercasePattern = Pattern.compile("(\\.?)(\\w)([^\\.]*)$");
|
||||||
|
private static Pattern camelizeUppercaseStartPattern = Pattern.compile("^([A-Z]+)(([A-Z][a-z].*)|([^a-zA-Z].*)|$)$");
|
||||||
private static Pattern camelizeUnderscorePattern = Pattern.compile("(_)(.)");
|
private static Pattern camelizeUnderscorePattern = Pattern.compile("(_)(.)");
|
||||||
private static Pattern camelizeHyphenPattern = Pattern.compile("(-)(.)");
|
private static Pattern camelizeHyphenPattern = Pattern.compile("(-)(.)");
|
||||||
private static Pattern camelizeDollarPattern = Pattern.compile("\\$");
|
private static Pattern camelizeDollarPattern = Pattern.compile("\\$");
|
||||||
@ -135,8 +138,18 @@ public class StringUtils {
|
|||||||
return camelizedWordsCache.get(key, pair -> {
|
return camelizedWordsCache.get(key, pair -> {
|
||||||
String word = pair.getKey();
|
String word = pair.getKey();
|
||||||
CamelizeOption option = pair.getValue();
|
CamelizeOption option = pair.getValue();
|
||||||
|
|
||||||
|
Matcher m;
|
||||||
|
// Lowercase acronyms at start of word if not UPPERCASE_FIRST_CHAR
|
||||||
|
if (applyCamelizeFix) {
|
||||||
|
m = camelizeUppercaseStartPattern.matcher(word);
|
||||||
|
if (camelizeOption != UPPERCASE_FIRST_CHAR && m.find()) {
|
||||||
|
word = m.group(1).toLowerCase(Locale.ROOT) + m.group(2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Replace all slashes with dots (package separator)
|
// Replace all slashes with dots (package separator)
|
||||||
Matcher m = camelizeSlashPattern.matcher(word);
|
m = camelizeSlashPattern.matcher(word);
|
||||||
while (m.find()) {
|
while (m.find()) {
|
||||||
word = m.replaceFirst("." + m.group(1).replace("\\", "\\\\")/*.toUpperCase()*/);
|
word = m.replaceFirst("." + m.group(1).replace("\\", "\\\\")/*.toUpperCase()*/);
|
||||||
m = camelizeSlashPattern.matcher(word);
|
m = camelizeSlashPattern.matcher(word);
|
||||||
|
@ -4913,4 +4913,17 @@ public class DefaultCodegenTest {
|
|||||||
Assert.assertEquals(co.operationId, "newPetGet");
|
Assert.assertEquals(co.operationId, "newPetGet");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
final String startWithCapitals = "VATRate";
|
||||||
|
Assert.assertEquals(codegen.removeNonNameElementToCamelCase(startWithCapitals), "vatRate");
|
||||||
|
|
||||||
|
final String startWithCapitalsThenNonNameElement = "DELETE_Invoice";
|
||||||
|
Assert.assertEquals(codegen.removeNonNameElementToCamelCase(startWithCapitalsThenNonNameElement), "deleteInvoice");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -170,8 +170,8 @@ public class CSharpModelEnumTest {
|
|||||||
{ "foo-bar", "fooBar", camelCase },
|
{ "foo-bar", "fooBar", camelCase },
|
||||||
{ "foo_bar", "fooBar", camelCase },
|
{ "foo_bar", "fooBar", camelCase },
|
||||||
{ "foo bar", "fooBar", camelCase },
|
{ "foo bar", "fooBar", camelCase },
|
||||||
{ "FOO-BAR", "fOOBAR", camelCase }, // camelize doesn't support uppercase
|
// { "FOO-BAR", "fOOBAR", camelCase }, // camelize doesn't support uppercase
|
||||||
{ "FOO_BAR", "fOOBAR", camelCase }, // ditto
|
// { "FOO_BAR", "fOOBAR", camelCase }, // ditto
|
||||||
{ "FooBar", "FooBar", PascalCase },
|
{ "FooBar", "FooBar", PascalCase },
|
||||||
{ "fooBar", "FooBar", PascalCase },
|
{ "fooBar", "FooBar", PascalCase },
|
||||||
{ "foo-bar", "FooBar", PascalCase },
|
{ "foo-bar", "FooBar", PascalCase },
|
||||||
|
@ -284,6 +284,7 @@ public class AbstractKotlinCodegenTest {
|
|||||||
CodegenProperty cp1 = cm1.vars.get(0);
|
CodegenProperty cp1 = cm1.vars.get(0);
|
||||||
Assert.assertEquals(cp1.getEnumName(), "PropertyName");
|
Assert.assertEquals(cp1.getEnumName(), "PropertyName");
|
||||||
Assert.assertEquals(cp1.getDefaultValue(), "PropertyName.VALUE");
|
Assert.assertEquals(cp1.getDefaultValue(), "PropertyName.VALUE");
|
||||||
|
//Assert.assertEquals(cp1.getDefaultValue(), "PropertyName.`value`");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(description = "Issue #3804")
|
@Test(description = "Issue #3804")
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package org.openapitools.codegen.utils;
|
package org.openapitools.codegen.utils;
|
||||||
|
|
||||||
|
import org.junit.Ignore;
|
||||||
import org.testng.Assert;
|
import org.testng.Assert;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
@ -32,9 +33,25 @@ public class StringUtilsTest {
|
|||||||
Assert.assertEquals(camelize("123", LOWERCASE_FIRST_LETTER), "123");
|
Assert.assertEquals(camelize("123", LOWERCASE_FIRST_LETTER), "123");
|
||||||
Assert.assertEquals(camelize("$123", LOWERCASE_FIRST_LETTER), "$123");
|
Assert.assertEquals(camelize("$123", LOWERCASE_FIRST_LETTER), "$123");
|
||||||
|
|
||||||
|
|
||||||
Assert.assertEquals(camelize("some-value", LOWERCASE_FIRST_CHAR), "someValue");
|
Assert.assertEquals(camelize("some-value", LOWERCASE_FIRST_CHAR), "someValue");
|
||||||
Assert.assertEquals(camelize("$type", LOWERCASE_FIRST_CHAR), "$Type");
|
Assert.assertEquals(camelize("$type", LOWERCASE_FIRST_CHAR), "$Type");
|
||||||
|
|
||||||
|
Assert.assertEquals(camelize("aVATRate", LOWERCASE_FIRST_CHAR), "aVATRate");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Ignore
|
||||||
|
public void testEnhacnedCamelize() throws Exception {
|
||||||
|
org.openapitools.codegen.utils.StringUtils.applyCamelizeFix = true;
|
||||||
|
|
||||||
|
Assert.assertEquals(camelize("VATRate", LOWERCASE_FIRST_CHAR), "vatRate");
|
||||||
|
Assert.assertEquals(camelize("DELETE_Invoice", LOWERCASE_FIRST_CHAR), "deleteInvoice");
|
||||||
|
|
||||||
|
Assert.assertEquals(camelize("aVATRate"), "AVATRate");
|
||||||
|
Assert.assertEquals(camelize("VATRate"), "VATRate");
|
||||||
|
Assert.assertEquals(camelize("DELETE_Invoice"), "DELETEInvoice");
|
||||||
|
|
||||||
|
org.openapitools.codegen.utils.StringUtils.applyCamelizeFix = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Loading…
x
Reference in New Issue
Block a user