diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/ObjcClientCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/ObjcClientCodegen.java index 0ecdfb667c9..713ee4286a7 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/ObjcClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/ObjcClientCodegen.java @@ -28,6 +28,9 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig { public static final String AUTHOR_EMAIL = "authorEmail"; public static final String GIT_REPO_URL = "gitRepoURL"; public static final String LICENSE = "license"; + + public static final String BinaryDataType = "ObjcClientCodegenBinaryData"; + protected Set foundationClasses = new HashSet(); protected String podName = "SwaggerClient"; protected String podVersion = "1.0.0"; @@ -65,6 +68,8 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig { defaultIncludes.add("NSDictionary"); defaultIncludes.add("NSMutableArray"); defaultIncludes.add("NSMutableDictionary"); + + defaultIncludes.add(BinaryDataType); languageSpecificPrimitives.clear(); languageSpecificPrimitives.add("NSNumber"); @@ -92,10 +97,8 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig { typeMapping.put("List", "NSArray"); typeMapping.put("object", "NSObject"); typeMapping.put("file", "NSURL"); - //TODO binary should be mapped to byte array - // mapped to String as a workaround - typeMapping.put("binary", "NSString"); - typeMapping.put("ByteArray", "NSString"); + typeMapping.put("binary", BinaryDataType); + typeMapping.put("ByteArray", BinaryDataType); // ref: http://www.tutorialspoint.com/objective_c/objective_c_basic_syntax.htm setReservedWordsLowerCase( @@ -280,11 +283,13 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig { 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 codition, type of property p is array of primitive, // return container type with pointer, e.g. `NSArray* /* NSString */' if (languageSpecificPrimitives.contains(innerType)) { diff --git a/modules/swagger-codegen/src/main/resources/objc/ResponseDeserializer-body.mustache b/modules/swagger-codegen/src/main/resources/objc/ResponseDeserializer-body.mustache index 27a59e39cdc..812ed061c04 100644 --- a/modules/swagger-codegen/src/main/resources/objc/ResponseDeserializer-body.mustache +++ b/modules/swagger-codegen/src/main/resources/objc/ResponseDeserializer-body.mustache @@ -33,7 +33,7 @@ NSInteger const {{classPrefix}}UnknownResponseObjectErrorCode = 143528; formatter.numberStyle = NSNumberFormatterDecimalStyle; _numberFormatter = formatter; _primitiveTypes = @[@"NSString", @"NSDate", @"NSNumber"]; - _basicReturnTypes = @[@"NSObject", @"id"]; + _basicReturnTypes = @[@"NSObject", @"id", @"NSData"]; _arrayOfModelsPatExpression = [NSRegularExpression regularExpressionWithPattern:@"NSArray<(.+)>" options:NSRegularExpressionCaseInsensitive error:nil]; diff --git a/samples/client/petstore/objc/README.md b/samples/client/petstore/objc/README.md index a3550545c24..f4b3f2f2f76 100644 --- a/samples/client/petstore/objc/README.md +++ b/samples/client/petstore/objc/README.md @@ -6,7 +6,7 @@ This ObjC package is automatically generated by the [Swagger Codegen](https://gi - API version: 1.0.0 - 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 ## Requirements diff --git a/samples/client/petstore/objc/SwaggerClient/SWGResponseDeserializer.m b/samples/client/petstore/objc/SwaggerClient/SWGResponseDeserializer.m index fa5be3af3d2..a0efd1d5927 100644 --- a/samples/client/petstore/objc/SwaggerClient/SWGResponseDeserializer.m +++ b/samples/client/petstore/objc/SwaggerClient/SWGResponseDeserializer.m @@ -33,7 +33,7 @@ NSInteger const SWGUnknownResponseObjectErrorCode = 143528; formatter.numberStyle = NSNumberFormatterDecimalStyle; _numberFormatter = formatter; _primitiveTypes = @[@"NSString", @"NSDate", @"NSNumber"]; - _basicReturnTypes = @[@"NSObject", @"id"]; + _basicReturnTypes = @[@"NSObject", @"id", @"NSData"]; _arrayOfModelsPatExpression = [NSRegularExpression regularExpressionWithPattern:@"NSArray<(.+)>" options:NSRegularExpressionCaseInsensitive error:nil];