Skip to content

Commit a0ade99

Browse files
authored
Merge branch 'master' into minor.fixes
2 parents f0cf674 + 0e22587 commit a0ade99

File tree

9 files changed

+45
-8
lines changed

9 files changed

+45
-8
lines changed

src/main/java/io/swagger/codegen/v3/generators/DefaultCodegenConfig.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,12 @@ public void processModelEnums(Map<String, Object> objs) {
362362
}
363363
}
364364

365+
public boolean isPrimivite(String datatype) {
366+
return "number".equalsIgnoreCase(datatype)
367+
|| "integer".equalsIgnoreCase(datatype)
368+
|| "boolean".equalsIgnoreCase(datatype);
369+
}
370+
365371
/**
366372
* update codegen property enum with proper naming convention
367373
* and handling of numbers, special characters
@@ -1465,6 +1471,9 @@ else if (schema instanceof ComposedSchema) {
14651471
// comment out below as allowableValues is not set in post processing model enum
14661472
codegenModel.allowableValues = new HashMap<String, Object>();
14671473
codegenModel.allowableValues.put("values", schema.getEnum());
1474+
if (codegenModel.dataType.equals("BigDecimal")) {
1475+
addImport(codegenModel, "BigDecimal");
1476+
}
14681477
}
14691478
addVars(codegenModel, schema.getProperties(), schema.getRequired());
14701479
}
@@ -1474,6 +1483,7 @@ else if (schema instanceof ComposedSchema) {
14741483
postProcessModelProperty(codegenModel, prop);
14751484
}
14761485
}
1486+
14771487
return codegenModel;
14781488
}
14791489

src/main/java/io/swagger/codegen/v3/generators/java/AbstractJavaCodegen.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1258,8 +1258,7 @@ public String toEnumVarName(String value, String datatype) {
12581258
}
12591259

12601260
// number
1261-
if ("Integer".equals(datatype) || "Long".equals(datatype) ||
1262-
"Float".equals(datatype) || "Double".equals(datatype)) {
1261+
if ("Integer".equals(datatype) || "Long".equals(datatype) || "Float".equals(datatype) || "Double".equals(datatype) || "BigDecimal".equals(datatype)) {
12631262
String varName = "NUMBER_" + value;
12641263
varName = varName.replaceAll("-", "MINUS_");
12651264
varName = varName.replaceAll("\\+", "PLUS_");
@@ -1281,14 +1280,17 @@ public String toEnumValue(String value, String datatype) {
12811280
if (value == null) {
12821281
return null;
12831282
}
1284-
if ("Integer".equals(datatype) || "Double".equals(datatype)) {
1283+
System.out.println("|||||||||||||||||||||||||||| datatype: " + datatype);
1284+
if ("Integer".equals(datatype) || "Double".equals(datatype) || "Boolean".equals(datatype)) {
12851285
return value;
12861286
} else if ("Long".equals(datatype)) {
12871287
// add l to number, e.g. 2048 => 2048l
12881288
return value + "l";
12891289
} else if ("Float".equals(datatype)) {
12901290
// add f to number, e.g. 3.14 => 3.14f
12911291
return value + "f";
1292+
} else if ("BigDecimal".equals(datatype)) {
1293+
return "new BigDecimal(" + escapeText(value) + ")";
12921294
} else {
12931295
return "\"" + escapeText(value) + "\"";
12941296
}

src/main/java/io/swagger/codegen/v3/generators/javascript/JavaScriptClientCodegen.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1064,7 +1064,7 @@ public String toEnumVarName(String value, String datatype) {
10641064

10651065
@Override
10661066
public String toEnumValue(String value, String datatype) {
1067-
if ("Integer".equals(datatype) || "Number".equals(datatype)) {
1067+
if ("Integer".equals(datatype) || "Number".equals(datatype) || "Boolean".equals(datatype)) {
10681068
return value;
10691069
} else {
10701070
return "\"" + escapeText(value) + "\"";

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,25 @@ public String toEnumVarName(String value, String datatype) {
467467
return modified;
468468
}
469469

470+
@Override
471+
public String toEnumValue(String value, String datatype) {
472+
if (isPrimivite(datatype)) {
473+
return value;
474+
}
475+
return super.toEnumValue(value, datatype);
476+
}
477+
478+
@Override
479+
public boolean isPrimivite(String datatype) {
480+
return "kotlin.Byte".equalsIgnoreCase(datatype)
481+
|| "kotlin.Short".equalsIgnoreCase(datatype)
482+
|| "kotlin.Int".equalsIgnoreCase(datatype)
483+
|| "kotlin.Long".equalsIgnoreCase(datatype)
484+
|| "kotlin.Float".equalsIgnoreCase(datatype)
485+
|| "kotlin.Double".equalsIgnoreCase(datatype)
486+
|| "kotlin.Boolean".equalsIgnoreCase(datatype);
487+
}
488+
470489
@Override
471490
public String toInstantiationType(Schema p) {
472491
if (p instanceof ArraySchema) {

src/main/java/io/swagger/codegen/v3/generators/swift/AbstractSwiftCodegen.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ public abstract class AbstractSwiftCodegen extends DefaultCodegenConfig {
5151
public static final String SWIFT_USE_API_NAMESPACE = "swiftUseApiNamespace";
5252
public static final String DEFAULT_POD_AUTHORS = "Swagger Codegen";
5353
public static final String LENIENT_TYPE_CAST = "lenientTypeCast";
54+
protected static final String MODEL_CLASSES = "modelClasses";
55+
protected static final String USE_MODEL_CLASSES = "useModelClasses";
5456

5557
private static final String LIBRARY_PROMISE_KIT = "PromiseKit";
5658
private static final String LIBRARY_RX_SWIFT = "RxSwift";
@@ -192,6 +194,10 @@ public void processOpts() {
192194
additionalProperties.put(POD_AUTHORS, DEFAULT_POD_AUTHORS);
193195
}
194196

197+
if (additionalProperties.containsKey(MODEL_CLASSES)) {
198+
additionalProperties.put(USE_MODEL_CLASSES, true);
199+
}
200+
195201
setLenientTypeCast(convertPropertyToBooleanAndWriteBack(LENIENT_TYPE_CAST));
196202

197203
supportingFiles.add(new SupportingFile("Podspec.mustache",

src/main/resources/handlebars/Java/modelEnum.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public enum {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum
6262

6363
@Override
6464
public {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} read(final JsonReader jsonReader) throws IOException {
65-
{{{dataType}}} value = jsonReader.{{#is this 'integer'}}nextInt(){{/is}}{{#isNot this 'integer'}}next{{{dataType}}}(){{/isNot}};
65+
{{{dataType}}} value = {{#isNumber}}new BigDecimal(jsonReader.nextDouble()){{/isNumber}}{{^isNumber}}jsonReader.{{#isInteger}}nextInt(){{/isInteger}}{{^isInteger}}next{{{dataType}}}(){{/isInteger}}{{/isNumber}};
6666
return {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}}.fromValue(String.valueOf(value));
6767
}
6868
}

src/main/resources/handlebars/Java/modelInnerEnum.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545

4646
@Override
4747
public {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}} read(final JsonReader jsonReader) throws IOException {
48-
{{{datatype}}} value = jsonReader.{{#is ../this 'integer'}}nextInt(){{/is}}{{#isNot ../this 'integer'}}next{{{datatype}}}(){{/isNot}};
48+
{{{dataType}}} value = {{#isNumber}}new BigDecimal(jsonReader.nextDouble()){{/isNumber}}{{^isNumber}}jsonReader.{{#isInteger}}nextInt(){{/isInteger}}{{^isInteger}}next{{{dataType}}}(){{/isInteger}}{{/isNumber}};
4949
return {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}}.fromValue(String.valueOf(value));
5050
}
5151
}{{/gson}}

src/main/resources/handlebars/swift4/modelObject.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
public struct {{classname}}: Codable {
2+
public {{#useModelClasses}}class{{/useModelClasses}}{{^useModelClasses}}struct{{/useModelClasses}} {{classname}}: Codable {
33
44
{{#allVars}}{{#is this 'enum'}}{{> modelInlineEnumDeclaration}}
55
{{/is}}{{/allVars}}{{#allVars}}{{#is this 'enum'}} {{#description}}/** {{description}} */

src/main/resources/handlebars/swift5/modelObject.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
public struct {{classname}}: Codable {
2+
public {{#useModelClasses}}class{{/useModelClasses}}{{^useModelClasses}}struct{{/useModelClasses}} {{classname}}: Codable {
33
44
{{#allVars}}
55
{{#isEnum}}

0 commit comments

Comments
 (0)