Skip to content

Commit b755d46

Browse files
committed
fixed enum for kotlin
1 parent 8f1b693 commit b755d46

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ public String toEnumDefaultValue(String value, String datatype) {
348348
* @return the sanitized value for enum
349349
*/
350350
public String toEnumValue(String value, String datatype) {
351-
if ("number".equalsIgnoreCase(datatype)) {
351+
if (isPrimivite(datatype)) {
352352
return value;
353353
} else {
354354
return "\"" + escapeText(value) + "\"";
@@ -375,6 +375,12 @@ public String toEnumVarName(String value, String datatype) {
375375
}
376376
}
377377

378+
public boolean isPrimivite(String datatype) {
379+
return "number".equalsIgnoreCase(datatype)
380+
|| "integer".equalsIgnoreCase(datatype)
381+
|| "boolean".equalsIgnoreCase(datatype);
382+
}
383+
378384
// override with any special post-processing
379385
@SuppressWarnings("static-method")
380386
public Map<String, Object> postProcessOperations(Map<String, Object> objs) {

modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/AbstractKotlinCodegen.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,25 @@ public String toEnumVarName(String value, String datatype) {
406406
return modified;
407407
}
408408

409+
@Override
410+
public String toEnumValue(String value, String datatype) {
411+
if (isPrimivite(datatype)) {
412+
return value;
413+
}
414+
return super.toEnumValue(value, datatype);
415+
}
416+
417+
@Override
418+
public boolean isPrimivite(String datatype) {
419+
return "kotlin.Byte".equalsIgnoreCase(datatype)
420+
|| "kotlin.Short".equalsIgnoreCase(datatype)
421+
|| "kotlin.Int".equalsIgnoreCase(datatype)
422+
|| "kotlin.Long".equalsIgnoreCase(datatype)
423+
|| "kotlin.Float".equalsIgnoreCase(datatype)
424+
|| "kotlin.Double".equalsIgnoreCase(datatype)
425+
|| "kotlin.Boolean".equalsIgnoreCase(datatype);
426+
}
427+
409428
@Override
410429
public String toInstantiationType(Property p) {
411430
if (p instanceof ArrayProperty) {

0 commit comments

Comments
 (0)