From 0da3e58fffb324e5821978c85d6a6d3b962f71dd Mon Sep 17 00:00:00 2001 From: geekerzp Date: Fri, 12 Jun 2015 14:48:02 +0800 Subject: [PATCH] Support map response for objc client. not completed --- .../codegen/languages/ObjcClientCodegen.java | 16 +- ...ApiClient.m => SWGApiClient-body.mustache} | 260 +++++--------- ...iClient.h => SWGApiClient-header.mustache} | 54 ++- .../src/main/resources/objc/api-body.mustache | 34 +- .../apiBodyResponseWithContainer.mustache | 7 + .../src/test/scala/Objc/ObjcModelTest.scala | 4 +- .../petstore/objc/client/SWGApiClient.h | 58 ++- .../petstore/objc/client/SWGApiClient.m | 260 +++++--------- .../client/petstore/objc/client/SWGPetApi.m | 338 ++++++------------ .../client/petstore/objc/client/SWGStoreApi.h | 4 +- .../client/petstore/objc/client/SWGStoreApi.m | 187 +++------- .../client/petstore/objc/client/SWGUserApi.m | 323 ++++++----------- 12 files changed, 539 insertions(+), 1006 deletions(-) rename modules/swagger-codegen/src/main/resources/objc/{SWGApiClient.m => SWGApiClient-body.mustache} (70%) rename modules/swagger-codegen/src/main/resources/objc/{SWGApiClient.h => SWGApiClient-header.mustache} (72%) 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 01f72040bf53..ce3ec0650129 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 @@ -143,15 +143,15 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig { supportingFiles.add(new SupportingFile("SWGObject.m", sourceFolder, "SWGObject.m")); supportingFiles.add(new SupportingFile("SWGQueryParamCollection.h", sourceFolder, "SWGQueryParamCollection.h")); supportingFiles.add(new SupportingFile("SWGQueryParamCollection.m", sourceFolder, "SWGQueryParamCollection.m")); - supportingFiles.add(new SupportingFile("SWGApiClient.h", sourceFolder, "SWGApiClient.h")); - supportingFiles.add(new SupportingFile("SWGApiClient.m", sourceFolder, "SWGApiClient.m")); + supportingFiles.add(new SupportingFile("SWGApiClient-header.mustache", sourceFolder, "SWGApiClient.h")); + supportingFiles.add(new SupportingFile("SWGApiClient-body.mustache", sourceFolder, "SWGApiClient.m")); supportingFiles.add(new SupportingFile("SWGFile.h", sourceFolder, "SWGFile.h")); supportingFiles.add(new SupportingFile("SWGFile.m", sourceFolder, "SWGFile.m")); supportingFiles.add(new SupportingFile("JSONValueTransformer+ISO8601.m", sourceFolder, "JSONValueTransformer+ISO8601.m")); supportingFiles.add(new SupportingFile("JSONValueTransformer+ISO8601.h", sourceFolder, "JSONValueTransformer+ISO8601.h")); supportingFiles.add(new SupportingFile("SWGConfiguration-body.mustache", sourceFolder, "SWGConfiguration.m")); supportingFiles.add(new SupportingFile("SWGConfiguration-header.mustache", sourceFolder, "SWGConfiguration.h")); - supportingFiles.add(new SupportingFile("Podfile.mustache", "", "Podfile")); + // supportingFiles.add(new SupportingFile("Podfile.mustache", "", "Podfile")); } @Override @@ -215,6 +215,16 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig { } return getSwaggerType(p) + "<" + innerTypeDeclaration + ">*"; + } else if (p instanceof MapProperty) { + MapProperty mp = (MapProperty) p; + Property inner = mp.getAdditionalProperties(); + + String innerTypeDeclaration = getTypeDeclaration(inner); + + if (innerTypeDeclaration.endsWith("*")) { + innerTypeDeclaration = innerTypeDeclaration.substring(0, innerTypeDeclaration.length() - 1); + } + return getSwaggerType(p) + "* /* NSString, " + innerTypeDeclaration + " */"; } else { String swaggerType = getSwaggerType(p); diff --git a/modules/swagger-codegen/src/main/resources/objc/SWGApiClient.m b/modules/swagger-codegen/src/main/resources/objc/SWGApiClient-body.mustache similarity index 70% rename from modules/swagger-codegen/src/main/resources/objc/SWGApiClient.m rename to modules/swagger-codegen/src/main/resources/objc/SWGApiClient-body.mustache index 5e2985bbe792..ee8be40e2abe 100644 --- a/modules/swagger-codegen/src/main/resources/objc/SWGApiClient.m +++ b/modules/swagger-codegen/src/main/resources/objc/SWGApiClient-body.mustache @@ -351,179 +351,114 @@ static bool loggingEnabled = true; *querys = [NSDictionary dictionaryWithDictionary:querysWithAuth]; } -#pragma mark - Perform Request Methods --(NSNumber*) dictionary: (NSString*) path - method: (NSString*) method - queryParams: (NSDictionary*) queryParams - body: (id) body - headerParams: (NSDictionary*) headerParams - authSettings: (NSArray *) authSettings - requestContentType: (NSString*) requestContentType - responseContentType: (NSString*) responseContentType - completionBlock: (void (^)(NSDictionary*, NSError *))completionBlock { - // setting request serializer - if ([requestContentType isEqualToString:@"application/json"]) { - self.requestSerializer = [AFJSONRequestSerializer serializer]; - } - else if ([requestContentType isEqualToString:@"application/x-www-form-urlencoded"]) { - self.requestSerializer = [AFHTTPRequestSerializer serializer]; - } - else if ([requestContentType isEqualToString:@"multipart/form-data"]) { - self.requestSerializer = [AFHTTPRequestSerializer serializer]; - } - else { - NSAssert(false, @"unsupport request type %@", requestContentType); +- (id) deserialize:(id) data class:(NSString *) class { + NSRegularExpression *regexp = nil; + NSTextCheckingResult *match = nil; + NSMutableArray *resultArray = nil; + NSMutableDictionary *resultDict = nil; + + // list of models + NSString *arrayOfModelsPat = @"NSArray<(.+)>"; + regexp = [NSRegularExpression regularExpressionWithPattern:arrayOfModelsPat + options:NSRegularExpressionCaseInsensitive + error:nil]; + + match = [regexp firstMatchInString:class + options:0 + range:NSMakeRange(0, [class length])]; + + if (match) { + NSString *innerType = [class substringWithRange:[match rangeAtIndex:1]]; + + resultArray = [NSMutableArray arrayWithCapacity:[data length]]; + [data enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { + [resultArray addObject:[self deserialize:obj class:innerType]]; + } + ]; + + return resultArray; } - // setting response serializer - if ([responseContentType isEqualToString:@"application/json"]) { - self.responseSerializer = [AFJSONResponseSerializer serializer]; + // list of primitives + NSString *arrayOfPrimitivesPet = @"NSArray"; + regexp = [NSRegularExpression regularExpressionWithPattern:arrayOfPrimitivesPet + options:NSRegularExpressionCaseInsensitive + error:nil]; + match = [regexp firstMatchInString:class + options:0 + range:NSMakeRange(0, [class length])]; + + if (match) { + resultArray = [NSMutableArray arrayWithCapacity:[data length]]; + [data enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { + [resultArray addObject:[self deserialize:obj class:NSStringFromClass([obj class])]]; + }]; + + return resultArray; } - else { - self.responseSerializer = [AFHTTPResponseSerializer serializer]; + + // map + NSString *dictPat = @"NSDictionary /\\* (.+), (.+) \\*/"; + regexp = [NSRegularExpression regularExpressionWithPattern:dictPat + options:NSRegularExpressionCaseInsensitive + error:nil]; + match = [regexp firstMatchInString:class + options:0 + range:NSMakeRange(0, [class length])]; + + if (match) { + NSString *valueType = [class substringWithRange:[match rangeAtIndex:2]]; + + resultDict = [NSMutableDictionary dictionaryWithCapacity:[data count]]; + [data enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) { + [resultDict setValue:[self deserialize:obj class:valueType] forKey:key]; + }]; + + return resultDict; } - // auth setting - [self updateHeaderParams:&headerParams queryParams:&queryParams WithAuthSettings:authSettings]; + // primitives + NSArray *primitiveTypes = @[@"NSString", @"NSDate", @"BOOL", @"NSNumber"]; - 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]; - } - } + if ([primitiveTypes containsObject:class]) { + if ([class isEqualToString:@"NSString"]) { + return [NSString stringWithString:data]; } - 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]; + else if ([class isEqualToString:@"NSDate"]) { + return [NSDate dateWithISO8601String:data]; } - // 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]; + else if ([class isEqualToString:@"BOOL"]) { + // Returns YES on encountering one of "Y", "y", "T", "t", or a + // digit 1-9—the method ignores any trailing characters + // NSString => BOOL => NSNumber + return [NSNumber numberWithBool:[data boolValue]]; + } + else if ([class isEqualToString:@"NSNumber"]) { + return [data numberFromString:data]; } } - 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]; - } - BOOL hasHeaderParams = false; - if(headerParams != nil && [headerParams count] > 0) - hasHeaderParams = true; - if(offlineState) { - NSLog(@"%@ cache forced", path); - [request setCachePolicy:NSURLRequestReturnCacheDataDontLoad]; - } - else if(!hasHeaderParams && [method isEqualToString:@"GET"] && cacheEnabled) { - NSLog(@"%@ cache enabled", path); - [request setCachePolicy:NSURLRequestUseProtocolCachePolicy]; - } - else { - NSLog(@"%@ cache disabled", path); - [request setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData]; + + // model + Class ModelClass = NSClassFromString(class); + if ([ModelClass instancesRespondToSelector:@selector(initWithDictionary:error:)]) { + return [[ModelClass alloc] initWithDictionary:data error:nil]; } - if(body != nil) { - if([body isKindOfClass:[NSDictionary class]] || [body isKindOfClass:[NSArray class]]){ - [self.requestSerializer setValue:requestContentType forHTTPHeaderField:@"Content-Type"]; - } - else if ([body isKindOfClass:[SWGFile class]]) {} - else { - NSAssert(false, @"unsupported post type!"); - } - } - if(headerParams != nil){ - for(NSString * key in [headerParams keyEnumerator]){ - [request setValue:[headerParams valueForKey:key] forHTTPHeaderField:key]; - } - } - [self.requestSerializer setValue:responseContentType forHTTPHeaderField:@"Accept"]; - - // Always disable cookies! - [request setHTTPShouldHandleCookies:NO]; - - - if (self.logRequests) { - [self logRequest:request]; - } - - NSNumber* requestId = [SWGApiClient queueRequest]; - AFHTTPRequestOperation *op = - [self HTTPRequestOperationWithRequest:request - success:^(AFHTTPRequestOperation *operation, id JSON) { - if([self executeRequestWithId:requestId]) { - if(self.logServerResponses) - [self logResponse:JSON forRequest:request error:nil]; - completionBlock(JSON, nil); - } - } failure:^(AFHTTPRequestOperation *operation, NSError *error) { - if([self executeRequestWithId:requestId]) { - NSMutableDictionary *userInfo = [error.userInfo mutableCopy]; - if(operation.responseObject) { - // Add in the (parsed) response body. - userInfo[SWGResponseObjectErrorKey] = operation.responseObject; - } - NSError *augmentedError = [error initWithDomain:error.domain code:error.code userInfo:userInfo]; - - if(self.logServerResponses) - [self logResponse:nil forRequest:request error:augmentedError]; - completionBlock(nil, augmentedError); - } - } - ]; - - [self.operationQueue addOperation:op]; - return requestId; + return nil; } --(NSNumber*) stringWithCompletionBlock: (NSString*) path - method: (NSString*) method - queryParams: (NSDictionary*) queryParams - body: (id) body - headerParams: (NSDictionary*) headerParams - authSettings: (NSArray *) authSettings - requestContentType: (NSString*) requestContentType - responseContentType: (NSString*) responseContentType - completionBlock: (void (^)(NSString*, NSError *))completionBlock { +#pragma mark - Perform Request Methods + +-(NSNumber*) requestWithCompletionBlock: (NSString*) path + method: (NSString*) method + queryParams: (NSDictionary*) queryParams + body: (id) body + headerParams: (NSDictionary*) headerParams + authSettings: (NSArray *) authSettings + requestContentType: (NSString*) requestContentType + responseContentType: (NSString*) responseContentType + completionBlock: (void (^)(id, NSError *))completionBlock { // setting request serializer if ([requestContentType isEqualToString:@"application/json"]) { self.requestSerializer = [AFJSONRequestSerializer serializer]; @@ -648,11 +583,11 @@ static bool loggingEnabled = true; NSNumber* requestId = [SWGApiClient queueRequest]; AFHTTPRequestOperation *op = [self HTTPRequestOperationWithRequest:request - success:^(AFHTTPRequestOperation *operation, id responseObject) { - NSString *response = [operation responseString]; + success:^(AFHTTPRequestOperation *operation, id response) { if([self executeRequestWithId:requestId]) { - if(self.logServerResponses) - [self logResponse:responseObject forRequest:request error:nil]; + if(self.logServerResponses) { + [self logResponse:response forRequest:request error:nil]; + } completionBlock(response, nil); } } failure:^(AFHTTPRequestOperation *operation, NSError *error) { @@ -683,3 +618,4 @@ static bool loggingEnabled = true; + diff --git a/modules/swagger-codegen/src/main/resources/objc/SWGApiClient.h b/modules/swagger-codegen/src/main/resources/objc/SWGApiClient-header.mustache similarity index 72% rename from modules/swagger-codegen/src/main/resources/objc/SWGApiClient.h rename to modules/swagger-codegen/src/main/resources/objc/SWGApiClient-header.mustache index 250811c4016c..09cb6fe57bd7 100644 --- a/modules/swagger-codegen/src/main/resources/objc/SWGApiClient.h +++ b/modules/swagger-codegen/src/main/resources/objc/SWGApiClient-header.mustache @@ -1,6 +1,10 @@ #import +#import #import "AFHTTPRequestOperationManager.h" +{{#models}}{{#model}}#import "{{classname}}.h" +{{/model}}{{/models}} + /** * A key for `NSError` user info dictionaries. * @@ -159,37 +163,16 @@ extern NSString *const SWGResponseObjectErrorKey; WithAuthSettings:(NSArray *)authSettings; /** - * Perform request + * Deserialize the given data to Objective-C object. * - * Request with non-empty response - * - * @param path Request url. - * @param method Request method. - * @param queryParams Request query parameters. - * @param body Request body. - * @param headerParams Request header parameters. - * @param authSettings Request authentication names. - * @param requestContentType Request content-type. - * @param responseContentType Response content-type. - * @param completionBlock The block will be executed when the request completed. - * - * @return The request id. + * @param data The data will be deserialized. + * @param class The type of objective-c object. */ --(NSNumber*) dictionary:(NSString*) path - method:(NSString*) method - queryParams:(NSDictionary*) queryParams - body:(id) body - headerParams:(NSDictionary*) headerParams - authSettings: (NSArray *) authSettings - requestContentType:(NSString*) requestContentType - responseContentType:(NSString*) responseContentType - completionBlock:(void (^)(NSDictionary*, NSError *))completionBlock; +- (id) deserialize:(id) data class:(NSString *) class; /** * Perform request * - * Request with empty response - * * @param path Request url. * @param method Request method. * @param queryParams Request query parameters. @@ -202,15 +185,18 @@ extern NSString *const SWGResponseObjectErrorKey; * * @return The request id. */ --(NSNumber*) stringWithCompletionBlock:(NSString*) path - method:(NSString*) method - queryParams:(NSDictionary*) queryParams - body:(id) body - headerParams:(NSDictionary*) headerParams - authSettings: (NSArray *) authSettings - requestContentType:(NSString*) requestContentType - responseContentType:(NSString*) responseContentType - completionBlock:(void (^)(NSString*, NSError *))completionBlock; +-(NSNumber*) requestWithCompletionBlock:(NSString*) path + method:(NSString*) method + queryParams:(NSDictionary*) queryParams + body:(id) body + headerParams:(NSDictionary*) headerParams + authSettings: (NSArray *) authSettings + requestContentType:(NSString*) requestContentType + responseContentType:(NSString*) responseContentType + completionBlock:(void (^)(id, NSError *))completionBlock; + + @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 40d75bd806b2..ba61a8b2c7c8 100644 --- a/modules/swagger-codegen/src/main/resources/objc/api-body.mustache +++ b/modules/swagger-codegen/src/main/resources/objc/api-body.mustache @@ -195,27 +195,19 @@ static NSString * basePath = @"{{basePath}}"; } {{/requiredParams}} {{/requiredParamCount}} - - {{#returnContainer}} - // response is in a container - {{>apiBodyResponseWithContainer}}{{/returnContainer}} - - {{#returnSimpleType}} - // non container response - - {{#returnTypeIsPrimitive}} - // primitive response - {{>apiPrimitiveResponse}}{{/returnTypeIsPrimitive}} - - {{#returnBaseType}} - // complex response - {{>apiNonPrimitiveResponse}}{{/returnBaseType}} - {{/returnSimpleType}} - - {{^returnSimpleType}}{{^returnContainer}} - // it's void - {{>voidResponse}} - {{/returnContainer}}{{/returnSimpleType}} + return [self.apiClient requestWithCompletionBlock: requestUrl + method: @"{{httpMethod}}" + queryParams: queryParams + body: bodyDictionary + headerParams: headerParams + authSettings: authSettings + requestContentType: requestContentType + responseContentType: responseContentType + completionBlock: ^(id data, NSError *error) { + {{^returnType}}completionBlock(error);{{/returnType}} + {{#returnType}}completionBlock([self.apiClient deserialize: data class:@"{{{returnType}}}"], error);{{/returnType}} + } + ]; } {{/operation}} diff --git a/modules/swagger-codegen/src/main/resources/objc/apiBodyResponseWithContainer.mustache b/modules/swagger-codegen/src/main/resources/objc/apiBodyResponseWithContainer.mustache index acaeaf2ddf5b..7d178353d52d 100644 --- a/modules/swagger-codegen/src/main/resources/objc/apiBodyResponseWithContainer.mustache +++ b/modules/swagger-codegen/src/main/resources/objc/apiBodyResponseWithContainer.mustache @@ -36,3 +36,10 @@ {{/isListContainer}} }]; + + + + + + + diff --git a/modules/swagger-codegen/src/test/scala/Objc/ObjcModelTest.scala b/modules/swagger-codegen/src/test/scala/Objc/ObjcModelTest.scala index 6cfac9a0eff5..6747b94d4f8e 100644 --- a/modules/swagger-codegen/src/test/scala/Objc/ObjcModelTest.scala +++ b/modules/swagger-codegen/src/test/scala/Objc/ObjcModelTest.scala @@ -118,7 +118,7 @@ class ObjcModelTest extends FlatSpec with Matchers { val vars = cm.vars vars.get(0).baseName should be("translations") - vars.get(0).datatype should be("NSDictionary*") + vars.get(0).datatype should be("NSDictionary* /* NSString, NSString */") vars.get(0).name should be("translations") vars.get(0).baseType should be("NSDictionary") vars.get(0).containerType should be("map") @@ -192,7 +192,7 @@ class ObjcModelTest extends FlatSpec with Matchers { val vars = cm.vars vars.get(0).baseName should be("children") vars.get(0).complexType should be("SWGChildren") - vars.get(0).datatype should be("NSDictionary*") + vars.get(0).datatype should be("NSDictionary* /* NSString, SWGChildren */") vars.get(0).name should be("children") vars.get(0).baseType should be("NSDictionary") vars.get(0).containerType should be("map") diff --git a/samples/client/petstore/objc/client/SWGApiClient.h b/samples/client/petstore/objc/client/SWGApiClient.h index 250811c4016c..829aec58b968 100644 --- a/samples/client/petstore/objc/client/SWGApiClient.h +++ b/samples/client/petstore/objc/client/SWGApiClient.h @@ -1,6 +1,14 @@ #import +#import #import "AFHTTPRequestOperationManager.h" +#import "SWGUser.h" +#import "SWGCategory.h" +#import "SWGPet.h" +#import "SWGTag.h" +#import "SWGOrder.h" + + /** * A key for `NSError` user info dictionaries. * @@ -159,37 +167,16 @@ extern NSString *const SWGResponseObjectErrorKey; WithAuthSettings:(NSArray *)authSettings; /** - * Perform request + * Deserialize the given data to Objective-C object. * - * Request with non-empty response - * - * @param path Request url. - * @param method Request method. - * @param queryParams Request query parameters. - * @param body Request body. - * @param headerParams Request header parameters. - * @param authSettings Request authentication names. - * @param requestContentType Request content-type. - * @param responseContentType Response content-type. - * @param completionBlock The block will be executed when the request completed. - * - * @return The request id. + * @param data The data will be deserialized. + * @param class The type of objective-c object. */ --(NSNumber*) dictionary:(NSString*) path - method:(NSString*) method - queryParams:(NSDictionary*) queryParams - body:(id) body - headerParams:(NSDictionary*) headerParams - authSettings: (NSArray *) authSettings - requestContentType:(NSString*) requestContentType - responseContentType:(NSString*) responseContentType - completionBlock:(void (^)(NSDictionary*, NSError *))completionBlock; +- (id) deserialize:(id) data class:(NSString *) class; /** * Perform request * - * Request with empty response - * * @param path Request url. * @param method Request method. * @param queryParams Request query parameters. @@ -202,15 +189,18 @@ extern NSString *const SWGResponseObjectErrorKey; * * @return The request id. */ --(NSNumber*) stringWithCompletionBlock:(NSString*) path - method:(NSString*) method - queryParams:(NSDictionary*) queryParams - body:(id) body - headerParams:(NSDictionary*) headerParams - authSettings: (NSArray *) authSettings - requestContentType:(NSString*) requestContentType - responseContentType:(NSString*) responseContentType - completionBlock:(void (^)(NSString*, NSError *))completionBlock; +-(NSNumber*) requestWithCompletionBlock:(NSString*) path + method:(NSString*) method + queryParams:(NSDictionary*) queryParams + body:(id) body + headerParams:(NSDictionary*) headerParams + authSettings: (NSArray *) authSettings + requestContentType:(NSString*) requestContentType + responseContentType:(NSString*) responseContentType + completionBlock:(void (^)(id, NSError *))completionBlock; + + @end + diff --git a/samples/client/petstore/objc/client/SWGApiClient.m b/samples/client/petstore/objc/client/SWGApiClient.m index 5e2985bbe792..ee8be40e2abe 100644 --- a/samples/client/petstore/objc/client/SWGApiClient.m +++ b/samples/client/petstore/objc/client/SWGApiClient.m @@ -351,179 +351,114 @@ static bool loggingEnabled = true; *querys = [NSDictionary dictionaryWithDictionary:querysWithAuth]; } -#pragma mark - Perform Request Methods --(NSNumber*) dictionary: (NSString*) path - method: (NSString*) method - queryParams: (NSDictionary*) queryParams - body: (id) body - headerParams: (NSDictionary*) headerParams - authSettings: (NSArray *) authSettings - requestContentType: (NSString*) requestContentType - responseContentType: (NSString*) responseContentType - completionBlock: (void (^)(NSDictionary*, NSError *))completionBlock { - // setting request serializer - if ([requestContentType isEqualToString:@"application/json"]) { - self.requestSerializer = [AFJSONRequestSerializer serializer]; - } - else if ([requestContentType isEqualToString:@"application/x-www-form-urlencoded"]) { - self.requestSerializer = [AFHTTPRequestSerializer serializer]; - } - else if ([requestContentType isEqualToString:@"multipart/form-data"]) { - self.requestSerializer = [AFHTTPRequestSerializer serializer]; - } - else { - NSAssert(false, @"unsupport request type %@", requestContentType); +- (id) deserialize:(id) data class:(NSString *) class { + NSRegularExpression *regexp = nil; + NSTextCheckingResult *match = nil; + NSMutableArray *resultArray = nil; + NSMutableDictionary *resultDict = nil; + + // list of models + NSString *arrayOfModelsPat = @"NSArray<(.+)>"; + regexp = [NSRegularExpression regularExpressionWithPattern:arrayOfModelsPat + options:NSRegularExpressionCaseInsensitive + error:nil]; + + match = [regexp firstMatchInString:class + options:0 + range:NSMakeRange(0, [class length])]; + + if (match) { + NSString *innerType = [class substringWithRange:[match rangeAtIndex:1]]; + + resultArray = [NSMutableArray arrayWithCapacity:[data length]]; + [data enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { + [resultArray addObject:[self deserialize:obj class:innerType]]; + } + ]; + + return resultArray; } - // setting response serializer - if ([responseContentType isEqualToString:@"application/json"]) { - self.responseSerializer = [AFJSONResponseSerializer serializer]; + // list of primitives + NSString *arrayOfPrimitivesPet = @"NSArray"; + regexp = [NSRegularExpression regularExpressionWithPattern:arrayOfPrimitivesPet + options:NSRegularExpressionCaseInsensitive + error:nil]; + match = [regexp firstMatchInString:class + options:0 + range:NSMakeRange(0, [class length])]; + + if (match) { + resultArray = [NSMutableArray arrayWithCapacity:[data length]]; + [data enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { + [resultArray addObject:[self deserialize:obj class:NSStringFromClass([obj class])]]; + }]; + + return resultArray; } - else { - self.responseSerializer = [AFHTTPResponseSerializer serializer]; + + // map + NSString *dictPat = @"NSDictionary /\\* (.+), (.+) \\*/"; + regexp = [NSRegularExpression regularExpressionWithPattern:dictPat + options:NSRegularExpressionCaseInsensitive + error:nil]; + match = [regexp firstMatchInString:class + options:0 + range:NSMakeRange(0, [class length])]; + + if (match) { + NSString *valueType = [class substringWithRange:[match rangeAtIndex:2]]; + + resultDict = [NSMutableDictionary dictionaryWithCapacity:[data count]]; + [data enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) { + [resultDict setValue:[self deserialize:obj class:valueType] forKey:key]; + }]; + + return resultDict; } - // auth setting - [self updateHeaderParams:&headerParams queryParams:&queryParams WithAuthSettings:authSettings]; + // primitives + NSArray *primitiveTypes = @[@"NSString", @"NSDate", @"BOOL", @"NSNumber"]; - 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]; - } - } + if ([primitiveTypes containsObject:class]) { + if ([class isEqualToString:@"NSString"]) { + return [NSString stringWithString:data]; } - 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]; + else if ([class isEqualToString:@"NSDate"]) { + return [NSDate dateWithISO8601String:data]; } - // 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]; + else if ([class isEqualToString:@"BOOL"]) { + // Returns YES on encountering one of "Y", "y", "T", "t", or a + // digit 1-9—the method ignores any trailing characters + // NSString => BOOL => NSNumber + return [NSNumber numberWithBool:[data boolValue]]; + } + else if ([class isEqualToString:@"NSNumber"]) { + return [data numberFromString:data]; } } - 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]; - } - BOOL hasHeaderParams = false; - if(headerParams != nil && [headerParams count] > 0) - hasHeaderParams = true; - if(offlineState) { - NSLog(@"%@ cache forced", path); - [request setCachePolicy:NSURLRequestReturnCacheDataDontLoad]; - } - else if(!hasHeaderParams && [method isEqualToString:@"GET"] && cacheEnabled) { - NSLog(@"%@ cache enabled", path); - [request setCachePolicy:NSURLRequestUseProtocolCachePolicy]; - } - else { - NSLog(@"%@ cache disabled", path); - [request setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData]; + + // model + Class ModelClass = NSClassFromString(class); + if ([ModelClass instancesRespondToSelector:@selector(initWithDictionary:error:)]) { + return [[ModelClass alloc] initWithDictionary:data error:nil]; } - if(body != nil) { - if([body isKindOfClass:[NSDictionary class]] || [body isKindOfClass:[NSArray class]]){ - [self.requestSerializer setValue:requestContentType forHTTPHeaderField:@"Content-Type"]; - } - else if ([body isKindOfClass:[SWGFile class]]) {} - else { - NSAssert(false, @"unsupported post type!"); - } - } - if(headerParams != nil){ - for(NSString * key in [headerParams keyEnumerator]){ - [request setValue:[headerParams valueForKey:key] forHTTPHeaderField:key]; - } - } - [self.requestSerializer setValue:responseContentType forHTTPHeaderField:@"Accept"]; - - // Always disable cookies! - [request setHTTPShouldHandleCookies:NO]; - - - if (self.logRequests) { - [self logRequest:request]; - } - - NSNumber* requestId = [SWGApiClient queueRequest]; - AFHTTPRequestOperation *op = - [self HTTPRequestOperationWithRequest:request - success:^(AFHTTPRequestOperation *operation, id JSON) { - if([self executeRequestWithId:requestId]) { - if(self.logServerResponses) - [self logResponse:JSON forRequest:request error:nil]; - completionBlock(JSON, nil); - } - } failure:^(AFHTTPRequestOperation *operation, NSError *error) { - if([self executeRequestWithId:requestId]) { - NSMutableDictionary *userInfo = [error.userInfo mutableCopy]; - if(operation.responseObject) { - // Add in the (parsed) response body. - userInfo[SWGResponseObjectErrorKey] = operation.responseObject; - } - NSError *augmentedError = [error initWithDomain:error.domain code:error.code userInfo:userInfo]; - - if(self.logServerResponses) - [self logResponse:nil forRequest:request error:augmentedError]; - completionBlock(nil, augmentedError); - } - } - ]; - - [self.operationQueue addOperation:op]; - return requestId; + return nil; } --(NSNumber*) stringWithCompletionBlock: (NSString*) path - method: (NSString*) method - queryParams: (NSDictionary*) queryParams - body: (id) body - headerParams: (NSDictionary*) headerParams - authSettings: (NSArray *) authSettings - requestContentType: (NSString*) requestContentType - responseContentType: (NSString*) responseContentType - completionBlock: (void (^)(NSString*, NSError *))completionBlock { +#pragma mark - Perform Request Methods + +-(NSNumber*) requestWithCompletionBlock: (NSString*) path + method: (NSString*) method + queryParams: (NSDictionary*) queryParams + body: (id) body + headerParams: (NSDictionary*) headerParams + authSettings: (NSArray *) authSettings + requestContentType: (NSString*) requestContentType + responseContentType: (NSString*) responseContentType + completionBlock: (void (^)(id, NSError *))completionBlock { // setting request serializer if ([requestContentType isEqualToString:@"application/json"]) { self.requestSerializer = [AFJSONRequestSerializer serializer]; @@ -648,11 +583,11 @@ static bool loggingEnabled = true; NSNumber* requestId = [SWGApiClient queueRequest]; AFHTTPRequestOperation *op = [self HTTPRequestOperationWithRequest:request - success:^(AFHTTPRequestOperation *operation, id responseObject) { - NSString *response = [operation responseString]; + success:^(AFHTTPRequestOperation *operation, id response) { if([self executeRequestWithId:requestId]) { - if(self.logServerResponses) - [self logResponse:responseObject forRequest:request error:nil]; + if(self.logServerResponses) { + [self logResponse:response forRequest:request error:nil]; + } completionBlock(response, nil); } } failure:^(AFHTTPRequestOperation *operation, NSError *error) { @@ -683,3 +618,4 @@ static bool loggingEnabled = true; + diff --git a/samples/client/petstore/objc/client/SWGPetApi.m b/samples/client/petstore/objc/client/SWGPetApi.m index c14da125af5b..8a03932001cd 100644 --- a/samples/client/petstore/objc/client/SWGPetApi.m +++ b/samples/client/petstore/objc/client/SWGPetApi.m @@ -153,30 +153,19 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; - - - - - - - // it's void - return [self.apiClient stringWithCompletionBlock: requestUrl - method: @"PUT" - queryParams: queryParams - body: bodyDictionary - headerParams: headerParams - authSettings: authSettings - requestContentType: requestContentType - responseContentType: responseContentType - completionBlock: ^(NSString *data, NSError *error) { - if (error) { - completionBlock(error); - return; - } - completionBlock(nil); - }]; - - + return [self.apiClient requestWithCompletionBlock: requestUrl + method: @"PUT" + queryParams: queryParams + body: bodyDictionary + headerParams: headerParams + authSettings: authSettings + requestContentType: requestContentType + responseContentType: responseContentType + completionBlock: ^(id data, NSError *error) { + completionBlock(error); + + } + ]; } /*! @@ -260,30 +249,19 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; - - - - - - - // it's void - return [self.apiClient stringWithCompletionBlock: requestUrl - method: @"POST" - queryParams: queryParams - body: bodyDictionary - headerParams: headerParams - authSettings: authSettings - requestContentType: requestContentType - responseContentType: responseContentType - completionBlock: ^(NSString *data, NSError *error) { - if (error) { - completionBlock(error); - return; - } - completionBlock(nil); - }]; - - + return [self.apiClient requestWithCompletionBlock: requestUrl + method: @"POST" + queryParams: queryParams + body: bodyDictionary + headerParams: headerParams + authSettings: authSettings + requestContentType: requestContentType + responseContentType: responseContentType + completionBlock: ^(id data, NSError *error) { + completionBlock(error); + + } + ]; } /*! @@ -350,44 +328,19 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; - - - // response is in a container - // array container response type - return [self.apiClient dictionary: requestUrl - method: @"GET" - queryParams: queryParams - body: bodyDictionary - headerParams: headerParams - authSettings: authSettings - requestContentType: requestContentType - responseContentType: responseContentType - completionBlock: ^(NSDictionary *data, NSError *error) { - if (error) { - completionBlock(nil, error); - return; - } - - if([data isKindOfClass:[NSArray class]]){ - NSMutableArray * objs = [[NSMutableArray alloc] initWithCapacity:[data count]]; - for (NSDictionary* dict in (NSArray*)data) { - - - SWGPet* d = [[SWGPet alloc] initWithDictionary:dict error:nil]; - - [objs addObject:d]; - } - completionBlock((NSArray*)objs, nil); - } - - - }]; - - - - - - + return [self.apiClient requestWithCompletionBlock: requestUrl + method: @"GET" + queryParams: queryParams + body: bodyDictionary + headerParams: headerParams + authSettings: authSettings + requestContentType: requestContentType + responseContentType: responseContentType + completionBlock: ^(id data, NSError *error) { + + completionBlock([self.apiClient deserialize: data class:@"NSArray*"], error); + } + ]; } /*! @@ -454,44 +407,19 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; - - - // response is in a container - // array container response type - return [self.apiClient dictionary: requestUrl - method: @"GET" - queryParams: queryParams - body: bodyDictionary - headerParams: headerParams - authSettings: authSettings - requestContentType: requestContentType - responseContentType: responseContentType - completionBlock: ^(NSDictionary *data, NSError *error) { - if (error) { - completionBlock(nil, error); - return; - } - - if([data isKindOfClass:[NSArray class]]){ - NSMutableArray * objs = [[NSMutableArray alloc] initWithCapacity:[data count]]; - for (NSDictionary* dict in (NSArray*)data) { - - - SWGPet* d = [[SWGPet alloc] initWithDictionary:dict error:nil]; - - [objs addObject:d]; - } - completionBlock((NSArray*)objs, nil); - } - - - }]; - - - - - - + return [self.apiClient requestWithCompletionBlock: requestUrl + method: @"GET" + queryParams: queryParams + body: bodyDictionary + headerParams: headerParams + authSettings: authSettings + requestContentType: requestContentType + responseContentType: responseContentType + completionBlock: ^(id data, NSError *error) { + + completionBlock([self.apiClient deserialize: data class:@"NSArray*"], error); + } + ]; } /*! @@ -556,44 +484,19 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; - - - - - // non container response - - - - - // complex response - - // comples response type - return [self.apiClient dictionary: requestUrl - method: @"GET" - queryParams: queryParams - body: bodyDictionary - headerParams: headerParams - authSettings: authSettings - requestContentType: requestContentType - responseContentType: responseContentType - completionBlock: ^(NSDictionary *data, NSError *error) { - if (error) { - completionBlock(nil, error); - - return; - } - SWGPet* result = nil; - if (data) { - result = [[SWGPet alloc] initWithDictionary:data error:nil]; - } - completionBlock(result , nil); - - }]; - - - - - + return [self.apiClient requestWithCompletionBlock: requestUrl + method: @"GET" + queryParams: queryParams + body: bodyDictionary + headerParams: headerParams + authSettings: authSettings + requestContentType: requestContentType + responseContentType: responseContentType + completionBlock: ^(id data, NSError *error) { + + completionBlock([self.apiClient deserialize: data class:@"SWGPet*"], error); + } + ]; } /*! @@ -678,30 +581,19 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; - - - - - - - // it's void - return [self.apiClient stringWithCompletionBlock: requestUrl - method: @"POST" - queryParams: queryParams - body: bodyDictionary - headerParams: headerParams - authSettings: authSettings - requestContentType: requestContentType - responseContentType: responseContentType - completionBlock: ^(NSString *data, NSError *error) { - if (error) { - completionBlock(error); - return; - } - completionBlock(nil); - }]; - - + return [self.apiClient requestWithCompletionBlock: requestUrl + method: @"POST" + queryParams: queryParams + body: bodyDictionary + headerParams: headerParams + authSettings: authSettings + requestContentType: requestContentType + responseContentType: responseContentType + completionBlock: ^(id data, NSError *error) { + completionBlock(error); + + } + ]; } /*! @@ -770,30 +662,19 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; - - - - - - - // it's void - return [self.apiClient stringWithCompletionBlock: requestUrl - method: @"DELETE" - queryParams: queryParams - body: bodyDictionary - headerParams: headerParams - authSettings: authSettings - requestContentType: requestContentType - responseContentType: responseContentType - completionBlock: ^(NSString *data, NSError *error) { - if (error) { - completionBlock(error); - return; - } - completionBlock(nil); - }]; - - + return [self.apiClient requestWithCompletionBlock: requestUrl + method: @"DELETE" + queryParams: queryParams + body: bodyDictionary + headerParams: headerParams + authSettings: authSettings + requestContentType: requestContentType + responseContentType: responseContentType + completionBlock: ^(id data, NSError *error) { + completionBlock(error); + + } + ]; } /*! @@ -885,30 +766,19 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; - - - - - - - // it's void - return [self.apiClient stringWithCompletionBlock: requestUrl - method: @"POST" - queryParams: queryParams - body: bodyDictionary - headerParams: headerParams - authSettings: authSettings - requestContentType: requestContentType - responseContentType: responseContentType - completionBlock: ^(NSString *data, NSError *error) { - if (error) { - completionBlock(error); - return; - } - completionBlock(nil); - }]; - - + return [self.apiClient requestWithCompletionBlock: requestUrl + method: @"POST" + queryParams: queryParams + body: bodyDictionary + headerParams: headerParams + authSettings: authSettings + requestContentType: requestContentType + responseContentType: responseContentType + completionBlock: ^(id data, NSError *error) { + completionBlock(error); + + } + ]; } diff --git a/samples/client/petstore/objc/client/SWGStoreApi.h b/samples/client/petstore/objc/client/SWGStoreApi.h index 49d8db806c80..b7d644695326 100644 --- a/samples/client/petstore/objc/client/SWGStoreApi.h +++ b/samples/client/petstore/objc/client/SWGStoreApi.h @@ -21,10 +21,10 @@ - return type: NSDictionary* + return type: NSDictionary* /* NSString, NSNumber */ */ -(NSNumber*) getInventoryWithCompletionBlock : - (void (^)(NSDictionary* output, NSError* error))completionBlock; + (void (^)(NSDictionary* /* NSString, NSNumber */ output, NSError* error))completionBlock; diff --git a/samples/client/petstore/objc/client/SWGStoreApi.m b/samples/client/petstore/objc/client/SWGStoreApi.m index a112db6d639a..0af0ebaad78c 100644 --- a/samples/client/petstore/objc/client/SWGStoreApi.m +++ b/samples/client/petstore/objc/client/SWGStoreApi.m @@ -74,10 +74,10 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; /*! * Returns pet inventories by status * Returns a map of status codes to quantities - * \returns NSDictionary* + * \returns NSDictionary* /* NSString, NSNumber */ */ -(NSNumber*) getInventoryWithCompletionBlock: - (void (^)(NSDictionary* output, NSError* error))completionBlock + (void (^)(NSDictionary* /* NSString, NSNumber */ output, NSError* error))completionBlock { @@ -127,37 +127,19 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; - - - // response is in a container - // map container response type - return [self.apiClient dictionary: requestUrl - method: @"GET" - queryParams: queryParams - body: bodyDictionary - headerParams: headerParams - authSettings: authSettings - requestContentType: requestContentType - responseContentType: responseContentType - completionBlock: ^(NSDictionary *data, NSError *error) { - if (error) { - completionBlock(nil, error); - return; - } - - NSDictionary *result = nil; - if (data) { - result = [[NSDictionary alloc]initWithDictionary: data]; - } - completionBlock(data, nil); - - }]; - - - - - - + return [self.apiClient requestWithCompletionBlock: requestUrl + method: @"GET" + queryParams: queryParams + body: bodyDictionary + headerParams: headerParams + authSettings: authSettings + requestContentType: requestContentType + responseContentType: responseContentType + completionBlock: ^(id data, NSError *error) { + + completionBlock([self.apiClient deserialize: data class:@"NSDictionary* /* NSString, NSNumber */"], error); + } + ]; } /*! @@ -241,44 +223,19 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; - - - - - // non container response - - - - - // complex response - - // comples response type - return [self.apiClient dictionary: requestUrl - method: @"POST" - queryParams: queryParams - body: bodyDictionary - headerParams: headerParams - authSettings: authSettings - requestContentType: requestContentType - responseContentType: responseContentType - completionBlock: ^(NSDictionary *data, NSError *error) { - if (error) { - completionBlock(nil, error); - - return; - } - SWGOrder* result = nil; - if (data) { - result = [[SWGOrder alloc] initWithDictionary:data error:nil]; - } - completionBlock(result , nil); - - }]; - - - - - + return [self.apiClient requestWithCompletionBlock: requestUrl + method: @"POST" + queryParams: queryParams + body: bodyDictionary + headerParams: headerParams + authSettings: authSettings + requestContentType: requestContentType + responseContentType: responseContentType + completionBlock: ^(id data, NSError *error) { + + completionBlock([self.apiClient deserialize: data class:@"SWGOrder*"], error); + } + ]; } /*! @@ -343,44 +300,19 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; - - - - - // non container response - - - - - // complex response - - // comples response type - return [self.apiClient dictionary: requestUrl - method: @"GET" - queryParams: queryParams - body: bodyDictionary - headerParams: headerParams - authSettings: authSettings - requestContentType: requestContentType - responseContentType: responseContentType - completionBlock: ^(NSDictionary *data, NSError *error) { - if (error) { - completionBlock(nil, error); - - return; - } - SWGOrder* result = nil; - if (data) { - result = [[SWGOrder alloc] initWithDictionary:data error:nil]; - } - completionBlock(result , nil); - - }]; - - - - - + return [self.apiClient requestWithCompletionBlock: requestUrl + method: @"GET" + queryParams: queryParams + body: bodyDictionary + headerParams: headerParams + authSettings: authSettings + requestContentType: requestContentType + responseContentType: responseContentType + completionBlock: ^(id data, NSError *error) { + + completionBlock([self.apiClient deserialize: data class:@"SWGOrder*"], error); + } + ]; } /*! @@ -445,30 +377,19 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; - - - - - - - // it's void - return [self.apiClient stringWithCompletionBlock: requestUrl - method: @"DELETE" - queryParams: queryParams - body: bodyDictionary - headerParams: headerParams - authSettings: authSettings - requestContentType: requestContentType - responseContentType: responseContentType - completionBlock: ^(NSString *data, NSError *error) { - if (error) { - completionBlock(error); - return; - } - completionBlock(nil); - }]; - - + return [self.apiClient requestWithCompletionBlock: requestUrl + method: @"DELETE" + queryParams: queryParams + body: bodyDictionary + headerParams: headerParams + authSettings: authSettings + requestContentType: requestContentType + responseContentType: responseContentType + completionBlock: ^(id data, NSError *error) { + completionBlock(error); + + } + ]; } diff --git a/samples/client/petstore/objc/client/SWGUserApi.m b/samples/client/petstore/objc/client/SWGUserApi.m index e2fe69aca8db..401df17e3962 100644 --- a/samples/client/petstore/objc/client/SWGUserApi.m +++ b/samples/client/petstore/objc/client/SWGUserApi.m @@ -152,30 +152,19 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; - - - - - - - // it's void - return [self.apiClient stringWithCompletionBlock: requestUrl - method: @"POST" - queryParams: queryParams - body: bodyDictionary - headerParams: headerParams - authSettings: authSettings - requestContentType: requestContentType - responseContentType: responseContentType - completionBlock: ^(NSString *data, NSError *error) { - if (error) { - completionBlock(error); - return; - } - completionBlock(nil); - }]; - - + return [self.apiClient requestWithCompletionBlock: requestUrl + method: @"POST" + queryParams: queryParams + body: bodyDictionary + headerParams: headerParams + authSettings: authSettings + requestContentType: requestContentType + responseContentType: responseContentType + completionBlock: ^(id data, NSError *error) { + completionBlock(error); + + } + ]; } /*! @@ -259,30 +248,19 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; - - - - - - - // it's void - return [self.apiClient stringWithCompletionBlock: requestUrl - method: @"POST" - queryParams: queryParams - body: bodyDictionary - headerParams: headerParams - authSettings: authSettings - requestContentType: requestContentType - responseContentType: responseContentType - completionBlock: ^(NSString *data, NSError *error) { - if (error) { - completionBlock(error); - return; - } - completionBlock(nil); - }]; - - + return [self.apiClient requestWithCompletionBlock: requestUrl + method: @"POST" + queryParams: queryParams + body: bodyDictionary + headerParams: headerParams + authSettings: authSettings + requestContentType: requestContentType + responseContentType: responseContentType + completionBlock: ^(id data, NSError *error) { + completionBlock(error); + + } + ]; } /*! @@ -366,30 +344,19 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; - - - - - - - // it's void - return [self.apiClient stringWithCompletionBlock: requestUrl - method: @"POST" - queryParams: queryParams - body: bodyDictionary - headerParams: headerParams - authSettings: authSettings - requestContentType: requestContentType - responseContentType: responseContentType - completionBlock: ^(NSString *data, NSError *error) { - if (error) { - completionBlock(error); - return; - } - completionBlock(nil); - }]; - - + return [self.apiClient requestWithCompletionBlock: requestUrl + method: @"POST" + queryParams: queryParams + body: bodyDictionary + headerParams: headerParams + authSettings: authSettings + requestContentType: requestContentType + responseContentType: responseContentType + completionBlock: ^(id data, NSError *error) { + completionBlock(error); + + } + ]; } /*! @@ -460,43 +427,19 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; - - - - - // non container response - - - // primitive response - // primitive response type - return [self.apiClient stringWithCompletionBlock: requestUrl - method: @"GET" - queryParams: queryParams - body: bodyDictionary - headerParams: headerParams - authSettings: authSettings - requestContentType: requestContentType - responseContentType: responseContentType - completionBlock: ^(NSString *data, NSError *error) { - if (error) { - completionBlock(nil, error); - return; - } - NSString *result = data ? [[NSString alloc]initWithString: data] : nil; - completionBlock(result, nil); - }]; - - - - - - - // complex response - - - - - + return [self.apiClient requestWithCompletionBlock: requestUrl + method: @"GET" + queryParams: queryParams + body: bodyDictionary + headerParams: headerParams + authSettings: authSettings + requestContentType: requestContentType + responseContentType: responseContentType + completionBlock: ^(id data, NSError *error) { + + completionBlock([self.apiClient deserialize: data class:@"NSString*"], error); + } + ]; } /*! @@ -555,30 +498,19 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; - - - - - - - // it's void - return [self.apiClient stringWithCompletionBlock: requestUrl - method: @"GET" - queryParams: queryParams - body: bodyDictionary - headerParams: headerParams - authSettings: authSettings - requestContentType: requestContentType - responseContentType: responseContentType - completionBlock: ^(NSString *data, NSError *error) { - if (error) { - completionBlock(error); - return; - } - completionBlock(nil); - }]; - - + return [self.apiClient requestWithCompletionBlock: requestUrl + method: @"GET" + queryParams: queryParams + body: bodyDictionary + headerParams: headerParams + authSettings: authSettings + requestContentType: requestContentType + responseContentType: responseContentType + completionBlock: ^(id data, NSError *error) { + completionBlock(error); + + } + ]; } /*! @@ -643,44 +575,19 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; - - - - - // non container response - - - - - // complex response - - // comples response type - return [self.apiClient dictionary: requestUrl - method: @"GET" - queryParams: queryParams - body: bodyDictionary - headerParams: headerParams - authSettings: authSettings - requestContentType: requestContentType - responseContentType: responseContentType - completionBlock: ^(NSDictionary *data, NSError *error) { - if (error) { - completionBlock(nil, error); - - return; - } - SWGUser* result = nil; - if (data) { - result = [[SWGUser alloc] initWithDictionary:data error:nil]; - } - completionBlock(result , nil); - - }]; - - - - - + return [self.apiClient requestWithCompletionBlock: requestUrl + method: @"GET" + queryParams: queryParams + body: bodyDictionary + headerParams: headerParams + authSettings: authSettings + requestContentType: requestContentType + responseContentType: responseContentType + completionBlock: ^(id data, NSError *error) { + + completionBlock([self.apiClient deserialize: data class:@"SWGUser*"], error); + } + ]; } /*! @@ -770,30 +677,19 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; - - - - - - - // it's void - return [self.apiClient stringWithCompletionBlock: requestUrl - method: @"PUT" - queryParams: queryParams - body: bodyDictionary - headerParams: headerParams - authSettings: authSettings - requestContentType: requestContentType - responseContentType: responseContentType - completionBlock: ^(NSString *data, NSError *error) { - if (error) { - completionBlock(error); - return; - } - completionBlock(nil); - }]; - - + return [self.apiClient requestWithCompletionBlock: requestUrl + method: @"PUT" + queryParams: queryParams + body: bodyDictionary + headerParams: headerParams + authSettings: authSettings + requestContentType: requestContentType + responseContentType: responseContentType + completionBlock: ^(id data, NSError *error) { + completionBlock(error); + + } + ]; } /*! @@ -858,30 +754,19 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; - - - - - - - // it's void - return [self.apiClient stringWithCompletionBlock: requestUrl - method: @"DELETE" - queryParams: queryParams - body: bodyDictionary - headerParams: headerParams - authSettings: authSettings - requestContentType: requestContentType - responseContentType: responseContentType - completionBlock: ^(NSString *data, NSError *error) { - if (error) { - completionBlock(error); - return; - } - completionBlock(nil); - }]; - - + return [self.apiClient requestWithCompletionBlock: requestUrl + method: @"DELETE" + queryParams: queryParams + body: bodyDictionary + headerParams: headerParams + authSettings: authSettings + requestContentType: requestContentType + responseContentType: responseContentType + completionBlock: ^(id data, NSError *error) { + completionBlock(error); + + } + ]; }