Merge pull request #3018 from mateuszmackowiak/objc/binary_data

[Objc] Proper binary data handle
This commit is contained in:
wing328
2016-06-05 22:28:56 +08:00
7 changed files with 63 additions and 52 deletions

View File

@@ -1960,7 +1960,7 @@ public class DefaultCodegen {
}
}
r.dataType = cm.datatype;
r.isBinary = cm.datatype.toLowerCase().startsWith("byte");
r.isBinary = isDataTypeBinary(cm.datatype);
if (cm.isContainer != null) {
r.simpleType = false;
r.containerType = cm.containerType;
@@ -2129,7 +2129,7 @@ public class DefaultCodegen {
p.baseType = cp.baseType;
p.dataType = cp.datatype;
p.isPrimitiveType = cp.isPrimitiveType;
p.isBinary = cp.datatype.toLowerCase().startsWith("byte");
p.isBinary = isDataTypeBinary(cp.datatype);
}
// set boolean flag (e.g. isString)
@@ -2226,7 +2226,7 @@ public class DefaultCodegen {
p.isCookieParam = true;
} else if (param instanceof BodyParameter) {
p.isBodyParam = true;
p.isBinary = p.dataType.toLowerCase().startsWith("byte");
p.isBinary = isDataTypeBinary(p.dataType);
} else if (param instanceof FormParameter) {
if ("file".equalsIgnoreCase(((FormParameter) param).getType())) {
p.isFile = true;
@@ -2242,6 +2242,10 @@ public class DefaultCodegen {
return p;
}
public boolean isDataTypeBinary(String dataType) {
return dataType.toLowerCase().startsWith("byte");
}
/**
* Convert map of Swagger SecuritySchemeDefinition objects to a list of Codegen Security objects
*

View File

@@ -23,7 +23,6 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
public static final String GIT_REPO_URL = "gitRepoURL";
public static final String DEFAULT_LICENSE = "Apache License, Version 2.0";
public static final String CORE_DATA = "coreData";
public static final String BinaryDataType = "ObjcClientCodegenBinaryData";
protected Set<String> foundationClasses = new HashSet<String>();
protected String podName = "SwaggerClient";
@@ -70,8 +69,7 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
defaultIncludes.add("NSMutableArray");
defaultIncludes.add("NSMutableDictionary");
defaultIncludes.add("NSManagedObject");
defaultIncludes.add(BinaryDataType);
defaultIncludes.add("NSData");
advancedMapingTypes.add("NSDictionary");
advancedMapingTypes.add("NSArray");
@@ -88,6 +86,7 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
languageSpecificPrimitives.add("NSString");
languageSpecificPrimitives.add("NSObject");
languageSpecificPrimitives.add("NSDate");
languageSpecificPrimitives.add("NSData");
languageSpecificPrimitives.add("NSURL");
languageSpecificPrimitives.add("bool");
languageSpecificPrimitives.add("BOOL");
@@ -109,8 +108,9 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
typeMapping.put("List", "NSArray");
typeMapping.put("object", "NSObject");
typeMapping.put("file", "NSURL");
typeMapping.put("binary", BinaryDataType);
typeMapping.put("ByteArray", BinaryDataType);
typeMapping.put("binary", "NSData");
typeMapping.put("ByteArray", "NSData");
typeMapping.put("byte", "NSData");
// ref: http://www.tutorialspoint.com/objective_c/objective_c_basic_syntax.htm
setReservedWordsLowerCase(
@@ -143,6 +143,7 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
"NSObject",
"NSString",
"NSDate",
"NSData",
"NSURL",
"NSDictionary")
);
@@ -317,16 +318,10 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
if (p instanceof ArrayProperty) {
ArrayProperty ap = (ArrayProperty) p;
Property inner = ap.getItems();
String innerType = getSwaggerType(inner);
String innerTypeDeclaration = getTypeDeclaration(inner);
if (innerTypeDeclaration.endsWith("*")) {
innerTypeDeclaration = innerTypeDeclaration.substring(0, innerTypeDeclaration.length() - 1);
}
if(innerTypeDeclaration.equalsIgnoreCase(BinaryDataType)) {
return "NSData*";
}
// In this condition, type of property p is array of primitive,
// return container type with pointer, e.g. `NSArray*<NSString*>*'
if (languageSpecificPrimitives.contains(innerTypeDeclaration)) {
@@ -363,7 +358,6 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
}
} else {
String swaggerType = getSwaggerType(p);
// In this condition, type of p is objective-c primitive type, e.g. `NSSNumber',
// return type of p with pointer, e.g. `NSNumber*'
if (languageSpecificPrimitives.contains(swaggerType) &&
@@ -394,10 +388,6 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
if (innerTypeDeclaration.endsWith("*")) {
innerTypeDeclaration = innerTypeDeclaration.substring(0, innerTypeDeclaration.length() - 1);
}
if(innerTypeDeclaration.equalsIgnoreCase(BinaryDataType)) {
return "NSData*";
}
// In this codition, type of property p is array of primitive,
// return container type with pointer, e.g. `NSArray*<NSString*>*'
if (languageSpecificPrimitives.contains(innerTypeDeclaration)) {
@@ -454,6 +444,11 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
}
}
@Override
public boolean isDataTypeBinary(String dataType) {
return dataType.toLowerCase().startsWith("nsdata");
}
@Override
public String toModelName(String type) {
// model name cannot use reserved keyword