Skip to content

Commit b3abdf2

Browse files
Степан РусаковHugoMario
authored andcommitted
Fix issue-463 - add kotlin reserved words
1 parent 6d92e69 commit b3abdf2

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

src/main/java/io/swagger/codegen/v3/generators/kotlin/AbstractKotlinCodegen.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,12 @@
1717
import java.util.Map;
1818
import java.util.Set;
1919

20-
public abstract class AbstractKotlinCodegen extends DefaultCodegenConfig {
20+
public abstract class AbstractKotlinCodegen extends DefaultCodegenConfig {
2121

2222
private static Logger LOGGER = LoggerFactory.getLogger(AbstractKotlinCodegen.class);
2323

2424
private Set<String> instantiationLibraryFunction;
2525

26-
27-
2826
protected String artifactId;
2927
protected String artifactVersion = "1.0.0";
3028
protected String groupId = "io.swagger";
@@ -62,6 +60,7 @@ public AbstractKotlinCodegen() {
6260
// as well as keywords from https://kotlinlang.org/docs/reference/keyword-reference.html
6361
reservedWords = new HashSet<String>(Arrays.asList(
6462
"abstract",
63+
"actual",
6564
"annotation",
6665
"as",
6766
"break",
@@ -78,6 +77,7 @@ public AbstractKotlinCodegen() {
7877
"do",
7978
"else",
8079
"enum",
80+
"expect",
8181
"external",
8282
"false",
8383
"final",
@@ -272,7 +272,7 @@ public void setEnumPropertyNaming(final String enumPropertyNamingType) {
272272
public String getTypeDeclaration(Schema propertySchema) {
273273
if (propertySchema instanceof ArraySchema) {
274274
return getArrayTypeDeclaration((ArraySchema) propertySchema);
275-
} else if (propertySchema instanceof MapSchema && hasSchemaProperties(propertySchema)) {
275+
} else if (propertySchema instanceof MapSchema && hasSchemaProperties(propertySchema)) {
276276
Schema inner = (Schema) propertySchema.getAdditionalProperties();
277277
if (inner == null) {
278278
LOGGER.warn(propertySchema.getName() + "(map property) does not have a proper inner type defined");
@@ -444,7 +444,7 @@ public String toEnumVarName(String value, String datatype) {
444444
break;
445445
}
446446

447-
if (reservedWords.contains(modified)) {
447+
if (isReservedWord(modified)) {
448448
return escapeReservedWord(modified);
449449
}
450450

@@ -498,7 +498,7 @@ public String toModelName(final String name) {
498498
String modifiedName = name.replaceAll("\\.", "");
499499
modifiedName = sanitizeKotlinSpecificNames(modifiedName);
500500

501-
if (reservedWords.contains(modifiedName)) {
501+
if (isReservedWord(modifiedName)) {
502502
modifiedName = escapeReservedWord(modifiedName);
503503
}
504504

@@ -578,11 +578,11 @@ protected boolean isReservedWord(String word) {
578578
protected boolean needToImport(String type) {
579579
// provides extra protection against improperly trying to import language primitives and java types
580580
boolean imports =
581-
!type.startsWith("kotlin.") &&
582-
!type.startsWith("java.") &&
583-
!defaultIncludes.contains(type) &&
584-
!languageSpecificPrimitives.contains(type) &&
585-
!instantiationLibraryFunction.contains(type);
581+
!type.startsWith("kotlin.") &&
582+
!type.startsWith("java.") &&
583+
!defaultIncludes.contains(type) &&
584+
!languageSpecificPrimitives.contains(type) &&
585+
!instantiationLibraryFunction.contains(type);
586586

587587
return imports;
588588
}

0 commit comments

Comments
 (0)