[Swift4] Fix default value for enums (#652) (#656)

This fixes an issue that makes the swift 4 api client fail to compile when using enums with a default value.
The fix changes the toDefaultValue method to check if the property is of enum type, and then returns a properly formatted value.
Looking into the code, I wonder why toEnumDefaultValue is not being used here, which seems to be the case for the java implementation.
This commit is contained in:
Even André Fiskvik
2018-09-09 18:18:49 +02:00
committed by William Cheng
parent 7596fb7119
commit f80fa08a01
2 changed files with 60 additions and 0 deletions

View File

@@ -510,6 +510,11 @@ public class Swift4Codegen extends DefaultCodegen implements CodegenConfig {
@Override
public String toDefaultValue(Schema p) {
if (p.getEnum() != null && !p.getEnum().isEmpty()) {
if (p.getDefault() != null) {
return "." + escapeText((String) p.getDefault());
}
}
if (ModelUtils.isIntegerSchema(p) || ModelUtils.isNumberSchema(p) || ModelUtils.isBooleanSchema(p)) {
if (p.getDefault() != null) {
return p.getDefault().toString();