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 e751bda408e..314067c2ae0 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 @@ -36,6 +36,7 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig { defaultIncludes.add("bool"); defaultIncludes.add("BOOL"); defaultIncludes.add("int"); + defaultIncludes.add("NSURL"); defaultIncludes.add("NSString"); defaultIncludes.add("NSObject"); defaultIncludes.add("NSArray"); @@ -50,6 +51,7 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig { languageSpecificPrimitives.add("NSString"); languageSpecificPrimitives.add("NSObject"); languageSpecificPrimitives.add("NSDate"); + languageSpecificPrimitives.add("NSURL"); languageSpecificPrimitives.add("bool"); languageSpecificPrimitives.add("BOOL"); @@ -69,7 +71,7 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig { typeMapping.put("number", "NSNumber"); typeMapping.put("List", "NSArray"); typeMapping.put("object", "NSObject"); - typeMapping.put("file", "File"); + typeMapping.put("file", "NSURL"); // ref: http://www.tutorialspoint.com/objective_c/objective_c_basic_syntax.htm reservedWords = new HashSet( @@ -97,6 +99,7 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig { "NSObject", "NSString", "NSDate", + "NSURL", "NSDictionary") ); @@ -156,8 +159,6 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig { supportingFiles.add(new SupportingFile("JSONResponseSerializer-body.mustache", swaggerFolder, classPrefix + "JSONResponseSerializer.m")); supportingFiles.add(new SupportingFile("JSONRequestSerializer-body.mustache", swaggerFolder, classPrefix + "JSONRequestSerializer.m")); supportingFiles.add(new SupportingFile("JSONRequestSerializer-header.mustache", swaggerFolder, classPrefix + "JSONRequestSerializer.h")); - supportingFiles.add(new SupportingFile("File-header.mustache", swaggerFolder, classPrefix + "File.h")); - supportingFiles.add(new SupportingFile("File-body.mustache", swaggerFolder, classPrefix + "File.m")); supportingFiles.add(new SupportingFile("JSONValueTransformer+ISO8601.m", swaggerFolder, "JSONValueTransformer+ISO8601.m")); supportingFiles.add(new SupportingFile("JSONValueTransformer+ISO8601.h", swaggerFolder, "JSONValueTransformer+ISO8601.h")); supportingFiles.add(new SupportingFile("Configuration-body.mustache", swaggerFolder, classPrefix + "Configuration.m")); diff --git a/modules/swagger-codegen/src/main/resources/objc/ApiClient-body.mustache b/modules/swagger-codegen/src/main/resources/objc/ApiClient-body.mustache index af82da664ee..e068829caf6 100644 --- a/modules/swagger-codegen/src/main/resources/objc/ApiClient-body.mustache +++ b/modules/swagger-codegen/src/main/resources/objc/ApiClient-body.mustache @@ -348,16 +348,6 @@ static bool loggingEnabled = true; *querys = [NSDictionary dictionaryWithDictionary:querysWithAuth]; } -#pragma mark - Predicate methods - -- (BOOL) isDownloadFile:(NSString *)responseType { - if ([responseType isEqualToString:@"{{classPrefix}}File*"]) { - return YES; - } else { - return NO; - } -} - #pragma mark - Deserialize methods - (id) deserialize:(id) data class:(NSString *) class { @@ -542,10 +532,11 @@ static bool loggingEnabled = true; else { filename = [NSString stringWithFormat:@"%@", [[NSProcessInfo processInfo] globallyUniqueString]]; } - + NSString *filepath = [directory stringByAppendingPathComponent:filename]; + NSURL *file = [NSURL fileURLWithPath:filepath]; - {{classPrefix}}File *file = [[{{classPrefix}}File alloc] initWithPath:filepath data:operation.responseData name:filename]; + [operation.responseData writeToURL:file atomically:YES]; completionBlock(file, nil); } failure:^(AFHTTPRequestOperation *operation, NSError *error) { @@ -573,6 +564,8 @@ static bool loggingEnabled = true; -(NSNumber*) requestWithCompletionBlock: (NSString*) path method: (NSString*) method queryParams: (NSDictionary*) queryParams + formParams: (NSDictionary *) formParams + files: (NSDictionary *) files body: (id) body headerParams: (NSDictionary*) headerParams authSettings: (NSArray *) authSettings @@ -606,66 +599,38 @@ static bool loggingEnabled = true; [self updateHeaderParams:&headerParams queryParams:&queryParams WithAuthSettings:authSettings]; NSMutableURLRequest * request = nil; - if (body != nil && [body isKindOfClass:[NSArray class]]){ - {{classPrefix}}File * file; - NSMutableDictionary * params = [[NSMutableDictionary alloc] init]; - for(id obj in body) { - if([obj isKindOfClass:[{{classPrefix}}File class]]) { - file = ({{classPrefix}}File*) obj; - requestContentType = @"multipart/form-data"; - } - else if([obj isKindOfClass:[NSDictionary class]]) { - for(NSString * key in obj) { - params[key] = obj[key]; - } - } - } - NSString * urlString = [[NSURL URLWithString:path relativeToURL:self.baseURL] absoluteString]; - - // request with multipart form - if([requestContentType isEqualToString:@"multipart/form-data"]) { - request = [self.requestSerializer multipartFormRequestWithMethod: @"POST" - URLString: urlString - parameters: nil - constructingBodyWithBlock: ^(id formData) { - - for(NSString * key in params) { - NSData* data = [params[key] dataUsingEncoding:NSUTF8StringEncoding]; - [formData appendPartWithFormData: data name: key]; - } - - if (file) { - [formData appendPartWithFileData: [file data] - name: [file paramName] - fileName: [file name] - mimeType: [file mimeType]]; - } - - } - error:nil]; - } - // request with form parameters or json - else { - NSString* pathWithQueryParams = [self pathWithQueryParamsToString:path queryParams:queryParams]; - NSString* urlString = [[NSURL URLWithString:pathWithQueryParams relativeToURL:self.baseURL] absoluteString]; - - request = [self.requestSerializer requestWithMethod:method - URLString:urlString - parameters:params - error:nil]; - } - + NSString* pathWithQueryParams = [self pathWithQueryParamsToString:path queryParams:queryParams]; + NSString* urlString = [[NSURL URLWithString:pathWithQueryParams relativeToURL:self.baseURL] absoluteString]; + if (files.count > 0) { + request = [self.requestSerializer multipartFormRequestWithMethod:@"POST" + URLString:urlString + parameters:nil + constructingBodyWithBlock:^(id formData) { + [formParams enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) { + NSData *data = [obj dataUsingEncoding:NSUTF8StringEncoding]; + [formData appendPartWithFormData:data name:key]; + }]; + [files enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) { + NSURL *filePath = (NSURL *)obj; + [formData appendPartWithFileURL:filePath name:key error:nil]; + }]; + } error:nil]; } else { - NSString * pathWithQueryParams = [self pathWithQueryParamsToString:path queryParams:queryParams]; - NSString * urlString = [[NSURL URLWithString:pathWithQueryParams relativeToURL:self.baseURL] absoluteString]; - - request = [self.requestSerializer requestWithMethod: method - URLString: urlString - parameters: body - error: nil]; + if (formParams) { + request = [self.requestSerializer requestWithMethod:method + URLString:urlString + parameters:formParams + error:nil]; + } + if (body) { + request = [self.requestSerializer requestWithMethod:method + URLString:urlString + parameters:body + error:nil]; + } } - + BOOL hasHeaderParams = false; if(headerParams != nil && [headerParams count] > 0) { hasHeaderParams = true; @@ -695,7 +660,7 @@ static bool loggingEnabled = true; [request setHTTPShouldHandleCookies:NO]; NSNumber* requestId = [{{classPrefix}}ApiClient queueRequest]; - if ([self isDownloadFile:responseType]) { + if ([responseType isEqualToString:@"NSURL*"]) { [self downloadOperationWithCompletionBlock:request requestId:requestId completionBlock:^(id data, NSError *error) { completionBlock(data, error); }]; @@ -709,3 +674,7 @@ static bool loggingEnabled = true; } @end + + + + diff --git a/modules/swagger-codegen/src/main/resources/objc/ApiClient-header.mustache b/modules/swagger-codegen/src/main/resources/objc/ApiClient-header.mustache index ee309d774c5..84c61fa34bf 100644 --- a/modules/swagger-codegen/src/main/resources/objc/ApiClient-header.mustache +++ b/modules/swagger-codegen/src/main/resources/objc/ApiClient-header.mustache @@ -3,7 +3,6 @@ #import #import "{{classPrefix}}JSONResponseSerializer.h" #import "{{classPrefix}}JSONRequestSerializer.h" -#import "{{classPrefix}}File.h" #import "{{classPrefix}}QueryParamCollection.h" #import "{{classPrefix}}Configuration.h" @@ -194,6 +193,8 @@ extern NSString *const {{classPrefix}}ResponseObjectErrorKey; -(NSNumber*) requestWithCompletionBlock:(NSString*) path method:(NSString*) method queryParams:(NSDictionary*) queryParams + formParams:(NSDictionary *) formParams + files:(NSDictionary *) files body:(id) body headerParams:(NSDictionary*) headerParams authSettings: (NSArray *) authSettings diff --git a/modules/swagger-codegen/src/main/resources/objc/File-body.mustache b/modules/swagger-codegen/src/main/resources/objc/File-body.mustache deleted file mode 100644 index 496fd0c2519..00000000000 --- a/modules/swagger-codegen/src/main/resources/objc/File-body.mustache +++ /dev/null @@ -1,35 +0,0 @@ -#import "{{classPrefix}}File.h" - -@implementation {{classPrefix}}File - -- (id) init { - self = [super init]; - return self; -} - -- (id) initWithNameData: (NSString*) filename - mimeType: (NSString*) fileMimeType - data: (NSData*) data { - self = [super init]; - if(self) { - _name = filename; - _mimeType = fileMimeType; - _data = data; - } - return self; -} - -- (id) initWithPath:(NSString *)filepath data:(NSData *)data name:(NSString *)filename { - self = [super init]; - - if (self) { - _name = filename; - _data = data; - _path = filepath; - [data writeToFile:_path atomically:YES]; - } - - return self; -} - -@end diff --git a/modules/swagger-codegen/src/main/resources/objc/File-header.mustache b/modules/swagger-codegen/src/main/resources/objc/File-header.mustache deleted file mode 100644 index 3bea6848e6b..00000000000 --- a/modules/swagger-codegen/src/main/resources/objc/File-header.mustache +++ /dev/null @@ -1,45 +0,0 @@ -#import - -@interface {{classPrefix}}File : NSObject - -/** - * File name - */ -@property(nonatomic, readonly) NSString* name; - -/** - * File mimeType, for `multipart/form` post - */ -@property(nonatomic, readonly) NSString* mimeType; - -/** - * File data - */ -@property(nonatomic, readonly) NSData* data; - -/** - * File field parameter name, for `multipart/form` post - */ -@property(nonatomic) NSString* paramName; - -/** - * File path - */ -@property(nonatomic, readonly) NSString *path; - -/** - * Initialize with `filename`, `mimeType`, `filedata`. - */ -- (id) initWithNameData: (NSString*) filename - mimeType: (NSString*) mimeType - data: (NSData*) data; - -/** - * Initialize with `filepath`, `filedata`, `filename` - * and write file data into file path. - */ -- (id) initWithPath: (NSString *) filepath - data: (NSData *) data - name: (NSString *) filename; - -@end diff --git a/modules/swagger-codegen/src/main/resources/objc/api-body.mustache b/modules/swagger-codegen/src/main/resources/objc/api-body.mustache index 5a0442705dd..13a9ed1a9f0 100644 --- a/modules/swagger-codegen/src/main/resources/objc/api-body.mustache +++ b/modules/swagger-codegen/src/main/resources/objc/api-body.mustache @@ -139,6 +139,8 @@ static NSString * basePath = @"{{basePath}}"; NSArray *authSettings = @[{{#authMethods}}@"{{name}}"{{#hasMore}}, {{/hasMore}}{{/authMethods}}]; id bodyParam = nil; + NSMutableDictionary *formParams = [[NSMutableDictionary alloc] init]; + NSMutableDictionary *files = [[NSMutableDictionary alloc] init]; {{#bodyParam}} bodyParam = {{paramName}}; @@ -157,28 +159,13 @@ static NSString * basePath = @"{{basePath}}"; else if([bodyParam respondsToSelector:@selector(toDictionary)]) { bodyParam = [({{classPrefix}}Object*)bodyParam toDictionary]; } - {{/bodyParam}} - {{^bodyParam}} - - NSMutableDictionary * formParams = [[NSMutableDictionary alloc]init]; - + {{/bodyParam}}{{^bodyParam}} {{#formParams}} {{#notFile}} formParams[@"{{paramName}}"] = {{paramName}}; {{/notFile}}{{#isFile}} - requestContentType = @"multipart/form-data"; - if(bodyParam == nil) { - bodyParam = [[NSMutableArray alloc] init]; - } - if({{paramName}} != nil) { - [bodyParam addObject:{{paramName}}]; - {{paramName}}.paramName = @"{{baseName}}"; - } + files[@"{{paramName}}"] = {{paramName}}; {{/isFile}} - if(bodyParam == nil) { - bodyParam = [[NSMutableArray alloc] init]; - } - [bodyParam addObject:formParams]; {{/formParams}} {{/bodyParam}} @@ -192,6 +179,8 @@ static NSString * basePath = @"{{basePath}}"; return [self.apiClient requestWithCompletionBlock: requestUrl method: @"{{httpMethod}}" queryParams: queryParams + formParams: formParams + files: files body: bodyParam headerParams: headerParams authSettings: authSettings diff --git a/samples/client/petstore/objc/SwaggerClient/SWGApiClient.h b/samples/client/petstore/objc/SwaggerClient/SWGApiClient.h index 638e9b59952..5af4f2181e3 100644 --- a/samples/client/petstore/objc/SwaggerClient/SWGApiClient.h +++ b/samples/client/petstore/objc/SwaggerClient/SWGApiClient.h @@ -3,7 +3,6 @@ #import #import "SWGJSONResponseSerializer.h" #import "SWGJSONRequestSerializer.h" -#import "SWGFile.h" #import "SWGQueryParamCollection.h" #import "SWGConfiguration.h" @@ -198,6 +197,8 @@ extern NSString *const SWGResponseObjectErrorKey; -(NSNumber*) requestWithCompletionBlock:(NSString*) path method:(NSString*) method queryParams:(NSDictionary*) queryParams + formParams:(NSDictionary *) formParams + files:(NSDictionary *) files body:(id) body headerParams:(NSDictionary*) headerParams authSettings: (NSArray *) authSettings diff --git a/samples/client/petstore/objc/SwaggerClient/SWGApiClient.m b/samples/client/petstore/objc/SwaggerClient/SWGApiClient.m index febaac0fa72..3f35c52d849 100644 --- a/samples/client/petstore/objc/SwaggerClient/SWGApiClient.m +++ b/samples/client/petstore/objc/SwaggerClient/SWGApiClient.m @@ -348,16 +348,6 @@ static bool loggingEnabled = true; *querys = [NSDictionary dictionaryWithDictionary:querysWithAuth]; } -#pragma mark - Predicate methods - -- (BOOL) isDownloadFile:(NSString *)responseType { - if ([responseType isEqualToString:@"SWGFile*"]) { - return YES; - } else { - return NO; - } -} - #pragma mark - Deserialize methods - (id) deserialize:(id) data class:(NSString *) class { @@ -542,10 +532,11 @@ static bool loggingEnabled = true; else { filename = [NSString stringWithFormat:@"%@", [[NSProcessInfo processInfo] globallyUniqueString]]; } - + NSString *filepath = [directory stringByAppendingPathComponent:filename]; + NSURL *file = [NSURL fileURLWithPath:filepath]; - SWGFile *file = [[SWGFile alloc] initWithPath:filepath data:operation.responseData name:filename]; + [operation.responseData writeToURL:file atomically:YES]; completionBlock(file, nil); } failure:^(AFHTTPRequestOperation *operation, NSError *error) { @@ -573,6 +564,8 @@ static bool loggingEnabled = true; -(NSNumber*) requestWithCompletionBlock: (NSString*) path method: (NSString*) method queryParams: (NSDictionary*) queryParams + formParams: (NSDictionary *) formParams + files: (NSDictionary *) files body: (id) body headerParams: (NSDictionary*) headerParams authSettings: (NSArray *) authSettings @@ -606,66 +599,38 @@ static bool loggingEnabled = true; [self updateHeaderParams:&headerParams queryParams:&queryParams WithAuthSettings:authSettings]; NSMutableURLRequest * request = nil; - if (body != nil && [body isKindOfClass:[NSArray class]]){ - SWGFile * file; - NSMutableDictionary * params = [[NSMutableDictionary alloc] init]; - for(id obj in body) { - if([obj isKindOfClass:[SWGFile class]]) { - file = (SWGFile*) obj; - requestContentType = @"multipart/form-data"; - } - else if([obj isKindOfClass:[NSDictionary class]]) { - for(NSString * key in obj) { - params[key] = obj[key]; - } - } - } - NSString * urlString = [[NSURL URLWithString:path relativeToURL:self.baseURL] absoluteString]; - - // request with multipart form - if([requestContentType isEqualToString:@"multipart/form-data"]) { - request = [self.requestSerializer multipartFormRequestWithMethod: @"POST" - URLString: urlString - parameters: nil - constructingBodyWithBlock: ^(id formData) { - - for(NSString * key in params) { - NSData* data = [params[key] dataUsingEncoding:NSUTF8StringEncoding]; - [formData appendPartWithFormData: data name: key]; - } - - if (file) { - [formData appendPartWithFileData: [file data] - name: [file paramName] - fileName: [file name] - mimeType: [file mimeType]]; - } - - } - error:nil]; - } - // request with form parameters or json - else { - NSString* pathWithQueryParams = [self pathWithQueryParamsToString:path queryParams:queryParams]; - NSString* urlString = [[NSURL URLWithString:pathWithQueryParams relativeToURL:self.baseURL] absoluteString]; - - request = [self.requestSerializer requestWithMethod:method - URLString:urlString - parameters:params - error:nil]; - } - + NSString* pathWithQueryParams = [self pathWithQueryParamsToString:path queryParams:queryParams]; + NSString* urlString = [[NSURL URLWithString:pathWithQueryParams relativeToURL:self.baseURL] absoluteString]; + if (files.count > 0) { + request = [self.requestSerializer multipartFormRequestWithMethod:@"POST" + URLString:urlString + parameters:nil + constructingBodyWithBlock:^(id formData) { + [formParams enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) { + NSData *data = [obj dataUsingEncoding:NSUTF8StringEncoding]; + [formData appendPartWithFormData:data name:key]; + }]; + [files enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) { + NSURL *filePath = (NSURL *)obj; + [formData appendPartWithFileURL:filePath name:key error:nil]; + }]; + } error:nil]; } else { - NSString * pathWithQueryParams = [self pathWithQueryParamsToString:path queryParams:queryParams]; - NSString * urlString = [[NSURL URLWithString:pathWithQueryParams relativeToURL:self.baseURL] absoluteString]; - - request = [self.requestSerializer requestWithMethod: method - URLString: urlString - parameters: body - error: nil]; + if (formParams) { + request = [self.requestSerializer requestWithMethod:method + URLString:urlString + parameters:formParams + error:nil]; + } + if (body) { + request = [self.requestSerializer requestWithMethod:method + URLString:urlString + parameters:body + error:nil]; + } } - + BOOL hasHeaderParams = false; if(headerParams != nil && [headerParams count] > 0) { hasHeaderParams = true; @@ -695,7 +660,7 @@ static bool loggingEnabled = true; [request setHTTPShouldHandleCookies:NO]; NSNumber* requestId = [SWGApiClient queueRequest]; - if ([self isDownloadFile:responseType]) { + if ([responseType isEqualToString:@"NSURL*"]) { [self downloadOperationWithCompletionBlock:request requestId:requestId completionBlock:^(id data, NSError *error) { completionBlock(data, error); }]; @@ -709,3 +674,7 @@ static bool loggingEnabled = true; } @end + + + + diff --git a/samples/client/petstore/objc/SwaggerClient/SWGPetApi.h b/samples/client/petstore/objc/SwaggerClient/SWGPetApi.h index 257a7d1453e..e009300993d 100644 --- a/samples/client/petstore/objc/SwaggerClient/SWGPetApi.h +++ b/samples/client/petstore/objc/SwaggerClient/SWGPetApi.h @@ -1,6 +1,5 @@ #import #import "SWGPet.h" -#import "SWGFile.h" #import "SWGObject.h" #import "SWGApiClient.h" @@ -139,7 +138,7 @@ /// @return -(NSNumber*) uploadFileWithCompletionBlock :(NSNumber*) petId additionalMetadata:(NSString*) additionalMetadata - file:(SWGFile*) file + file:(NSURL*) file completionHandler: (void (^)(NSError* error))completionBlock; diff --git a/samples/client/petstore/objc/SwaggerClient/SWGPetApi.m b/samples/client/petstore/objc/SwaggerClient/SWGPetApi.m index 33c38b8ed2c..0933016d638 100644 --- a/samples/client/petstore/objc/SwaggerClient/SWGPetApi.m +++ b/samples/client/petstore/objc/SwaggerClient/SWGPetApi.m @@ -2,7 +2,6 @@ #import "SWGFile.h" #import "SWGQueryParamCollection.h" #import "SWGPet.h" -#import "SWGFile.h" @interface SWGPetApi () @@ -123,6 +122,8 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; NSArray *authSettings = @[@"petstore_auth"]; id bodyParam = nil; + NSMutableDictionary *formParams = [[NSMutableDictionary alloc] init]; + NSMutableDictionary *files = [[NSMutableDictionary alloc] init]; bodyParam = body; @@ -142,12 +143,13 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; bodyParam = [(SWGObject*)bodyParam toDictionary]; } - return [self.apiClient requestWithCompletionBlock: requestUrl method: @"PUT" queryParams: queryParams + formParams: formParams + files: files body: bodyParam headerParams: headerParams authSettings: authSettings @@ -211,6 +213,8 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; NSArray *authSettings = @[@"petstore_auth"]; id bodyParam = nil; + NSMutableDictionary *formParams = [[NSMutableDictionary alloc] init]; + NSMutableDictionary *files = [[NSMutableDictionary alloc] init]; bodyParam = body; @@ -230,12 +234,13 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; bodyParam = [(SWGObject*)bodyParam toDictionary]; } - return [self.apiClient requestWithCompletionBlock: requestUrl method: @"POST" queryParams: queryParams + formParams: formParams + files: files body: bodyParam headerParams: headerParams authSettings: authSettings @@ -305,18 +310,18 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; NSArray *authSettings = @[@"petstore_auth"]; id bodyParam = nil; + NSMutableDictionary *formParams = [[NSMutableDictionary alloc] init]; + NSMutableDictionary *files = [[NSMutableDictionary alloc] init]; - - NSMutableDictionary * formParams = [[NSMutableDictionary alloc]init]; - - return [self.apiClient requestWithCompletionBlock: requestUrl method: @"GET" queryParams: queryParams + formParams: formParams + files: files body: bodyParam headerParams: headerParams authSettings: authSettings @@ -386,18 +391,18 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; NSArray *authSettings = @[@"petstore_auth"]; id bodyParam = nil; + NSMutableDictionary *formParams = [[NSMutableDictionary alloc] init]; + NSMutableDictionary *files = [[NSMutableDictionary alloc] init]; - - NSMutableDictionary * formParams = [[NSMutableDictionary alloc]init]; - - return [self.apiClient requestWithCompletionBlock: requestUrl method: @"GET" queryParams: queryParams + formParams: formParams + files: files body: bodyParam headerParams: headerParams authSettings: authSettings @@ -467,18 +472,18 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; NSArray *authSettings = @[@"api_key", @"petstore_auth"]; id bodyParam = nil; + NSMutableDictionary *formParams = [[NSMutableDictionary alloc] init]; + NSMutableDictionary *files = [[NSMutableDictionary alloc] init]; - - NSMutableDictionary * formParams = [[NSMutableDictionary alloc]init]; - - return [self.apiClient requestWithCompletionBlock: requestUrl method: @"GET" queryParams: queryParams + formParams: formParams + files: files body: bodyParam headerParams: headerParams authSettings: authSettings @@ -554,27 +559,17 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; NSArray *authSettings = @[@"petstore_auth"]; id bodyParam = nil; + NSMutableDictionary *formParams = [[NSMutableDictionary alloc] init]; + NSMutableDictionary *files = [[NSMutableDictionary alloc] init]; - - NSMutableDictionary * formParams = [[NSMutableDictionary alloc]init]; - - formParams[@"name"] = name; - if(bodyParam == nil) { - bodyParam = [[NSMutableArray alloc] init]; - } - [bodyParam addObject:formParams]; formParams[@"status"] = status; - if(bodyParam == nil) { - bodyParam = [[NSMutableArray alloc] init]; - } - [bodyParam addObject:formParams]; @@ -582,6 +577,8 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; return [self.apiClient requestWithCompletionBlock: requestUrl method: @"POST" queryParams: queryParams + formParams: formParams + files: files body: bodyParam headerParams: headerParams authSettings: authSettings @@ -656,18 +653,18 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; NSArray *authSettings = @[@"petstore_auth"]; id bodyParam = nil; + NSMutableDictionary *formParams = [[NSMutableDictionary alloc] init]; + NSMutableDictionary *files = [[NSMutableDictionary alloc] init]; - - NSMutableDictionary * formParams = [[NSMutableDictionary alloc]init]; - - return [self.apiClient requestWithCompletionBlock: requestUrl method: @"DELETE" queryParams: queryParams + formParams: formParams + files: files body: bodyParam headerParams: headerParams authSettings: authSettings @@ -694,7 +691,7 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; /// -(NSNumber*) uploadFileWithCompletionBlock: (NSNumber*) petId additionalMetadata: (NSString*) additionalMetadata - file: (SWGFile*) file + file: (NSURL*) file completionHandler: (void (^)(NSError* error))completionBlock { @@ -743,34 +740,17 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; NSArray *authSettings = @[@"petstore_auth"]; id bodyParam = nil; + NSMutableDictionary *formParams = [[NSMutableDictionary alloc] init]; + NSMutableDictionary *files = [[NSMutableDictionary alloc] init]; - - NSMutableDictionary * formParams = [[NSMutableDictionary alloc]init]; - - formParams[@"additionalMetadata"] = additionalMetadata; - if(bodyParam == nil) { - bodyParam = [[NSMutableArray alloc] init]; - } - [bodyParam addObject:formParams]; - requestContentType = @"multipart/form-data"; - if(bodyParam == nil) { - bodyParam = [[NSMutableArray alloc] init]; - } - if(file != nil) { - [bodyParam addObject:file]; - file.paramName = @"file"; - } + files[@"file"] = file; - if(bodyParam == nil) { - bodyParam = [[NSMutableArray alloc] init]; - } - [bodyParam addObject:formParams]; @@ -778,6 +758,8 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; return [self.apiClient requestWithCompletionBlock: requestUrl method: @"POST" queryParams: queryParams + formParams: formParams + files: files body: bodyParam headerParams: headerParams authSettings: authSettings diff --git a/samples/client/petstore/objc/SwaggerClient/SWGStoreApi.m b/samples/client/petstore/objc/SwaggerClient/SWGStoreApi.m index 85a0afe47b0..040f7236a3d 100644 --- a/samples/client/petstore/objc/SwaggerClient/SWGStoreApi.m +++ b/samples/client/petstore/objc/SwaggerClient/SWGStoreApi.m @@ -119,18 +119,18 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; NSArray *authSettings = @[@"api_key"]; id bodyParam = nil; + NSMutableDictionary *formParams = [[NSMutableDictionary alloc] init]; + NSMutableDictionary *files = [[NSMutableDictionary alloc] init]; - - NSMutableDictionary * formParams = [[NSMutableDictionary alloc]init]; - - return [self.apiClient requestWithCompletionBlock: requestUrl method: @"GET" queryParams: queryParams + formParams: formParams + files: files body: bodyParam headerParams: headerParams authSettings: authSettings @@ -194,6 +194,8 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; NSArray *authSettings = @[]; id bodyParam = nil; + NSMutableDictionary *formParams = [[NSMutableDictionary alloc] init]; + NSMutableDictionary *files = [[NSMutableDictionary alloc] init]; bodyParam = body; @@ -213,12 +215,13 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; bodyParam = [(SWGObject*)bodyParam toDictionary]; } - return [self.apiClient requestWithCompletionBlock: requestUrl method: @"POST" queryParams: queryParams + formParams: formParams + files: files body: bodyParam headerParams: headerParams authSettings: authSettings @@ -288,18 +291,18 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; NSArray *authSettings = @[]; id bodyParam = nil; + NSMutableDictionary *formParams = [[NSMutableDictionary alloc] init]; + NSMutableDictionary *files = [[NSMutableDictionary alloc] init]; - - NSMutableDictionary * formParams = [[NSMutableDictionary alloc]init]; - - return [self.apiClient requestWithCompletionBlock: requestUrl method: @"GET" queryParams: queryParams + formParams: formParams + files: files body: bodyParam headerParams: headerParams authSettings: authSettings @@ -369,18 +372,18 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; NSArray *authSettings = @[]; id bodyParam = nil; + NSMutableDictionary *formParams = [[NSMutableDictionary alloc] init]; + NSMutableDictionary *files = [[NSMutableDictionary alloc] init]; - - NSMutableDictionary * formParams = [[NSMutableDictionary alloc]init]; - - return [self.apiClient requestWithCompletionBlock: requestUrl method: @"DELETE" queryParams: queryParams + formParams: formParams + files: files body: bodyParam headerParams: headerParams authSettings: authSettings diff --git a/samples/client/petstore/objc/SwaggerClient/SWGUserApi.m b/samples/client/petstore/objc/SwaggerClient/SWGUserApi.m index d28d94011b7..3a0e7b8bb40 100644 --- a/samples/client/petstore/objc/SwaggerClient/SWGUserApi.m +++ b/samples/client/petstore/objc/SwaggerClient/SWGUserApi.m @@ -122,6 +122,8 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; NSArray *authSettings = @[]; id bodyParam = nil; + NSMutableDictionary *formParams = [[NSMutableDictionary alloc] init]; + NSMutableDictionary *files = [[NSMutableDictionary alloc] init]; bodyParam = body; @@ -141,12 +143,13 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; bodyParam = [(SWGObject*)bodyParam toDictionary]; } - return [self.apiClient requestWithCompletionBlock: requestUrl method: @"POST" queryParams: queryParams + formParams: formParams + files: files body: bodyParam headerParams: headerParams authSettings: authSettings @@ -210,6 +213,8 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; NSArray *authSettings = @[]; id bodyParam = nil; + NSMutableDictionary *formParams = [[NSMutableDictionary alloc] init]; + NSMutableDictionary *files = [[NSMutableDictionary alloc] init]; bodyParam = body; @@ -229,12 +234,13 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; bodyParam = [(SWGObject*)bodyParam toDictionary]; } - return [self.apiClient requestWithCompletionBlock: requestUrl method: @"POST" queryParams: queryParams + formParams: formParams + files: files body: bodyParam headerParams: headerParams authSettings: authSettings @@ -298,6 +304,8 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; NSArray *authSettings = @[]; id bodyParam = nil; + NSMutableDictionary *formParams = [[NSMutableDictionary alloc] init]; + NSMutableDictionary *files = [[NSMutableDictionary alloc] init]; bodyParam = body; @@ -317,12 +325,13 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; bodyParam = [(SWGObject*)bodyParam toDictionary]; } - return [self.apiClient requestWithCompletionBlock: requestUrl method: @"POST" queryParams: queryParams + formParams: formParams + files: files body: bodyParam headerParams: headerParams authSettings: authSettings @@ -397,18 +406,18 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; NSArray *authSettings = @[]; id bodyParam = nil; + NSMutableDictionary *formParams = [[NSMutableDictionary alloc] init]; + NSMutableDictionary *files = [[NSMutableDictionary alloc] init]; - - NSMutableDictionary * formParams = [[NSMutableDictionary alloc]init]; - - return [self.apiClient requestWithCompletionBlock: requestUrl method: @"GET" queryParams: queryParams + formParams: formParams + files: files body: bodyParam headerParams: headerParams authSettings: authSettings @@ -469,18 +478,18 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; NSArray *authSettings = @[]; id bodyParam = nil; + NSMutableDictionary *formParams = [[NSMutableDictionary alloc] init]; + NSMutableDictionary *files = [[NSMutableDictionary alloc] init]; - - NSMutableDictionary * formParams = [[NSMutableDictionary alloc]init]; - - return [self.apiClient requestWithCompletionBlock: requestUrl method: @"GET" queryParams: queryParams + formParams: formParams + files: files body: bodyParam headerParams: headerParams authSettings: authSettings @@ -550,18 +559,18 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; NSArray *authSettings = @[]; id bodyParam = nil; + NSMutableDictionary *formParams = [[NSMutableDictionary alloc] init]; + NSMutableDictionary *files = [[NSMutableDictionary alloc] init]; - - NSMutableDictionary * formParams = [[NSMutableDictionary alloc]init]; - - return [self.apiClient requestWithCompletionBlock: requestUrl method: @"GET" queryParams: queryParams + formParams: formParams + files: files body: bodyParam headerParams: headerParams authSettings: authSettings @@ -634,6 +643,8 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; NSArray *authSettings = @[]; id bodyParam = nil; + NSMutableDictionary *formParams = [[NSMutableDictionary alloc] init]; + NSMutableDictionary *files = [[NSMutableDictionary alloc] init]; bodyParam = body; @@ -653,12 +664,13 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; bodyParam = [(SWGObject*)bodyParam toDictionary]; } - return [self.apiClient requestWithCompletionBlock: requestUrl method: @"PUT" queryParams: queryParams + formParams: formParams + files: files body: bodyParam headerParams: headerParams authSettings: authSettings @@ -728,18 +740,18 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; NSArray *authSettings = @[]; id bodyParam = nil; + NSMutableDictionary *formParams = [[NSMutableDictionary alloc] init]; + NSMutableDictionary *files = [[NSMutableDictionary alloc] init]; - - NSMutableDictionary * formParams = [[NSMutableDictionary alloc]init]; - - return [self.apiClient requestWithCompletionBlock: requestUrl method: @"DELETE" queryParams: queryParams + formParams: formParams + files: files body: bodyParam headerParams: headerParams authSettings: authSettings diff --git a/samples/client/petstore/objc/SwaggerClientTests/SwaggerClient.xcodeproj/project.xcworkspace/xcshareddata/SwaggerClient.xccheckout b/samples/client/petstore/objc/SwaggerClientTests/SwaggerClient.xcodeproj/project.xcworkspace/xcshareddata/SwaggerClient.xccheckout new file mode 100644 index 00000000000..879945048b3 --- /dev/null +++ b/samples/client/petstore/objc/SwaggerClientTests/SwaggerClient.xcodeproj/project.xcworkspace/xcshareddata/SwaggerClient.xccheckout @@ -0,0 +1,41 @@ + + + + + IDESourceControlProjectFavoriteDictionaryKey + + IDESourceControlProjectIdentifier + 303FE0A9-4715-4C57-8D01-F604EF82CF6D + IDESourceControlProjectName + SwaggerClient + IDESourceControlProjectOriginsDictionary + + E5BBF0AA85077C865C95437976D06D819733A208 + https://github.com/geekerzp/swagger-codegen.git + + IDESourceControlProjectPath + samples/client/petstore/objc/SwaggerClientTests/SwaggerClient.xcodeproj + IDESourceControlProjectRelativeInstallPathDictionary + + E5BBF0AA85077C865C95437976D06D819733A208 + ../../../../../../.. + + IDESourceControlProjectURL + https://github.com/geekerzp/swagger-codegen.git + IDESourceControlProjectVersion + 111 + IDESourceControlProjectWCCIdentifier + E5BBF0AA85077C865C95437976D06D819733A208 + IDESourceControlProjectWCConfigurations + + + IDESourceControlRepositoryExtensionIdentifierKey + public.vcs.git + IDESourceControlWCCIdentifierKey + E5BBF0AA85077C865C95437976D06D819733A208 + IDESourceControlWCCName + swagger-codegen + + + + diff --git a/samples/client/petstore/objc/SwaggerClientTests/SwaggerClient.xcodeproj/project.xcworkspace/xcuserdata/geekerzp.xcuserdatad/UserInterfaceState.xcuserstate b/samples/client/petstore/objc/SwaggerClientTests/SwaggerClient.xcodeproj/project.xcworkspace/xcuserdata/geekerzp.xcuserdatad/UserInterfaceState.xcuserstate new file mode 100644 index 00000000000..4b91a2c5500 Binary files /dev/null and b/samples/client/petstore/objc/SwaggerClientTests/SwaggerClient.xcodeproj/project.xcworkspace/xcuserdata/geekerzp.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/samples/client/petstore/objc/SwaggerClientTests/Tests/PetApiTest.m b/samples/client/petstore/objc/SwaggerClientTests/Tests/PetApiTest.m index 64527d1abcb..8b0a5a10bb2 100644 --- a/samples/client/petstore/objc/SwaggerClientTests/Tests/PetApiTest.m +++ b/samples/client/petstore/objc/SwaggerClientTests/Tests/PetApiTest.m @@ -219,14 +219,11 @@ } - (void)testUploadFile { - XCTestExpectation *expectation = [self expectationWithDescription:@"testUploadFile"]; - - NSString* str = @"teststring"; - NSData* data = [str dataUsingEncoding:NSUTF8StringEncoding]; + XCTestExpectation *expectation = [self expectationWithDescription:@"testUploadWithFile"]; - SWGFile * file = [[SWGFile alloc] initWithNameData: @"myFile.txt" mimeType:@"text/plain" data:data]; + NSURL *fileURL = [self createTempFile]; - [api uploadFileWithCompletionBlock:@1 additionalMetadata:@"special-metadata" file:file completionHandler:^(NSError *error) { + [api uploadFileWithCompletionBlock:@1 additionalMetadata:@"special-metadata" file:fileURL completionHandler:^(NSError *error) { if(error) { // good XCTFail(@"expected a failure"); @@ -278,4 +275,12 @@ pet.photoUrls = photos; return pet; } + +- (NSURL *) createTempFile { + NSString *filePath = [NSTemporaryDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"%@", [[NSProcessInfo processInfo] globallyUniqueString]]]; + NSData *data = [@"test string" dataUsingEncoding:NSUTF8StringEncoding]; + [data writeToFile:filePath atomically:YES]; + + return [NSURL fileURLWithPath:filePath]; +} @end