Merge branch 'obj/SupportForByteArray' of https://github.com/mateuszmackowiak/swagger-codegen into mateuszmackowiak-obj/SupportForByteArray

This commit is contained in:
wing328 2016-05-09 11:21:21 +08:00
commit f28e2f2a1b
4 changed files with 14 additions and 9 deletions

View File

@ -28,6 +28,9 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
public static final String AUTHOR_EMAIL = "authorEmail"; public static final String AUTHOR_EMAIL = "authorEmail";
public static final String GIT_REPO_URL = "gitRepoURL"; public static final String GIT_REPO_URL = "gitRepoURL";
public static final String LICENSE = "license"; public static final String LICENSE = "license";
public static final String BinaryDataType = "ObjcClientCodegenBinaryData";
protected Set<String> foundationClasses = new HashSet<String>(); protected Set<String> foundationClasses = new HashSet<String>();
protected String podName = "SwaggerClient"; protected String podName = "SwaggerClient";
protected String podVersion = "1.0.0"; protected String podVersion = "1.0.0";
@ -65,6 +68,8 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
defaultIncludes.add("NSDictionary"); defaultIncludes.add("NSDictionary");
defaultIncludes.add("NSMutableArray"); defaultIncludes.add("NSMutableArray");
defaultIncludes.add("NSMutableDictionary"); defaultIncludes.add("NSMutableDictionary");
defaultIncludes.add(BinaryDataType);
languageSpecificPrimitives.clear(); languageSpecificPrimitives.clear();
languageSpecificPrimitives.add("NSNumber"); languageSpecificPrimitives.add("NSNumber");
@ -92,10 +97,8 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
typeMapping.put("List", "NSArray"); typeMapping.put("List", "NSArray");
typeMapping.put("object", "NSObject"); typeMapping.put("object", "NSObject");
typeMapping.put("file", "NSURL"); typeMapping.put("file", "NSURL");
//TODO binary should be mapped to byte array typeMapping.put("binary", BinaryDataType);
// mapped to String as a workaround typeMapping.put("ByteArray", BinaryDataType);
typeMapping.put("binary", "NSString");
typeMapping.put("ByteArray", "NSString");
// ref: http://www.tutorialspoint.com/objective_c/objective_c_basic_syntax.htm // ref: http://www.tutorialspoint.com/objective_c/objective_c_basic_syntax.htm
setReservedWordsLowerCase( setReservedWordsLowerCase(
@ -280,11 +283,13 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
String innerType = getSwaggerType(inner); String innerType = getSwaggerType(inner);
String innerTypeDeclaration = getTypeDeclaration(inner); String innerTypeDeclaration = getTypeDeclaration(inner);
if (innerTypeDeclaration.endsWith("*")) { if (innerTypeDeclaration.endsWith("*")) {
innerTypeDeclaration = innerTypeDeclaration.substring(0, innerTypeDeclaration.length() - 1); innerTypeDeclaration = innerTypeDeclaration.substring(0, innerTypeDeclaration.length() - 1);
} }
if(innerTypeDeclaration.equalsIgnoreCase(BinaryDataType)) {
return "NSData*";
}
// In this codition, type of property p is array of primitive, // In this codition, type of property p is array of primitive,
// return container type with pointer, e.g. `NSArray* /* NSString */' // return container type with pointer, e.g. `NSArray* /* NSString */'
if (languageSpecificPrimitives.contains(innerType)) { if (languageSpecificPrimitives.contains(innerType)) {

View File

@ -33,7 +33,7 @@ NSInteger const {{classPrefix}}UnknownResponseObjectErrorCode = 143528;
formatter.numberStyle = NSNumberFormatterDecimalStyle; formatter.numberStyle = NSNumberFormatterDecimalStyle;
_numberFormatter = formatter; _numberFormatter = formatter;
_primitiveTypes = @[@"NSString", @"NSDate", @"NSNumber"]; _primitiveTypes = @[@"NSString", @"NSDate", @"NSNumber"];
_basicReturnTypes = @[@"NSObject", @"id"]; _basicReturnTypes = @[@"NSObject", @"id", @"NSData"];
_arrayOfModelsPatExpression = [NSRegularExpression regularExpressionWithPattern:@"NSArray<(.+)>" _arrayOfModelsPatExpression = [NSRegularExpression regularExpressionWithPattern:@"NSArray<(.+)>"
options:NSRegularExpressionCaseInsensitive options:NSRegularExpressionCaseInsensitive
error:nil]; error:nil];

View File

@ -6,7 +6,7 @@ This ObjC package is automatically generated by the [Swagger Codegen](https://gi
- API version: 1.0.0 - API version: 1.0.0
- Package version: - Package version:
- Build date: 2016-05-06T12:20:47.112+02:00 - Build date: 2016-05-08T12:06:01.121+02:00
- Build package: class io.swagger.codegen.languages.ObjcClientCodegen - Build package: class io.swagger.codegen.languages.ObjcClientCodegen
## Requirements ## Requirements

View File

@ -33,7 +33,7 @@ NSInteger const SWGUnknownResponseObjectErrorCode = 143528;
formatter.numberStyle = NSNumberFormatterDecimalStyle; formatter.numberStyle = NSNumberFormatterDecimalStyle;
_numberFormatter = formatter; _numberFormatter = formatter;
_primitiveTypes = @[@"NSString", @"NSDate", @"NSNumber"]; _primitiveTypes = @[@"NSString", @"NSDate", @"NSNumber"];
_basicReturnTypes = @[@"NSObject", @"id"]; _basicReturnTypes = @[@"NSObject", @"id", @"NSData"];
_arrayOfModelsPatExpression = [NSRegularExpression regularExpressionWithPattern:@"NSArray<(.+)>" _arrayOfModelsPatExpression = [NSRegularExpression regularExpressionWithPattern:@"NSArray<(.+)>"
options:NSRegularExpressionCaseInsensitive options:NSRegularExpressionCaseInsensitive
error:nil]; error:nil];