Skip to content

Commit f2410e9

Browse files
authored
Merge pull request #488 from swagger-api/crazyk2-issues-463
Crazyk2 issues 463
2 parents 6d92e69 + e4eafa6 commit f2410e9

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

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

Lines changed: 17 additions & 17 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";
@@ -41,7 +39,7 @@ public AbstractKotlinCodegen() {
4139
super();
4240
supportsInheritance = true;
4341

44-
languageSpecificPrimitives = new HashSet<String>(Arrays.asList(
42+
languageSpecificPrimitives = new HashSet<>(Arrays.asList(
4543
"kotlin.Any",
4644
"kotlin.Byte",
4745
"kotlin.Short",
@@ -60,8 +58,9 @@ public AbstractKotlinCodegen() {
6058

6159
// this includes hard reserved words defined by https://github.com/JetBrains/kotlin/blob/master/core/descriptors/src/org/jetbrains/kotlin/renderer/KeywordStringsGenerated.java
6260
// as well as keywords from https://kotlinlang.org/docs/reference/keyword-reference.html
63-
reservedWords = new HashSet<String>(Arrays.asList(
61+
reservedWords = new HashSet<>(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",
@@ -126,7 +126,7 @@ public AbstractKotlinCodegen() {
126126
"while"
127127
));
128128

129-
defaultIncludes = new HashSet<String>(Arrays.asList(
129+
defaultIncludes = new HashSet<>(Arrays.asList(
130130
"kotlin.Byte",
131131
"kotlin.Short",
132132
"kotlin.Int",
@@ -141,12 +141,12 @@ public AbstractKotlinCodegen() {
141141
"kotlin.collections.Map"
142142
));
143143

144-
instantiationLibraryFunction = new HashSet<String>(Arrays.asList(
144+
instantiationLibraryFunction = new HashSet<>(Arrays.asList(
145145
"arrayOf",
146146
"mapOf"
147147
));
148148

149-
typeMapping = new HashMap<String, String>();
149+
typeMapping = new HashMap<>();
150150
typeMapping.put("string", "kotlin.String");
151151
typeMapping.put("boolean", "kotlin.Boolean");
152152
typeMapping.put("integer", "kotlin.Int");
@@ -169,7 +169,7 @@ public AbstractKotlinCodegen() {
169169
instantiationTypes.put("list", "arrayOf");
170170
instantiationTypes.put("map", "mapOf");
171171

172-
importMapping = new HashMap<String, String>();
172+
importMapping = new HashMap<>();
173173
importMapping.put("BigDecimal", "java.math.BigDecimal");
174174
importMapping.put("UUID", "java.util.UUID");
175175
importMapping.put("File", "java.io.File");
@@ -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)