[Swift] Handle binary data types

This commit is contained in:
Jason Gavris
2016-06-30 14:31:31 -04:00
parent ef857176a6
commit 4f0b7dfaed
10 changed files with 174 additions and 51 deletions

View File

@@ -703,6 +703,8 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
example = "2013-10-20T19:20:30+01:00";
}
example = "@\"" + escapeText(example) + "\"";
} else if ("NSData".equalsIgnoreCase(type)) {
example = "1234";
} else if (!languageSpecificPrimitives.contains(type)) {
// type is a model class, e.g. User
type = type.replace("*", "");

View File

@@ -87,6 +87,7 @@ public class SwiftCodegen extends DefaultCodegen implements CodegenConfig {
);
defaultIncludes = new HashSet<String>(
Arrays.asList(
"NSData",
"NSDate",
"NSURL", // for file
"NSUUID",
@@ -129,10 +130,8 @@ public class SwiftCodegen extends DefaultCodegen implements CodegenConfig {
typeMapping.put("double", "Double");
typeMapping.put("object", "AnyObject");
typeMapping.put("file", "NSURL");
//TODO binary should be mapped to byte array
// mapped to String as a workaround
typeMapping.put("binary", "String");
typeMapping.put("ByteArray", "String");
typeMapping.put("binary", "NSData");
typeMapping.put("ByteArray", "NSData");
typeMapping.put("UUID", "NSUUID");
importMapping = new HashMap<String, String>();
@@ -258,6 +257,11 @@ public class SwiftCodegen extends DefaultCodegen implements CodegenConfig {
return toModelName(type);
}
@Override
public boolean isDataTypeBinary(final String dataType) {
return dataType != null && dataType.equals("NSData");
}
/**
* Output the proper model name (capitalized)
*