From 0da3e58fffb324e5821978c85d6a6d3b962f71dd Mon Sep 17 00:00:00 2001 From: geekerzp Date: Fri, 12 Jun 2015 14:48:02 +0800 Subject: [PATCH 1/7] 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 01f72040bf5..ce3ec065012 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 5e2985bbe79..ee8be40e2ab 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 250811c4016..09cb6fe57bd 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 40d75bd806b..ba61a8b2c7c 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 acaeaf2ddf5..7d178353d52 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 6cfac9a0eff..6747b94d4f8 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 250811c4016..829aec58b96 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 5e2985bbe79..ee8be40e2ab 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 c14da125af5..8a03932001c 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 49d8db806c8..b7d64469532 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 a112db6d639..0af0ebaad78 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 e2fe69aca8d..401df17e396 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); + + } + ]; } From c50c8b724d65186b4c548f0a76495871832f709e Mon Sep 17 00:00:00 2001 From: geekerzp Date: Sat, 13 Jun 2015 09:32:53 +0800 Subject: [PATCH 2/7] Support map response for objc client. completed. --- .../resources/objc/SWGApiClient-body.mustache | 23 ++- .../src/main/resources/objc/api-body.mustache | 12 +- .../main/resources/objc/api-header.mustache | 19 +- .../apiBodyResponseWithContainer.mustache | 45 ----- .../objc/apiNonPrimitiveResponse.mustache | 24 --- .../objc/apiPrimitiveResponse.mustache | 36 ---- .../main/resources/objc/voidResponse.mustache | 15 -- .../PetstoreClientTests/StoreApiTest.m | 47 +++++ .../SwaggerClient.xcodeproj/project.pbxproj | 4 + .../SwaggerClient/ViewController.m | 9 +- .../SwaggerClientTests/SWGApiClientTest.m | 62 +++++++ .../petstore/objc/client/SWGApiClient.m | 23 ++- .../client/petstore/objc/client/SWGPetApi.h | 162 +++++++++--------- .../client/petstore/objc/client/SWGPetApi.m | 106 ++++++------ .../client/petstore/objc/client/SWGStoreApi.h | 74 ++++---- .../client/petstore/objc/client/SWGStoreApi.m | 47 +++-- .../client/petstore/objc/client/SWGUserApi.h | 154 ++++++++--------- .../client/petstore/objc/client/SWGUserApi.m | 98 +++++------ 18 files changed, 477 insertions(+), 483 deletions(-) delete mode 100644 modules/swagger-codegen/src/main/resources/objc/apiBodyResponseWithContainer.mustache delete mode 100644 modules/swagger-codegen/src/main/resources/objc/apiNonPrimitiveResponse.mustache delete mode 100644 modules/swagger-codegen/src/main/resources/objc/apiPrimitiveResponse.mustache delete mode 100644 modules/swagger-codegen/src/main/resources/objc/voidResponse.mustache create mode 100644 samples/client/petstore/objc/PetstoreClient/PetstoreClientTests/StoreApiTest.m diff --git a/modules/swagger-codegen/src/main/resources/objc/SWGApiClient-body.mustache b/modules/swagger-codegen/src/main/resources/objc/SWGApiClient-body.mustache index ee8be40e2ab..45c6fc6d305 100644 --- a/modules/swagger-codegen/src/main/resources/objc/SWGApiClient-body.mustache +++ b/modules/swagger-codegen/src/main/resources/objc/SWGApiClient-body.mustache @@ -351,6 +351,7 @@ static bool loggingEnabled = true; *querys = [NSDictionary dictionaryWithDictionary:querysWithAuth]; } +#pragma mark - Deserialize methods - (id) deserialize:(id) data class:(NSString *) class { NSRegularExpression *regexp = nil; @@ -358,6 +359,11 @@ static bool loggingEnabled = true; NSMutableArray *resultArray = nil; NSMutableDictionary *resultDict = nil; + // remove "*" from class, if ends with "*" + if ([class hasSuffix:@"*"]) { + class = [class substringToIndex:[class length] - 1]; + } + // list of models NSString *arrayOfModelsPat = @"NSArray<(.+)>"; regexp = [NSRegularExpression regularExpressionWithPattern:arrayOfModelsPat @@ -371,7 +377,7 @@ static bool loggingEnabled = true; if (match) { NSString *innerType = [class substringWithRange:[match rangeAtIndex:1]]; - resultArray = [NSMutableArray arrayWithCapacity:[data length]]; + resultArray = [NSMutableArray arrayWithCapacity:[data count]]; [data enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { [resultArray addObject:[self deserialize:obj class:innerType]]; } @@ -390,7 +396,7 @@ static bool loggingEnabled = true; range:NSMakeRange(0, [class length])]; if (match) { - resultArray = [NSMutableArray arrayWithCapacity:[data length]]; + resultArray = [NSMutableArray arrayWithCapacity:[data count]]; [data enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { [resultArray addObject:[self deserialize:obj class:NSStringFromClass([obj class])]]; }]; @@ -399,7 +405,7 @@ static bool loggingEnabled = true; } // map - NSString *dictPat = @"NSDictionary /\\* (.+), (.+) \\*/"; + NSString *dictPat = @"NSDictionary\\* /\\* (.+), (.+) \\*/"; regexp = [NSRegularExpression regularExpressionWithPattern:dictPat options:NSRegularExpressionCaseInsensitive error:nil]; @@ -435,7 +441,16 @@ static bool loggingEnabled = true; return [NSNumber numberWithBool:[data boolValue]]; } else if ([class isEqualToString:@"NSNumber"]) { - return [data numberFromString:data]; + // NSNumber from NSNumber + if ([data isKindOfClass:[NSNumber class]]) { + return data; + } + // NSNumber from NSString + else { + NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init]; + formatter.numberStyle = NSNumberFormatterDecimalStyle; + return [formatter numberFromString:data]; + } } } 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 ba61a8b2c7c..1f3c6ca299e 100644 --- a/modules/swagger-codegen/src/main/resources/objc/api-body.mustache +++ b/modules/swagger-codegen/src/main/resources/objc/api-body.mustache @@ -74,12 +74,12 @@ static NSString * basePath = @"{{basePath}}"; {{#operation}} -/*! - * {{{summary}}} - * {{{notes}}} -{{#allParams}} * \param {{paramName}} {{{description}}} -{{/allParams}} * \returns {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}} - */ +// +// {{{summary}}} +// {{{notes}}} +// {{#allParams}} @param {{paramName}} {{{description}}} +// {{/allParams}} @returns {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}} +// -(NSNumber*) {{nickname}}WithCompletionBlock{{^allParams}}: {{/allParams}}{{#allParams}}{{#secondaryParam}} {{paramName}}{{/secondaryParam}}: ({{{dataType}}}) {{paramName}} {{/allParams}} {{#returnBaseType}}{{#hasParams}}completionHandler: {{/hasParams}}(void (^)({{{returnType}}} output, NSError* error))completionBlock{{/returnBaseType}} diff --git a/modules/swagger-codegen/src/main/resources/objc/api-header.mustache b/modules/swagger-codegen/src/main/resources/objc/api-header.mustache index 65f4c39e0b3..cc9ad03616e 100644 --- a/modules/swagger-codegen/src/main/resources/objc/api-header.mustache +++ b/modules/swagger-codegen/src/main/resources/objc/api-header.mustache @@ -17,16 +17,15 @@ +(void) setBasePath:(NSString*)basePath; +(NSString*) getBasePath; {{#operation}} -/** - - {{{summary}}} - {{#notes}}{{{notes}}}{{/notes}} - - {{#allParams}}@param {{paramName}} {{description}} - {{/allParams}} - - return type: {{{returnType}}} - */ +// +// +// {{{summary}}} +// {{#notes}}{{{notes}}}{{/notes}} +// +// {{#allParams}}@param {{paramName}} {{description}} +// {{/allParams}} +// +// @return {{{returnType}}} -(NSNumber*) {{nickname}}WithCompletionBlock {{^allParams}}:{{/allParams}}{{#allParams}}{{#secondaryParam}} {{paramName}}{{/secondaryParam}}:({{{dataType}}}) {{paramName}} {{#hasMore}} {{/hasMore}}{{/allParams}} {{#returnBaseType}}{{#hasParams}} diff --git a/modules/swagger-codegen/src/main/resources/objc/apiBodyResponseWithContainer.mustache b/modules/swagger-codegen/src/main/resources/objc/apiBodyResponseWithContainer.mustache deleted file mode 100644 index 7d178353d52..00000000000 --- a/modules/swagger-codegen/src/main/resources/objc/apiBodyResponseWithContainer.mustache +++ /dev/null @@ -1,45 +0,0 @@ - // {{returnContainer}} container response type - return [self.apiClient dictionary: requestUrl - method: @"{{httpMethod}}" - queryParams: queryParams - body: bodyDictionary - headerParams: headerParams - authSettings: authSettings - requestContentType: requestContentType - responseContentType: responseContentType - completionBlock: ^(NSDictionary *data, NSError *error) { - if (error) { - {{#returnBaseType}}completionBlock(nil, error);{{/returnBaseType}}{{^returnBaseType}}completionBlock(error);{{/returnBaseType}} - return; - } - {{#isMapContainer}} - NSDictionary *result = nil; - if (data) { - result = [[NSDictionary alloc]initWithDictionary: data]; - } - completionBlock(data, nil); - {{/isMapContainer}}{{#isListContainer}} - {{#returnBaseType}}if([data isKindOfClass:[NSArray class]]){ - NSMutableArray * objs = [[NSMutableArray alloc] initWithCapacity:[data count]]; - for (NSDictionary* dict in (NSArray*)data) { - {{#returnTypeIsPrimitive}} - {{returnBaseType}}* d = [[{{{returnBaseType}}} alloc]initWithString: dict]; - {{/returnTypeIsPrimitive}} - {{^returnTypeIsPrimitive}} - {{{returnBaseType}}}* d = [[{{{returnBaseType}}} alloc] initWithDictionary:dict error:nil]; - {{/returnTypeIsPrimitive}} - [objs addObject:d]; - } - completionBlock(({{{returnType}}})objs, nil); - } - {{/returnBaseType}} - {{/isListContainer}} - }]; - - - - - - - - diff --git a/modules/swagger-codegen/src/main/resources/objc/apiNonPrimitiveResponse.mustache b/modules/swagger-codegen/src/main/resources/objc/apiNonPrimitiveResponse.mustache deleted file mode 100644 index da8ea063bfb..00000000000 --- a/modules/swagger-codegen/src/main/resources/objc/apiNonPrimitiveResponse.mustache +++ /dev/null @@ -1,24 +0,0 @@ - {{^returnTypeIsPrimitive}} - // comples response type - return [self.apiClient dictionary: requestUrl - method: @"{{httpMethod}}" - queryParams: queryParams - body: bodyDictionary - headerParams: headerParams - authSettings: authSettings - requestContentType: requestContentType - responseContentType: responseContentType - completionBlock: ^(NSDictionary *data, NSError *error) { - if (error) { - {{#returnBaseType}}completionBlock(nil, error);{{/returnBaseType}} - {{^returnBaseType}}completionBlock(error);{{/returnBaseType}} - return; - } - {{#returnType}}{{returnType}} result = nil; - if (data) { - result = [[{{#instantiationType}}NSClassFromString(@"{{{instantiationType}}}") {{/instantiationType}}{{^instantiationType}}{{{returnBaseType}}} {{/instantiationType}} alloc] {{#returnContainer}}{{#isMapContainer}}initWithDictionary{{/isMapContainer}}{{#isListContainer}} initWithDictionary{{/isListContainer}}{{/returnContainer}}{{^returnContainer}} initWithDictionary{{/returnContainer}}:data error:nil]; - } - {{#returnType}}completionBlock(result , nil);{{/returnType}} - {{/returnType}} - }]; - {{/returnTypeIsPrimitive}} diff --git a/modules/swagger-codegen/src/main/resources/objc/apiPrimitiveResponse.mustache b/modules/swagger-codegen/src/main/resources/objc/apiPrimitiveResponse.mustache deleted file mode 100644 index d44d356526d..00000000000 --- a/modules/swagger-codegen/src/main/resources/objc/apiPrimitiveResponse.mustache +++ /dev/null @@ -1,36 +0,0 @@ - // primitive response type - {{#returnBaseType}}return [self.apiClient stringWithCompletionBlock: requestUrl - method: @"{{httpMethod}}" - queryParams: queryParams - body: bodyDictionary - headerParams: headerParams - authSettings: authSettings - requestContentType: requestContentType - responseContentType: responseContentType - completionBlock: ^(NSString *data, NSError *error) { - if (error) { - completionBlock(nil, error); - return; - } - {{returnBaseType}} *result = data ? [[{{#instantiationType}}NSClassFromString(@"{{{instantiationType}}}") {{/instantiationType}}{{^instantiationType}}{{{returnBaseType}}} {{/instantiationType}} alloc]initWithString: data] : nil; - completionBlock(result, nil); - }]; - {{/returnBaseType}} - {{^returnBaseType}} - // no return base type - return [self.apiClient stringWithCompletionBlock: requestUrl - method: @"{{httpMethod}}" - queryParams: queryParams - body: bodyDictionary - headerParams: headerParams - requestContentType: requestContentType - responseContentType: responseContentType - completionBlock: ^(NSString *data, NSError *error) { - if (error) { - completionBlock(error); - return; - } - completionBlock(nil); - }]; - {{/returnBaseType}} - diff --git a/modules/swagger-codegen/src/main/resources/objc/voidResponse.mustache b/modules/swagger-codegen/src/main/resources/objc/voidResponse.mustache deleted file mode 100644 index 7bbbc14c066..00000000000 --- a/modules/swagger-codegen/src/main/resources/objc/voidResponse.mustache +++ /dev/null @@ -1,15 +0,0 @@ - return [self.apiClient stringWithCompletionBlock: requestUrl - method: @"{{httpMethod}}" - queryParams: queryParams - body: bodyDictionary - headerParams: headerParams - authSettings: authSettings - requestContentType: requestContentType - responseContentType: responseContentType - completionBlock: ^(NSString *data, NSError *error) { - if (error) { - completionBlock(error); - return; - } - completionBlock(nil); - }]; diff --git a/samples/client/petstore/objc/PetstoreClient/PetstoreClientTests/StoreApiTest.m b/samples/client/petstore/objc/PetstoreClient/PetstoreClientTests/StoreApiTest.m new file mode 100644 index 00000000000..5440935be1b --- /dev/null +++ b/samples/client/petstore/objc/PetstoreClient/PetstoreClientTests/StoreApiTest.m @@ -0,0 +1,47 @@ +#import +#import +#import "SWGStoreApi.h" + +@interface StoreApiTest : XCTestCase + +@property (nonatomic) SWGStoreApi *api; + +@end + +@implementation StoreApiTest + +- (void)setUp { + [super setUp]; + self.api = [[SWGStoreApi alloc] init]; +} + +- (void)tearDown { + [super tearDown]; +} + +- (void)testGetInventory { + XCTestExpectation *expectation = [self expectationWithDescription:@"testGetPetByStatus"]; + + [self.api getInventoryWithCompletionBlock:^(NSDictionary *output, NSError *error) { + + if (error) { + XCTFail(@"got error %@", error); + } + + if (!output) { + XCTFail(@"failed to fetch inventory"); + } + + NSSet *expectKeys = [NSSet setWithArray:@[@"confused", @"string", @"pending", @"available", @"sold"]]; + NSSet *keys = [NSSet setWithArray:[output allKeys]]; + + XCTAssertEqualObjects(expectKeys, keys); + + [expectation fulfill]; + }]; + + [self waitForExpectationsWithTimeout:10.0 handler:nil]; +} + + +@end diff --git a/samples/client/petstore/objc/SwaggerClient/SwaggerClient.xcodeproj/project.pbxproj b/samples/client/petstore/objc/SwaggerClient/SwaggerClient.xcodeproj/project.pbxproj index ae903f27499..ffb61953051 100644 --- a/samples/client/petstore/objc/SwaggerClient/SwaggerClient.xcodeproj/project.pbxproj +++ b/samples/client/petstore/objc/SwaggerClient/SwaggerClient.xcodeproj/project.pbxproj @@ -10,6 +10,7 @@ BA525648922D4C0E9F44D4F1 /* libPods.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 73DA4F1067C343C3962F1542 /* libPods.a */; }; CF0560EB1B1855CF00C0D4EC /* SWGConfiguration.m in Sources */ = {isa = PBXBuildFile; fileRef = CF0560EA1B1855CF00C0D4EC /* SWGConfiguration.m */; }; CF31D0991B105E4B00509935 /* SWGApiClientTest.m in Sources */ = {isa = PBXBuildFile; fileRef = CF31D0981B105E4B00509935 /* SWGApiClientTest.m */; }; + CFB37D061B2B11DD00D2E5F1 /* StoreApiTest.m in Sources */ = {isa = PBXBuildFile; fileRef = CFB37D051B2B11DC00D2E5F1 /* StoreApiTest.m */; }; CFD1B6701B05EC7D00DCCD51 /* JSONValueTransformer+ISO8601.m in Sources */ = {isa = PBXBuildFile; fileRef = CFD1B66F1B05EC7D00DCCD51 /* JSONValueTransformer+ISO8601.m */; }; CFD1B6711B05EC7D00DCCD51 /* JSONValueTransformer+ISO8601.m in Sources */ = {isa = PBXBuildFile; fileRef = CFD1B66F1B05EC7D00DCCD51 /* JSONValueTransformer+ISO8601.m */; }; EA66999A1811D2FA00A70D03 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EA6699991811D2FA00A70D03 /* Foundation.framework */; }; @@ -60,6 +61,7 @@ CF0560E91B1855CF00C0D4EC /* SWGConfiguration.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SWGConfiguration.h; sourceTree = ""; }; CF0560EA1B1855CF00C0D4EC /* SWGConfiguration.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SWGConfiguration.m; sourceTree = ""; }; CF31D0981B105E4B00509935 /* SWGApiClientTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SWGApiClientTest.m; sourceTree = ""; }; + CFB37D051B2B11DC00D2E5F1 /* StoreApiTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = StoreApiTest.m; sourceTree = ""; }; CFD1B66E1B05EC7D00DCCD51 /* JSONValueTransformer+ISO8601.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "JSONValueTransformer+ISO8601.h"; sourceTree = ""; }; CFD1B66F1B05EC7D00DCCD51 /* JSONValueTransformer+ISO8601.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "JSONValueTransformer+ISO8601.m"; sourceTree = ""; }; E2B6DA00BE52336E23783686 /* Pods.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.debug.xcconfig; path = "../Pods/Target Support Files/Pods/Pods.debug.xcconfig"; sourceTree = ""; }; @@ -212,6 +214,7 @@ isa = PBXGroup; children = ( EA8CD3EB1AC274BE00C47D0B /* PetApiTest.h */, + CFB37D051B2B11DC00D2E5F1 /* StoreApiTest.m */, CF31D0981B105E4B00509935 /* SWGApiClientTest.m */, EA6699C71811D2FB00A70D03 /* PetApiTest.m */, EA6699C21811D2FB00A70D03 /* Supporting Files */, @@ -426,6 +429,7 @@ EAB26B0C1AC8DF78002F5C7A /* PetApiTest.h in Sources */, CFD1B6711B05EC7D00DCCD51 /* JSONValueTransformer+ISO8601.m in Sources */, EAB26B0D1AC8DF78002F5C7A /* PetApiTest.m in Sources */, + CFB37D061B2B11DD00D2E5F1 /* StoreApiTest.m in Sources */, CF31D0991B105E4B00509935 /* SWGApiClientTest.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/samples/client/petstore/objc/SwaggerClient/SwaggerClient/ViewController.m b/samples/client/petstore/objc/SwaggerClient/SwaggerClient/ViewController.m index fd15f391f49..56d0a8f621f 100644 --- a/samples/client/petstore/objc/SwaggerClient/SwaggerClient/ViewController.m +++ b/samples/client/petstore/objc/SwaggerClient/SwaggerClient/ViewController.m @@ -8,6 +8,7 @@ #import "ViewController.h" #import "SWGPetApi.h" +#import "SWGStoreApi.h" #import "SWGConfiguration.h" @interface ViewController () @@ -54,14 +55,6 @@ // } ]; */ - SWGConfiguration *config = [SWGConfiguration sharedConfig]; - config.username = @"foo"; - config.password = @"bar"; - SWGPetApi *api = [[SWGPetApi alloc] init]; - [api addPetWithCompletionBlock:nil - completionHandler:^(NSError *error) { - - }]; } - (void)didReceiveMemoryWarning diff --git a/samples/client/petstore/objc/SwaggerClient/SwaggerClientTests/SWGApiClientTest.m b/samples/client/petstore/objc/SwaggerClient/SwaggerClientTests/SWGApiClientTest.m index 61925b16960..1bd0c0eb1c3 100644 --- a/samples/client/petstore/objc/SwaggerClient/SwaggerClientTests/SWGApiClientTest.m +++ b/samples/client/petstore/objc/SwaggerClient/SwaggerClientTests/SWGApiClientTest.m @@ -98,4 +98,66 @@ XCTAssertEqualObjects(basicAuthCredentials, [config getBasicAuthToken]); } +- (void)testDeserialize { + id data; + id result; + + // list of models + data = + @[ + @{ + @"id": @119, + @"category": @{ + @"id": @0, + @"name": @"string" + }, + @"name": @"doggie", + @"photoUrls": @[ + @"string" + ], + @"tags": @[ + @{ + @"id": @0, + @"name": @"string" + } + ], + @"status": @"available" + + }]; + result = [self.apiClient deserialize:data class:@"NSArray*"]; + + XCTAssertTrue([result isKindOfClass:[NSArray class]]); + XCTAssertTrue([[result firstObject] isKindOfClass:[SWGPet class]]); + XCTAssertEqualObjects([[result firstObject] _id], @119); + + // map of models + data = + @{ + @"pet": @{ + @"id": @119, + @"category": @{ + @"id": @0, + @"name": @"string" + }, + @"name": @"doggie", + @"photoUrls": @[ + @"string" + ], + @"tags": @[ + @{ + @"id": @0, + @"name": @"string" + } + ], + @"status": @"available" + + } + }; + result = [self.apiClient deserialize:data class:@"NSDictionary* /* NSString, SWGPet */"]; + + XCTAssertTrue([result isKindOfClass:[NSDictionary class]]); + XCTAssertTrue([result[@"pet"] isKindOfClass:[SWGPet class]]); + XCTAssertEqualObjects([result[@"pet"] _id], @119); +} + @end diff --git a/samples/client/petstore/objc/client/SWGApiClient.m b/samples/client/petstore/objc/client/SWGApiClient.m index ee8be40e2ab..45c6fc6d305 100644 --- a/samples/client/petstore/objc/client/SWGApiClient.m +++ b/samples/client/petstore/objc/client/SWGApiClient.m @@ -351,6 +351,7 @@ static bool loggingEnabled = true; *querys = [NSDictionary dictionaryWithDictionary:querysWithAuth]; } +#pragma mark - Deserialize methods - (id) deserialize:(id) data class:(NSString *) class { NSRegularExpression *regexp = nil; @@ -358,6 +359,11 @@ static bool loggingEnabled = true; NSMutableArray *resultArray = nil; NSMutableDictionary *resultDict = nil; + // remove "*" from class, if ends with "*" + if ([class hasSuffix:@"*"]) { + class = [class substringToIndex:[class length] - 1]; + } + // list of models NSString *arrayOfModelsPat = @"NSArray<(.+)>"; regexp = [NSRegularExpression regularExpressionWithPattern:arrayOfModelsPat @@ -371,7 +377,7 @@ static bool loggingEnabled = true; if (match) { NSString *innerType = [class substringWithRange:[match rangeAtIndex:1]]; - resultArray = [NSMutableArray arrayWithCapacity:[data length]]; + resultArray = [NSMutableArray arrayWithCapacity:[data count]]; [data enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { [resultArray addObject:[self deserialize:obj class:innerType]]; } @@ -390,7 +396,7 @@ static bool loggingEnabled = true; range:NSMakeRange(0, [class length])]; if (match) { - resultArray = [NSMutableArray arrayWithCapacity:[data length]]; + resultArray = [NSMutableArray arrayWithCapacity:[data count]]; [data enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { [resultArray addObject:[self deserialize:obj class:NSStringFromClass([obj class])]]; }]; @@ -399,7 +405,7 @@ static bool loggingEnabled = true; } // map - NSString *dictPat = @"NSDictionary /\\* (.+), (.+) \\*/"; + NSString *dictPat = @"NSDictionary\\* /\\* (.+), (.+) \\*/"; regexp = [NSRegularExpression regularExpressionWithPattern:dictPat options:NSRegularExpressionCaseInsensitive error:nil]; @@ -435,7 +441,16 @@ static bool loggingEnabled = true; return [NSNumber numberWithBool:[data boolValue]]; } else if ([class isEqualToString:@"NSNumber"]) { - return [data numberFromString:data]; + // NSNumber from NSNumber + if ([data isKindOfClass:[NSNumber class]]) { + return data; + } + // NSNumber from NSString + else { + NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init]; + formatter.numberStyle = NSNumberFormatterDecimalStyle; + return [formatter numberFromString:data]; + } } } diff --git a/samples/client/petstore/objc/client/SWGPetApi.h b/samples/client/petstore/objc/client/SWGPetApi.h index aa255cd144e..ce17f2c30ab 100644 --- a/samples/client/petstore/objc/client/SWGPetApi.h +++ b/samples/client/petstore/objc/client/SWGPetApi.h @@ -15,98 +15,92 @@ +(SWGPetApi*) apiWithHeader:(NSString*)headerValue key:(NSString*)key; +(void) setBasePath:(NSString*)basePath; +(NSString*) getBasePath; -/** - - Update an existing pet - - - @param body Pet object that needs to be added to the store - - - return type: - */ +// +// +// Update an existing pet +// +// +// @param body Pet object that needs to be added to the store +// +// +// @return -(NSNumber*) updatePetWithCompletionBlock :(SWGPet*) body completionHandler: (void (^)(NSError* error))completionBlock; -/** - - Add a new pet to the store - - - @param body Pet object that needs to be added to the store - - - return type: - */ +// +// +// Add a new pet to the store +// +// +// @param body Pet object that needs to be added to the store +// +// +// @return -(NSNumber*) addPetWithCompletionBlock :(SWGPet*) body completionHandler: (void (^)(NSError* error))completionBlock; -/** - - Finds Pets by status - Multiple status values can be provided with comma seperated strings - - @param status Status values that need to be considered for filter - - - return type: NSArray* - */ +// +// +// Finds Pets by status +// Multiple status values can be provided with comma seperated strings +// +// @param status Status values that need to be considered for filter +// +// +// @return NSArray* -(NSNumber*) findPetsByStatusWithCompletionBlock :(NSArray*) status completionHandler: (void (^)(NSArray* output, NSError* error))completionBlock; -/** - - Finds Pets by tags - Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing. - - @param tags Tags to filter by - - - return type: NSArray* - */ +// +// +// Finds Pets by tags +// Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing. +// +// @param tags Tags to filter by +// +// +// @return NSArray* -(NSNumber*) findPetsByTagsWithCompletionBlock :(NSArray*) tags completionHandler: (void (^)(NSArray* output, NSError* error))completionBlock; -/** - - Find pet by ID - Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions - - @param petId ID of pet that needs to be fetched - - - return type: SWGPet* - */ +// +// +// Find pet by ID +// Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions +// +// @param petId ID of pet that needs to be fetched +// +// +// @return SWGPet* -(NSNumber*) getPetByIdWithCompletionBlock :(NSNumber*) petId completionHandler: (void (^)(SWGPet* output, NSError* error))completionBlock; -/** - - Updates a pet in the store with form data - - - @param petId ID of pet that needs to be updated - @param name Updated name of the pet - @param status Updated status of the pet - - - return type: - */ +// +// +// Updates a pet in the store with form data +// +// +// @param petId ID of pet that needs to be updated +// @param name Updated name of the pet +// @param status Updated status of the pet +// +// +// @return -(NSNumber*) updatePetWithFormWithCompletionBlock :(NSString*) petId name:(NSString*) name status:(NSString*) status @@ -115,17 +109,16 @@ completionHandler: (void (^)(NSError* error))completionBlock; -/** - - Deletes a pet - - - @param apiKey - @param petId Pet id to delete - - - return type: - */ +// +// +// Deletes a pet +// +// +// @param apiKey +// @param petId Pet id to delete +// +// +// @return -(NSNumber*) deletePetWithCompletionBlock :(NSString*) apiKey petId:(NSNumber*) petId @@ -133,18 +126,17 @@ completionHandler: (void (^)(NSError* error))completionBlock; -/** - - uploads an image - - - @param petId ID of pet to update - @param additionalMetadata Additional data to pass to server - @param file file to upload - - - return type: - */ +// +// +// uploads an image +// +// +// @param petId ID of pet to update +// @param additionalMetadata Additional data to pass to server +// @param file file to upload +// +// +// @return -(NSNumber*) uploadFileWithCompletionBlock :(NSNumber*) petId additionalMetadata:(NSString*) additionalMetadata file:(SWGFile*) file diff --git a/samples/client/petstore/objc/client/SWGPetApi.m b/samples/client/petstore/objc/client/SWGPetApi.m index 8a03932001c..d23a2ce9979 100644 --- a/samples/client/petstore/objc/client/SWGPetApi.m +++ b/samples/client/petstore/objc/client/SWGPetApi.m @@ -72,12 +72,12 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; } -/*! - * Update an existing pet - * - * \param body Pet object that needs to be added to the store - * \returns void - */ +// +// Update an existing pet +// +// @param body Pet object that needs to be added to the store +// @returns void +// -(NSNumber*) updatePetWithCompletionBlock: (SWGPet*) body @@ -168,12 +168,12 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; ]; } -/*! - * Add a new pet to the store - * - * \param body Pet object that needs to be added to the store - * \returns void - */ +// +// Add a new pet to the store +// +// @param body Pet object that needs to be added to the store +// @returns void +// -(NSNumber*) addPetWithCompletionBlock: (SWGPet*) body @@ -264,12 +264,12 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; ]; } -/*! - * Finds Pets by status - * Multiple status values can be provided with comma seperated strings - * \param status Status values that need to be considered for filter - * \returns NSArray* - */ +// +// Finds Pets by status +// Multiple status values can be provided with comma seperated strings +// @param status Status values that need to be considered for filter +// @returns NSArray* +// -(NSNumber*) findPetsByStatusWithCompletionBlock: (NSArray*) status completionHandler: (void (^)(NSArray* output, NSError* error))completionBlock @@ -343,12 +343,12 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; ]; } -/*! - * Finds Pets by tags - * Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing. - * \param tags Tags to filter by - * \returns NSArray* - */ +// +// Finds Pets by tags +// Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing. +// @param tags Tags to filter by +// @returns NSArray* +// -(NSNumber*) findPetsByTagsWithCompletionBlock: (NSArray*) tags completionHandler: (void (^)(NSArray* output, NSError* error))completionBlock @@ -422,12 +422,12 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; ]; } -/*! - * Find pet by ID - * Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions - * \param petId ID of pet that needs to be fetched - * \returns SWGPet* - */ +// +// Find pet by ID +// Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions +// @param petId ID of pet that needs to be fetched +// @returns SWGPet* +// -(NSNumber*) getPetByIdWithCompletionBlock: (NSNumber*) petId completionHandler: (void (^)(SWGPet* output, NSError* error))completionBlock @@ -499,14 +499,14 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; ]; } -/*! - * Updates a pet in the store with form data - * - * \param petId ID of pet that needs to be updated - * \param name Updated name of the pet - * \param status Updated status of the pet - * \returns void - */ +// +// Updates a pet in the store with form data +// +// @param petId ID of pet that needs to be updated +// @param name Updated name of the pet +// @param status Updated status of the pet +// @returns void +// -(NSNumber*) updatePetWithFormWithCompletionBlock: (NSString*) petId name: (NSString*) name status: (NSString*) status @@ -596,13 +596,13 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; ]; } -/*! - * Deletes a pet - * - * \param apiKey - * \param petId Pet id to delete - * \returns void - */ +// +// Deletes a pet +// +// @param apiKey +// @param petId Pet id to delete +// @returns void +// -(NSNumber*) deletePetWithCompletionBlock: (NSString*) apiKey petId: (NSNumber*) petId @@ -677,14 +677,14 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; ]; } -/*! - * uploads an image - * - * \param petId ID of pet to update - * \param additionalMetadata Additional data to pass to server - * \param file file to upload - * \returns void - */ +// +// uploads an image +// +// @param petId ID of pet to update +// @param additionalMetadata Additional data to pass to server +// @param file file to upload +// @returns void +// -(NSNumber*) uploadFileWithCompletionBlock: (NSNumber*) petId additionalMetadata: (NSString*) additionalMetadata file: (SWGFile*) file diff --git a/samples/client/petstore/objc/client/SWGStoreApi.h b/samples/client/petstore/objc/client/SWGStoreApi.h index b7d64469532..a59d861bbb8 100644 --- a/samples/client/petstore/objc/client/SWGStoreApi.h +++ b/samples/client/petstore/objc/client/SWGStoreApi.h @@ -14,62 +14,58 @@ +(SWGStoreApi*) apiWithHeader:(NSString*)headerValue key:(NSString*)key; +(void) setBasePath:(NSString*)basePath; +(NSString*) getBasePath; -/** - - Returns pet inventories by status - Returns a map of status codes to quantities - - - - return type: NSDictionary* /* NSString, NSNumber */ - */ +// +// +// Returns pet inventories by status +// Returns a map of status codes to quantities +// +// +// +// @return NSDictionary* /* NSString, NSNumber */ -(NSNumber*) getInventoryWithCompletionBlock : (void (^)(NSDictionary* /* NSString, NSNumber */ output, NSError* error))completionBlock; -/** - - Place an order for a pet - - - @param body order placed for purchasing the pet - - - return type: SWGOrder* - */ +// +// +// Place an order for a pet +// +// +// @param body order placed for purchasing the pet +// +// +// @return SWGOrder* -(NSNumber*) placeOrderWithCompletionBlock :(SWGOrder*) body completionHandler: (void (^)(SWGOrder* output, NSError* error))completionBlock; -/** - - Find purchase order by ID - For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions - - @param orderId ID of pet that needs to be fetched - - - return type: SWGOrder* - */ +// +// +// Find purchase order by ID +// For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions +// +// @param orderId ID of pet that needs to be fetched +// +// +// @return SWGOrder* -(NSNumber*) getOrderByIdWithCompletionBlock :(NSString*) orderId completionHandler: (void (^)(SWGOrder* output, NSError* error))completionBlock; -/** - - Delete purchase order by ID - For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors - - @param orderId ID of the order that needs to be deleted - - - return type: - */ +// +// +// Delete purchase order by ID +// For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors +// +// @param orderId ID of the order that needs to be deleted +// +// +// @return -(NSNumber*) deleteOrderWithCompletionBlock :(NSString*) orderId diff --git a/samples/client/petstore/objc/client/SWGStoreApi.m b/samples/client/petstore/objc/client/SWGStoreApi.m index 0af0ebaad78..ce3a63c9483 100644 --- a/samples/client/petstore/objc/client/SWGStoreApi.m +++ b/samples/client/petstore/objc/client/SWGStoreApi.m @@ -71,17 +71,16 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; } -/*! - * Returns pet inventories by status - * Returns a map of status codes to quantities - * \returns NSDictionary* /* NSString, NSNumber */ - */ +// +// Returns pet inventories by status +// Returns a map of status codes to quantities +// @returns NSDictionary* /* NSString, NSNumber */ +// -(NSNumber*) getInventoryWithCompletionBlock: (void (^)(NSDictionary* /* NSString, NSNumber */ output, NSError* error))completionBlock { - NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/store/inventory", basePath]; // remove format in URL if needed @@ -142,12 +141,12 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; ]; } -/*! - * Place an order for a pet - * - * \param body order placed for purchasing the pet - * \returns SWGOrder* - */ +// +// Place an order for a pet +// +// @param body order placed for purchasing the pet +// @returns SWGOrder* +// -(NSNumber*) placeOrderWithCompletionBlock: (SWGOrder*) body completionHandler: (void (^)(SWGOrder* output, NSError* error))completionBlock @@ -238,12 +237,12 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; ]; } -/*! - * Find purchase order by ID - * For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions - * \param orderId ID of pet that needs to be fetched - * \returns SWGOrder* - */ +// +// Find purchase order by ID +// For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions +// @param orderId ID of pet that needs to be fetched +// @returns SWGOrder* +// -(NSNumber*) getOrderByIdWithCompletionBlock: (NSString*) orderId completionHandler: (void (^)(SWGOrder* output, NSError* error))completionBlock @@ -315,12 +314,12 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; ]; } -/*! - * Delete purchase order by ID - * For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors - * \param orderId ID of the order that needs to be deleted - * \returns void - */ +// +// Delete purchase order by ID +// For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors +// @param orderId ID of the order that needs to be deleted +// @returns void +// -(NSNumber*) deleteOrderWithCompletionBlock: (NSString*) orderId diff --git a/samples/client/petstore/objc/client/SWGUserApi.h b/samples/client/petstore/objc/client/SWGUserApi.h index e6e73ddfba6..c26046a17c6 100644 --- a/samples/client/petstore/objc/client/SWGUserApi.h +++ b/samples/client/petstore/objc/client/SWGUserApi.h @@ -14,65 +14,61 @@ +(SWGUserApi*) apiWithHeader:(NSString*)headerValue key:(NSString*)key; +(void) setBasePath:(NSString*)basePath; +(NSString*) getBasePath; -/** - - Create user - This can only be done by the logged in user. - - @param body Created user object - - - return type: - */ +// +// +// Create user +// This can only be done by the logged in user. +// +// @param body Created user object +// +// +// @return -(NSNumber*) createUserWithCompletionBlock :(SWGUser*) body completionHandler: (void (^)(NSError* error))completionBlock; -/** - - Creates list of users with given input array - - - @param body List of user object - - - return type: - */ +// +// +// Creates list of users with given input array +// +// +// @param body List of user object +// +// +// @return -(NSNumber*) createUsersWithArrayInputWithCompletionBlock :(NSArray*) body completionHandler: (void (^)(NSError* error))completionBlock; -/** - - Creates list of users with given input array - - - @param body List of user object - - - return type: - */ +// +// +// Creates list of users with given input array +// +// +// @param body List of user object +// +// +// @return -(NSNumber*) createUsersWithListInputWithCompletionBlock :(NSArray*) body completionHandler: (void (^)(NSError* error))completionBlock; -/** - - Logs user into the system - - - @param username The user name for login - @param password The password for login in clear text - - - return type: NSString* - */ +// +// +// Logs user into the system +// +// +// @param username The user name for login +// @param password The password for login in clear text +// +// +// @return NSString* -(NSNumber*) loginUserWithCompletionBlock :(NSString*) username password:(NSString*) password @@ -80,47 +76,44 @@ -/** - - Logs out current logged in user session - - - - - return type: - */ +// +// +// Logs out current logged in user session +// +// +// +// +// @return -(NSNumber*) logoutUserWithCompletionBlock : (void (^)(NSError* error))completionBlock; -/** - - Get user by user name - - - @param username The name that needs to be fetched. Use user1 for testing. - - - return type: SWGUser* - */ +// +// +// Get user by user name +// +// +// @param username The name that needs to be fetched. Use user1 for testing. +// +// +// @return SWGUser* -(NSNumber*) getUserByNameWithCompletionBlock :(NSString*) username completionHandler: (void (^)(SWGUser* output, NSError* error))completionBlock; -/** - - Updated user - This can only be done by the logged in user. - - @param username name that need to be deleted - @param body Updated user object - - - return type: - */ +// +// +// Updated user +// This can only be done by the logged in user. +// +// @param username name that need to be deleted +// @param body Updated user object +// +// +// @return -(NSNumber*) updateUserWithCompletionBlock :(NSString*) username body:(SWGUser*) body @@ -128,16 +121,15 @@ completionHandler: (void (^)(NSError* error))completionBlock; -/** - - Delete user - This can only be done by the logged in user. - - @param username The name that needs to be deleted - - - return type: - */ +// +// +// Delete user +// This can only be done by the logged in user. +// +// @param username The name that needs to be deleted +// +// +// @return -(NSNumber*) deleteUserWithCompletionBlock :(NSString*) username diff --git a/samples/client/petstore/objc/client/SWGUserApi.m b/samples/client/petstore/objc/client/SWGUserApi.m index 401df17e396..3ef45ea1e77 100644 --- a/samples/client/petstore/objc/client/SWGUserApi.m +++ b/samples/client/petstore/objc/client/SWGUserApi.m @@ -71,12 +71,12 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; } -/*! - * Create user - * This can only be done by the logged in user. - * \param body Created user object - * \returns void - */ +// +// Create user +// This can only be done by the logged in user. +// @param body Created user object +// @returns void +// -(NSNumber*) createUserWithCompletionBlock: (SWGUser*) body @@ -167,12 +167,12 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; ]; } -/*! - * Creates list of users with given input array - * - * \param body List of user object - * \returns void - */ +// +// Creates list of users with given input array +// +// @param body List of user object +// @returns void +// -(NSNumber*) createUsersWithArrayInputWithCompletionBlock: (NSArray*) body @@ -263,12 +263,12 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; ]; } -/*! - * Creates list of users with given input array - * - * \param body List of user object - * \returns void - */ +// +// Creates list of users with given input array +// +// @param body List of user object +// @returns void +// -(NSNumber*) createUsersWithListInputWithCompletionBlock: (NSArray*) body @@ -359,13 +359,13 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; ]; } -/*! - * Logs user into the system - * - * \param username The user name for login - * \param password The password for login in clear text - * \returns NSString* - */ +// +// Logs user into the system +// +// @param username The user name for login +// @param password The password for login in clear text +// @returns NSString* +// -(NSNumber*) loginUserWithCompletionBlock: (NSString*) username password: (NSString*) password @@ -442,11 +442,11 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; ]; } -/*! - * Logs out current logged in user session - * - * \returns void - */ +// +// Logs out current logged in user session +// +// @returns void +// -(NSNumber*) logoutUserWithCompletionBlock: (void (^)(NSError* error))completionBlock { @@ -513,12 +513,12 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; ]; } -/*! - * Get user by user name - * - * \param username The name that needs to be fetched. Use user1 for testing. - * \returns SWGUser* - */ +// +// Get user by user name +// +// @param username The name that needs to be fetched. Use user1 for testing. +// @returns SWGUser* +// -(NSNumber*) getUserByNameWithCompletionBlock: (NSString*) username completionHandler: (void (^)(SWGUser* output, NSError* error))completionBlock @@ -590,13 +590,13 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; ]; } -/*! - * Updated user - * This can only be done by the logged in user. - * \param username name that need to be deleted - * \param body Updated user object - * \returns void - */ +// +// Updated user +// This can only be done by the logged in user. +// @param username name that need to be deleted +// @param body Updated user object +// @returns void +// -(NSNumber*) updateUserWithCompletionBlock: (NSString*) username body: (SWGUser*) body @@ -692,12 +692,12 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; ]; } -/*! - * Delete user - * This can only be done by the logged in user. - * \param username The name that needs to be deleted - * \returns void - */ +// +// Delete user +// This can only be done by the logged in user. +// @param username The name that needs to be deleted +// @returns void +// -(NSNumber*) deleteUserWithCompletionBlock: (NSString*) username From a6bdc35d59b0692352f6465a4f483c0f182cc0e8 Mon Sep 17 00:00:00 2001 From: geekerzp Date: Sat, 13 Jun 2015 10:17:08 +0800 Subject: [PATCH 3/7] Support pure object response for objc client --- .../src/main/resources/objc/SWGApiClient-body.mustache | 5 +++++ .../objc/PetstoreClient/PetstoreClientTests/StoreApiTest.m | 2 +- .../objc/SwaggerClient/SwaggerClientTests/SWGApiClientTest.m | 5 +++++ samples/client/petstore/objc/client/SWGApiClient.m | 5 +++++ samples/client/petstore/objc/client/SWGStoreApi.m | 1 + 5 files changed, 17 insertions(+), 1 deletion(-) diff --git a/modules/swagger-codegen/src/main/resources/objc/SWGApiClient-body.mustache b/modules/swagger-codegen/src/main/resources/objc/SWGApiClient-body.mustache index 45c6fc6d305..a0c9c63d27c 100644 --- a/modules/swagger-codegen/src/main/resources/objc/SWGApiClient-body.mustache +++ b/modules/swagger-codegen/src/main/resources/objc/SWGApiClient-body.mustache @@ -364,6 +364,11 @@ static bool loggingEnabled = true; class = [class substringToIndex:[class length] - 1]; } + // pure object + if ([class isEqualToString:@"NSObject"]) { + return [[NSObject alloc] init]; + } + // list of models NSString *arrayOfModelsPat = @"NSArray<(.+)>"; regexp = [NSRegularExpression regularExpressionWithPattern:arrayOfModelsPat diff --git a/samples/client/petstore/objc/PetstoreClient/PetstoreClientTests/StoreApiTest.m b/samples/client/petstore/objc/PetstoreClient/PetstoreClientTests/StoreApiTest.m index 5440935be1b..8ea2e7ee0fc 100644 --- a/samples/client/petstore/objc/PetstoreClient/PetstoreClientTests/StoreApiTest.m +++ b/samples/client/petstore/objc/PetstoreClient/PetstoreClientTests/StoreApiTest.m @@ -32,7 +32,7 @@ XCTFail(@"failed to fetch inventory"); } - NSSet *expectKeys = [NSSet setWithArray:@[@"confused", @"string", @"pending", @"available", @"sold"]]; + NSSet *expectKeys = [NSSet setWithArray:@[@"confused", @"string", @"available"]]; NSSet *keys = [NSSet setWithArray:[output allKeys]]; XCTAssertEqualObjects(expectKeys, keys); diff --git a/samples/client/petstore/objc/SwaggerClient/SwaggerClientTests/SWGApiClientTest.m b/samples/client/petstore/objc/SwaggerClient/SwaggerClientTests/SWGApiClientTest.m index 1bd0c0eb1c3..597cf2fb714 100644 --- a/samples/client/petstore/objc/SwaggerClient/SwaggerClientTests/SWGApiClientTest.m +++ b/samples/client/petstore/objc/SwaggerClient/SwaggerClientTests/SWGApiClientTest.m @@ -158,6 +158,11 @@ XCTAssertTrue([result isKindOfClass:[NSDictionary class]]); XCTAssertTrue([result[@"pet"] isKindOfClass:[SWGPet class]]); XCTAssertEqualObjects([result[@"pet"] _id], @119); + + // pure object + result = [self.apiClient deserialize:nil class:@"NSObject*"]; + + XCTAssertTrue([result isKindOfClass:[NSObject class]]); } @end diff --git a/samples/client/petstore/objc/client/SWGApiClient.m b/samples/client/petstore/objc/client/SWGApiClient.m index 45c6fc6d305..a0c9c63d27c 100644 --- a/samples/client/petstore/objc/client/SWGApiClient.m +++ b/samples/client/petstore/objc/client/SWGApiClient.m @@ -364,6 +364,11 @@ static bool loggingEnabled = true; class = [class substringToIndex:[class length] - 1]; } + // pure object + if ([class isEqualToString:@"NSObject"]) { + return [[NSObject alloc] init]; + } + // list of models NSString *arrayOfModelsPat = @"NSArray<(.+)>"; regexp = [NSRegularExpression regularExpressionWithPattern:arrayOfModelsPat diff --git a/samples/client/petstore/objc/client/SWGStoreApi.m b/samples/client/petstore/objc/client/SWGStoreApi.m index ce3a63c9483..2613f8b6caf 100644 --- a/samples/client/petstore/objc/client/SWGStoreApi.m +++ b/samples/client/petstore/objc/client/SWGStoreApi.m @@ -81,6 +81,7 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; { + NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/store/inventory", basePath]; // remove format in URL if needed From bc92465bf7596d488b9e3cb73325b773033a2482 Mon Sep 17 00:00:00 2001 From: geekerzp Date: Sat, 13 Jun 2015 10:48:45 +0800 Subject: [PATCH 4/7] Update Objective-C method description (doc comments) style --- .../src/main/resources/objc/api-body.mustache | 14 +- .../main/resources/objc/api-header.mustache | 18 +- .../client/petstore/objc/client/SWGPetApi.h | 154 +++++++++--------- .../client/petstore/objc/client/SWGPetApi.m | 120 ++++++++------ .../client/petstore/objc/client/SWGStoreApi.h | 70 ++++---- .../client/petstore/objc/client/SWGStoreApi.m | 50 +++--- .../client/petstore/objc/client/SWGUserApi.h | 146 ++++++++--------- .../client/petstore/objc/client/SWGUserApi.m | 108 ++++++------ 8 files changed, 355 insertions(+), 325 deletions(-) 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 1f3c6ca299e..29dca1f4a7a 100644 --- a/modules/swagger-codegen/src/main/resources/objc/api-body.mustache +++ b/modules/swagger-codegen/src/main/resources/objc/api-body.mustache @@ -72,14 +72,16 @@ static NSString * basePath = @"{{basePath}}"; return [SWGApiClient requestQueueSize]; } +#pragma mark - Api Methods {{#operation}} -// -// {{{summary}}} -// {{{notes}}} -// {{#allParams}} @param {{paramName}} {{{description}}} -// {{/allParams}} @returns {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}} -// +/// +/// {{{summary}}} +/// {{{notes}}} +/// {{#allParams}} @param {{paramName}} {{{description}}} +/// +/// {{/allParams}} @returns {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}} +/// -(NSNumber*) {{nickname}}WithCompletionBlock{{^allParams}}: {{/allParams}}{{#allParams}}{{#secondaryParam}} {{paramName}}{{/secondaryParam}}: ({{{dataType}}}) {{paramName}} {{/allParams}} {{#returnBaseType}}{{#hasParams}}completionHandler: {{/hasParams}}(void (^)({{{returnType}}} output, NSError* error))completionBlock{{/returnBaseType}} diff --git a/modules/swagger-codegen/src/main/resources/objc/api-header.mustache b/modules/swagger-codegen/src/main/resources/objc/api-header.mustache index cc9ad03616e..7f14262d116 100644 --- a/modules/swagger-codegen/src/main/resources/objc/api-header.mustache +++ b/modules/swagger-codegen/src/main/resources/objc/api-header.mustache @@ -17,15 +17,15 @@ +(void) setBasePath:(NSString*)basePath; +(NSString*) getBasePath; {{#operation}} -// -// -// {{{summary}}} -// {{#notes}}{{{notes}}}{{/notes}} -// -// {{#allParams}}@param {{paramName}} {{description}} -// {{/allParams}} -// -// @return {{{returnType}}} +/// +/// +/// {{{summary}}} +/// {{#notes}}{{{notes}}}{{/notes}} +/// +/// {{#allParams}}@param {{paramName}} {{description}} +/// {{/allParams}} +/// +/// @return {{{returnType}}} -(NSNumber*) {{nickname}}WithCompletionBlock {{^allParams}}:{{/allParams}}{{#allParams}}{{#secondaryParam}} {{paramName}}{{/secondaryParam}}:({{{dataType}}}) {{paramName}} {{#hasMore}} {{/hasMore}}{{/allParams}} {{#returnBaseType}}{{#hasParams}} diff --git a/samples/client/petstore/objc/client/SWGPetApi.h b/samples/client/petstore/objc/client/SWGPetApi.h index ce17f2c30ab..257a7d1453e 100644 --- a/samples/client/petstore/objc/client/SWGPetApi.h +++ b/samples/client/petstore/objc/client/SWGPetApi.h @@ -15,92 +15,92 @@ +(SWGPetApi*) apiWithHeader:(NSString*)headerValue key:(NSString*)key; +(void) setBasePath:(NSString*)basePath; +(NSString*) getBasePath; -// -// -// Update an existing pet -// -// -// @param body Pet object that needs to be added to the store -// -// -// @return +/// +/// +/// Update an existing pet +/// +/// +/// @param body Pet object that needs to be added to the store +/// +/// +/// @return -(NSNumber*) updatePetWithCompletionBlock :(SWGPet*) body completionHandler: (void (^)(NSError* error))completionBlock; -// -// -// Add a new pet to the store -// -// -// @param body Pet object that needs to be added to the store -// -// -// @return +/// +/// +/// Add a new pet to the store +/// +/// +/// @param body Pet object that needs to be added to the store +/// +/// +/// @return -(NSNumber*) addPetWithCompletionBlock :(SWGPet*) body completionHandler: (void (^)(NSError* error))completionBlock; -// -// -// Finds Pets by status -// Multiple status values can be provided with comma seperated strings -// -// @param status Status values that need to be considered for filter -// -// -// @return NSArray* +/// +/// +/// Finds Pets by status +/// Multiple status values can be provided with comma seperated strings +/// +/// @param status Status values that need to be considered for filter +/// +/// +/// @return NSArray* -(NSNumber*) findPetsByStatusWithCompletionBlock :(NSArray*) status completionHandler: (void (^)(NSArray* output, NSError* error))completionBlock; -// -// -// Finds Pets by tags -// Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing. -// -// @param tags Tags to filter by -// -// -// @return NSArray* +/// +/// +/// Finds Pets by tags +/// Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing. +/// +/// @param tags Tags to filter by +/// +/// +/// @return NSArray* -(NSNumber*) findPetsByTagsWithCompletionBlock :(NSArray*) tags completionHandler: (void (^)(NSArray* output, NSError* error))completionBlock; -// -// -// Find pet by ID -// Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions -// -// @param petId ID of pet that needs to be fetched -// -// -// @return SWGPet* +/// +/// +/// Find pet by ID +/// Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions +/// +/// @param petId ID of pet that needs to be fetched +/// +/// +/// @return SWGPet* -(NSNumber*) getPetByIdWithCompletionBlock :(NSNumber*) petId completionHandler: (void (^)(SWGPet* output, NSError* error))completionBlock; -// -// -// Updates a pet in the store with form data -// -// -// @param petId ID of pet that needs to be updated -// @param name Updated name of the pet -// @param status Updated status of the pet -// -// -// @return +/// +/// +/// Updates a pet in the store with form data +/// +/// +/// @param petId ID of pet that needs to be updated +/// @param name Updated name of the pet +/// @param status Updated status of the pet +/// +/// +/// @return -(NSNumber*) updatePetWithFormWithCompletionBlock :(NSString*) petId name:(NSString*) name status:(NSString*) status @@ -109,16 +109,16 @@ completionHandler: (void (^)(NSError* error))completionBlock; -// -// -// Deletes a pet -// -// -// @param apiKey -// @param petId Pet id to delete -// -// -// @return +/// +/// +/// Deletes a pet +/// +/// +/// @param apiKey +/// @param petId Pet id to delete +/// +/// +/// @return -(NSNumber*) deletePetWithCompletionBlock :(NSString*) apiKey petId:(NSNumber*) petId @@ -126,17 +126,17 @@ completionHandler: (void (^)(NSError* error))completionBlock; -// -// -// uploads an image -// -// -// @param petId ID of pet to update -// @param additionalMetadata Additional data to pass to server -// @param file file to upload -// -// -// @return +/// +/// +/// uploads an image +/// +/// +/// @param petId ID of pet to update +/// @param additionalMetadata Additional data to pass to server +/// @param file file to upload +/// +/// +/// @return -(NSNumber*) uploadFileWithCompletionBlock :(NSNumber*) petId additionalMetadata:(NSString*) additionalMetadata file:(SWGFile*) file diff --git a/samples/client/petstore/objc/client/SWGPetApi.m b/samples/client/petstore/objc/client/SWGPetApi.m index d23a2ce9979..e4306f1b235 100644 --- a/samples/client/petstore/objc/client/SWGPetApi.m +++ b/samples/client/petstore/objc/client/SWGPetApi.m @@ -71,13 +71,15 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; return [SWGApiClient requestQueueSize]; } +#pragma mark - Api Methods -// -// Update an existing pet -// -// @param body Pet object that needs to be added to the store -// @returns void -// +/// +/// Update an existing pet +/// +/// @param body Pet object that needs to be added to the store +/// +/// @returns void +/// -(NSNumber*) updatePetWithCompletionBlock: (SWGPet*) body @@ -168,12 +170,13 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; ]; } -// -// Add a new pet to the store -// -// @param body Pet object that needs to be added to the store -// @returns void -// +/// +/// Add a new pet to the store +/// +/// @param body Pet object that needs to be added to the store +/// +/// @returns void +/// -(NSNumber*) addPetWithCompletionBlock: (SWGPet*) body @@ -264,12 +267,13 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; ]; } -// -// Finds Pets by status -// Multiple status values can be provided with comma seperated strings -// @param status Status values that need to be considered for filter -// @returns NSArray* -// +/// +/// Finds Pets by status +/// Multiple status values can be provided with comma seperated strings +/// @param status Status values that need to be considered for filter +/// +/// @returns NSArray* +/// -(NSNumber*) findPetsByStatusWithCompletionBlock: (NSArray*) status completionHandler: (void (^)(NSArray* output, NSError* error))completionBlock @@ -343,12 +347,13 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; ]; } -// -// Finds Pets by tags -// Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing. -// @param tags Tags to filter by -// @returns NSArray* -// +/// +/// Finds Pets by tags +/// Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing. +/// @param tags Tags to filter by +/// +/// @returns NSArray* +/// -(NSNumber*) findPetsByTagsWithCompletionBlock: (NSArray*) tags completionHandler: (void (^)(NSArray* output, NSError* error))completionBlock @@ -422,12 +427,13 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; ]; } -// -// Find pet by ID -// Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions -// @param petId ID of pet that needs to be fetched -// @returns SWGPet* -// +/// +/// Find pet by ID +/// Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions +/// @param petId ID of pet that needs to be fetched +/// +/// @returns SWGPet* +/// -(NSNumber*) getPetByIdWithCompletionBlock: (NSNumber*) petId completionHandler: (void (^)(SWGPet* output, NSError* error))completionBlock @@ -499,14 +505,17 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; ]; } -// -// Updates a pet in the store with form data -// -// @param petId ID of pet that needs to be updated -// @param name Updated name of the pet -// @param status Updated status of the pet -// @returns void -// +/// +/// Updates a pet in the store with form data +/// +/// @param petId ID of pet that needs to be updated +/// +/// @param name Updated name of the pet +/// +/// @param status Updated status of the pet +/// +/// @returns void +/// -(NSNumber*) updatePetWithFormWithCompletionBlock: (NSString*) petId name: (NSString*) name status: (NSString*) status @@ -596,13 +605,15 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; ]; } -// -// Deletes a pet -// -// @param apiKey -// @param petId Pet id to delete -// @returns void -// +/// +/// Deletes a pet +/// +/// @param apiKey +/// +/// @param petId Pet id to delete +/// +/// @returns void +/// -(NSNumber*) deletePetWithCompletionBlock: (NSString*) apiKey petId: (NSNumber*) petId @@ -677,14 +688,17 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; ]; } -// -// uploads an image -// -// @param petId ID of pet to update -// @param additionalMetadata Additional data to pass to server -// @param file file to upload -// @returns void -// +/// +/// uploads an image +/// +/// @param petId ID of pet to update +/// +/// @param additionalMetadata Additional data to pass to server +/// +/// @param file file to upload +/// +/// @returns void +/// -(NSNumber*) uploadFileWithCompletionBlock: (NSNumber*) petId additionalMetadata: (NSString*) additionalMetadata file: (SWGFile*) file diff --git a/samples/client/petstore/objc/client/SWGStoreApi.h b/samples/client/petstore/objc/client/SWGStoreApi.h index a59d861bbb8..7488c1baa70 100644 --- a/samples/client/petstore/objc/client/SWGStoreApi.h +++ b/samples/client/petstore/objc/client/SWGStoreApi.h @@ -14,58 +14,58 @@ +(SWGStoreApi*) apiWithHeader:(NSString*)headerValue key:(NSString*)key; +(void) setBasePath:(NSString*)basePath; +(NSString*) getBasePath; -// -// -// Returns pet inventories by status -// Returns a map of status codes to quantities -// -// -// -// @return NSDictionary* /* NSString, NSNumber */ +/// +/// +/// Returns pet inventories by status +/// Returns a map of status codes to quantities +/// +/// +/// +/// @return NSDictionary* /* NSString, NSNumber */ -(NSNumber*) getInventoryWithCompletionBlock : (void (^)(NSDictionary* /* NSString, NSNumber */ output, NSError* error))completionBlock; -// -// -// Place an order for a pet -// -// -// @param body order placed for purchasing the pet -// -// -// @return SWGOrder* +/// +/// +/// Place an order for a pet +/// +/// +/// @param body order placed for purchasing the pet +/// +/// +/// @return SWGOrder* -(NSNumber*) placeOrderWithCompletionBlock :(SWGOrder*) body completionHandler: (void (^)(SWGOrder* output, NSError* error))completionBlock; -// -// -// Find purchase order by ID -// For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions -// -// @param orderId ID of pet that needs to be fetched -// -// -// @return SWGOrder* +/// +/// +/// Find purchase order by ID +/// For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions +/// +/// @param orderId ID of pet that needs to be fetched +/// +/// +/// @return SWGOrder* -(NSNumber*) getOrderByIdWithCompletionBlock :(NSString*) orderId completionHandler: (void (^)(SWGOrder* output, NSError* error))completionBlock; -// -// -// Delete purchase order by ID -// For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors -// -// @param orderId ID of the order that needs to be deleted -// -// -// @return +/// +/// +/// Delete purchase order by ID +/// For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors +/// +/// @param orderId ID of the order that needs to be deleted +/// +/// +/// @return -(NSNumber*) deleteOrderWithCompletionBlock :(NSString*) orderId diff --git a/samples/client/petstore/objc/client/SWGStoreApi.m b/samples/client/petstore/objc/client/SWGStoreApi.m index 2613f8b6caf..98582602027 100644 --- a/samples/client/petstore/objc/client/SWGStoreApi.m +++ b/samples/client/petstore/objc/client/SWGStoreApi.m @@ -70,12 +70,13 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; return [SWGApiClient requestQueueSize]; } +#pragma mark - Api Methods -// -// Returns pet inventories by status -// Returns a map of status codes to quantities -// @returns NSDictionary* /* NSString, NSNumber */ -// +/// +/// Returns pet inventories by status +/// Returns a map of status codes to quantities +/// @returns NSDictionary* /* NSString, NSNumber */ +/// -(NSNumber*) getInventoryWithCompletionBlock: (void (^)(NSDictionary* /* NSString, NSNumber */ output, NSError* error))completionBlock { @@ -142,12 +143,13 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; ]; } -// -// Place an order for a pet -// -// @param body order placed for purchasing the pet -// @returns SWGOrder* -// +/// +/// Place an order for a pet +/// +/// @param body order placed for purchasing the pet +/// +/// @returns SWGOrder* +/// -(NSNumber*) placeOrderWithCompletionBlock: (SWGOrder*) body completionHandler: (void (^)(SWGOrder* output, NSError* error))completionBlock @@ -238,12 +240,13 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; ]; } -// -// Find purchase order by ID -// For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions -// @param orderId ID of pet that needs to be fetched -// @returns SWGOrder* -// +/// +/// Find purchase order by ID +/// For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions +/// @param orderId ID of pet that needs to be fetched +/// +/// @returns SWGOrder* +/// -(NSNumber*) getOrderByIdWithCompletionBlock: (NSString*) orderId completionHandler: (void (^)(SWGOrder* output, NSError* error))completionBlock @@ -315,12 +318,13 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; ]; } -// -// Delete purchase order by ID -// For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors -// @param orderId ID of the order that needs to be deleted -// @returns void -// +/// +/// Delete purchase order by ID +/// For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors +/// @param orderId ID of the order that needs to be deleted +/// +/// @returns void +/// -(NSNumber*) deleteOrderWithCompletionBlock: (NSString*) orderId diff --git a/samples/client/petstore/objc/client/SWGUserApi.h b/samples/client/petstore/objc/client/SWGUserApi.h index c26046a17c6..6fda87cca70 100644 --- a/samples/client/petstore/objc/client/SWGUserApi.h +++ b/samples/client/petstore/objc/client/SWGUserApi.h @@ -14,61 +14,61 @@ +(SWGUserApi*) apiWithHeader:(NSString*)headerValue key:(NSString*)key; +(void) setBasePath:(NSString*)basePath; +(NSString*) getBasePath; -// -// -// Create user -// This can only be done by the logged in user. -// -// @param body Created user object -// -// -// @return +/// +/// +/// Create user +/// This can only be done by the logged in user. +/// +/// @param body Created user object +/// +/// +/// @return -(NSNumber*) createUserWithCompletionBlock :(SWGUser*) body completionHandler: (void (^)(NSError* error))completionBlock; -// -// -// Creates list of users with given input array -// -// -// @param body List of user object -// -// -// @return +/// +/// +/// Creates list of users with given input array +/// +/// +/// @param body List of user object +/// +/// +/// @return -(NSNumber*) createUsersWithArrayInputWithCompletionBlock :(NSArray*) body completionHandler: (void (^)(NSError* error))completionBlock; -// -// -// Creates list of users with given input array -// -// -// @param body List of user object -// -// -// @return +/// +/// +/// Creates list of users with given input array +/// +/// +/// @param body List of user object +/// +/// +/// @return -(NSNumber*) createUsersWithListInputWithCompletionBlock :(NSArray*) body completionHandler: (void (^)(NSError* error))completionBlock; -// -// -// Logs user into the system -// -// -// @param username The user name for login -// @param password The password for login in clear text -// -// -// @return NSString* +/// +/// +/// Logs user into the system +/// +/// +/// @param username The user name for login +/// @param password The password for login in clear text +/// +/// +/// @return NSString* -(NSNumber*) loginUserWithCompletionBlock :(NSString*) username password:(NSString*) password @@ -76,44 +76,44 @@ -// -// -// Logs out current logged in user session -// -// -// -// -// @return +/// +/// +/// Logs out current logged in user session +/// +/// +/// +/// +/// @return -(NSNumber*) logoutUserWithCompletionBlock : (void (^)(NSError* error))completionBlock; -// -// -// Get user by user name -// -// -// @param username The name that needs to be fetched. Use user1 for testing. -// -// -// @return SWGUser* +/// +/// +/// Get user by user name +/// +/// +/// @param username The name that needs to be fetched. Use user1 for testing. +/// +/// +/// @return SWGUser* -(NSNumber*) getUserByNameWithCompletionBlock :(NSString*) username completionHandler: (void (^)(SWGUser* output, NSError* error))completionBlock; -// -// -// Updated user -// This can only be done by the logged in user. -// -// @param username name that need to be deleted -// @param body Updated user object -// -// -// @return +/// +/// +/// Updated user +/// This can only be done by the logged in user. +/// +/// @param username name that need to be deleted +/// @param body Updated user object +/// +/// +/// @return -(NSNumber*) updateUserWithCompletionBlock :(NSString*) username body:(SWGUser*) body @@ -121,15 +121,15 @@ completionHandler: (void (^)(NSError* error))completionBlock; -// -// -// Delete user -// This can only be done by the logged in user. -// -// @param username The name that needs to be deleted -// -// -// @return +/// +/// +/// Delete user +/// This can only be done by the logged in user. +/// +/// @param username The name that needs to be deleted +/// +/// +/// @return -(NSNumber*) deleteUserWithCompletionBlock :(NSString*) username diff --git a/samples/client/petstore/objc/client/SWGUserApi.m b/samples/client/petstore/objc/client/SWGUserApi.m index 3ef45ea1e77..2e8ce66b74e 100644 --- a/samples/client/petstore/objc/client/SWGUserApi.m +++ b/samples/client/petstore/objc/client/SWGUserApi.m @@ -70,13 +70,15 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; return [SWGApiClient requestQueueSize]; } +#pragma mark - Api Methods -// -// Create user -// This can only be done by the logged in user. -// @param body Created user object -// @returns void -// +/// +/// Create user +/// This can only be done by the logged in user. +/// @param body Created user object +/// +/// @returns void +/// -(NSNumber*) createUserWithCompletionBlock: (SWGUser*) body @@ -167,12 +169,13 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; ]; } -// -// Creates list of users with given input array -// -// @param body List of user object -// @returns void -// +/// +/// Creates list of users with given input array +/// +/// @param body List of user object +/// +/// @returns void +/// -(NSNumber*) createUsersWithArrayInputWithCompletionBlock: (NSArray*) body @@ -263,12 +266,13 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; ]; } -// -// Creates list of users with given input array -// -// @param body List of user object -// @returns void -// +/// +/// Creates list of users with given input array +/// +/// @param body List of user object +/// +/// @returns void +/// -(NSNumber*) createUsersWithListInputWithCompletionBlock: (NSArray*) body @@ -359,13 +363,15 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; ]; } -// -// Logs user into the system -// -// @param username The user name for login -// @param password The password for login in clear text -// @returns NSString* -// +/// +/// Logs user into the system +/// +/// @param username The user name for login +/// +/// @param password The password for login in clear text +/// +/// @returns NSString* +/// -(NSNumber*) loginUserWithCompletionBlock: (NSString*) username password: (NSString*) password @@ -442,11 +448,11 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; ]; } -// -// Logs out current logged in user session -// -// @returns void -// +/// +/// Logs out current logged in user session +/// +/// @returns void +/// -(NSNumber*) logoutUserWithCompletionBlock: (void (^)(NSError* error))completionBlock { @@ -513,12 +519,13 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; ]; } -// -// Get user by user name -// -// @param username The name that needs to be fetched. Use user1 for testing. -// @returns SWGUser* -// +/// +/// Get user by user name +/// +/// @param username The name that needs to be fetched. Use user1 for testing. +/// +/// @returns SWGUser* +/// -(NSNumber*) getUserByNameWithCompletionBlock: (NSString*) username completionHandler: (void (^)(SWGUser* output, NSError* error))completionBlock @@ -590,13 +597,15 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; ]; } -// -// Updated user -// This can only be done by the logged in user. -// @param username name that need to be deleted -// @param body Updated user object -// @returns void -// +/// +/// Updated user +/// This can only be done by the logged in user. +/// @param username name that need to be deleted +/// +/// @param body Updated user object +/// +/// @returns void +/// -(NSNumber*) updateUserWithCompletionBlock: (NSString*) username body: (SWGUser*) body @@ -692,12 +701,13 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; ]; } -// -// Delete user -// This can only be done by the logged in user. -// @param username The name that needs to be deleted -// @returns void -// +/// +/// Delete user +/// This can only be done by the logged in user. +/// @param username The name that needs to be deleted +/// +/// @returns void +/// -(NSNumber*) deleteUserWithCompletionBlock: (NSString*) username From 8b15416be5eb405174d6d147723f7a0ce9d11005 Mon Sep 17 00:00:00 2001 From: geekerzp Date: Sat, 13 Jun 2015 17:31:48 +0800 Subject: [PATCH 5/7] Add SWGJSONResponseSerializer for objective-c client. If the response data is valid json, return the deserialized json. If the response data is invalid json, return the string of response data. --- .../codegen/languages/ObjcClientCodegen.java | 2 + .../resources/objc/SWGApiClient-body.mustache | 5 ++ .../SWGJSONResponseSerializer-body.mustache | 28 +++++++++++ .../SWGJSONResponseSerializer-header.mustache | 6 +++ .../PetstoreClientTests/StoreApiTest.m | 5 +- .../PetstoreClientTests/UserApiTest.m | 47 +++++++++++++++++++ .../SwaggerClient.xcodeproj/project.pbxproj | 10 ++++ .../SwaggerClient/ViewController.m | 6 +++ .../SwaggerClientTests/SWGApiClientTest.m | 8 +++- .../petstore/objc/client/SWGApiClient.m | 5 ++ .../objc/client/SWGJSONResponseSerializer.h | 6 +++ .../objc/client/SWGJSONResponseSerializer.m | 28 +++++++++++ 12 files changed, 151 insertions(+), 5 deletions(-) create mode 100644 modules/swagger-codegen/src/main/resources/objc/SWGJSONResponseSerializer-body.mustache create mode 100644 modules/swagger-codegen/src/main/resources/objc/SWGJSONResponseSerializer-header.mustache create mode 100644 samples/client/petstore/objc/PetstoreClient/PetstoreClientTests/UserApiTest.m create mode 100644 samples/client/petstore/objc/client/SWGJSONResponseSerializer.h create mode 100644 samples/client/petstore/objc/client/SWGJSONResponseSerializer.m 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 ce3ec065012..ddd4d0c53ff 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 @@ -145,6 +145,8 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig { supportingFiles.add(new SupportingFile("SWGQueryParamCollection.m", sourceFolder, "SWGQueryParamCollection.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("SWGJSONResponseSerializer-header.mustache", sourceFolder, "SWGJSONResponseSerializer.h")); + supportingFiles.add(new SupportingFile("SWGJSONResponseSerializer-body.mustache", sourceFolder, "SWGJSONResponseSerializer.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")); diff --git a/modules/swagger-codegen/src/main/resources/objc/SWGApiClient-body.mustache b/modules/swagger-codegen/src/main/resources/objc/SWGApiClient-body.mustache index a0c9c63d27c..39ad87c76bb 100644 --- a/modules/swagger-codegen/src/main/resources/objc/SWGApiClient-body.mustache +++ b/modules/swagger-codegen/src/main/resources/objc/SWGApiClient-body.mustache @@ -359,6 +359,11 @@ static bool loggingEnabled = true; NSMutableArray *resultArray = nil; NSMutableDictionary *resultDict = nil; + // return nil if data is nil + if (!data) { + return nil; + } + // remove "*" from class, if ends with "*" if ([class hasSuffix:@"*"]) { class = [class substringToIndex:[class length] - 1]; diff --git a/modules/swagger-codegen/src/main/resources/objc/SWGJSONResponseSerializer-body.mustache b/modules/swagger-codegen/src/main/resources/objc/SWGJSONResponseSerializer-body.mustache new file mode 100644 index 00000000000..80fd09f6954 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/objc/SWGJSONResponseSerializer-body.mustache @@ -0,0 +1,28 @@ +#import "SWGJSONResponseSerializer.h" + +static BOOL JSONParseError(NSError *error) { + if ([error.domain isEqualToString:NSCocoaErrorDomain] && error.code == 3840) { + return YES; + } + + return NO; +} + +@implementation SWGJSONResponseSerializer + +- (id) responseObjectForResponse:(NSURLResponse *)response + data:(NSData *)data + error:(NSError *__autoreleasing *)error { + NSDictionary *responseJson = [super responseObjectForResponse:response data:data error:error]; + + // if response data is not a valid json, return string of data. + if (JSONParseError(*error)) { + *error = nil; + NSString *responseString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; + return responseString; + } + + return responseJson; +} + +@end diff --git a/modules/swagger-codegen/src/main/resources/objc/SWGJSONResponseSerializer-header.mustache b/modules/swagger-codegen/src/main/resources/objc/SWGJSONResponseSerializer-header.mustache new file mode 100644 index 00000000000..16cda122217 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/objc/SWGJSONResponseSerializer-header.mustache @@ -0,0 +1,6 @@ +#import +#import + +@interface SWGJSONResponseSerializer : AFJSONResponseSerializer + +@end diff --git a/samples/client/petstore/objc/PetstoreClient/PetstoreClientTests/StoreApiTest.m b/samples/client/petstore/objc/PetstoreClient/PetstoreClientTests/StoreApiTest.m index 8ea2e7ee0fc..d2864afe51d 100644 --- a/samples/client/petstore/objc/PetstoreClient/PetstoreClientTests/StoreApiTest.m +++ b/samples/client/petstore/objc/PetstoreClient/PetstoreClientTests/StoreApiTest.m @@ -32,10 +32,7 @@ XCTFail(@"failed to fetch inventory"); } - NSSet *expectKeys = [NSSet setWithArray:@[@"confused", @"string", @"available"]]; - NSSet *keys = [NSSet setWithArray:[output allKeys]]; - - XCTAssertEqualObjects(expectKeys, keys); + XCTAssertNotNil(output.allKeys); [expectation fulfill]; }]; diff --git a/samples/client/petstore/objc/PetstoreClient/PetstoreClientTests/UserApiTest.m b/samples/client/petstore/objc/PetstoreClient/PetstoreClientTests/UserApiTest.m new file mode 100644 index 00000000000..b703797a280 --- /dev/null +++ b/samples/client/petstore/objc/PetstoreClient/PetstoreClientTests/UserApiTest.m @@ -0,0 +1,47 @@ +#import +#import +#import "SWGUserApi.h" + +@interface UserApiTest : XCTestCase + +@property (nonatomic) SWGUserApi *api; + +@end + +@implementation UserApiTest + +- (void)setUp { + [super setUp]; + self.api = [[SWGUserApi alloc] init]; +} + +- (void)tearDown { + [super tearDown]; +} + +- (void)testLoginUser { + XCTestExpectation *expectation = [self expectationWithDescription:@"test login user"]; + + [self.api loginUserWithCompletionBlock:@"test username" password:@"test password" completionHandler:^(NSString *output, NSError *error) { + if (error) { + XCTFail(@"got error %@", error); + } + + if (!output) { + XCTFail(@"response can't be nil"); + } + + NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"logged in user" + options:0 + error:nil]; + NSTextCheckingResult *match = [regex firstMatchInString:output + options:0 + range:NSMakeRange(0, [output length])]; + XCTAssertNotNil(match); + [expectation fulfill]; + }]; + + [self waitForExpectationsWithTimeout:10.0 handler:nil]; +} + +@end diff --git a/samples/client/petstore/objc/SwaggerClient/SwaggerClient.xcodeproj/project.pbxproj b/samples/client/petstore/objc/SwaggerClient/SwaggerClient.xcodeproj/project.pbxproj index ffb61953051..ac15f78e357 100644 --- a/samples/client/petstore/objc/SwaggerClient/SwaggerClient.xcodeproj/project.pbxproj +++ b/samples/client/petstore/objc/SwaggerClient/SwaggerClient.xcodeproj/project.pbxproj @@ -10,7 +10,9 @@ BA525648922D4C0E9F44D4F1 /* libPods.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 73DA4F1067C343C3962F1542 /* libPods.a */; }; CF0560EB1B1855CF00C0D4EC /* SWGConfiguration.m in Sources */ = {isa = PBXBuildFile; fileRef = CF0560EA1B1855CF00C0D4EC /* SWGConfiguration.m */; }; CF31D0991B105E4B00509935 /* SWGApiClientTest.m in Sources */ = {isa = PBXBuildFile; fileRef = CF31D0981B105E4B00509935 /* SWGApiClientTest.m */; }; + CF5B6E2D1B2BD70800862A1C /* UserApiTest.m in Sources */ = {isa = PBXBuildFile; fileRef = CF5B6E2C1B2BD70800862A1C /* UserApiTest.m */; }; CFB37D061B2B11DD00D2E5F1 /* StoreApiTest.m in Sources */ = {isa = PBXBuildFile; fileRef = CFB37D051B2B11DC00D2E5F1 /* StoreApiTest.m */; }; + CFCEFE511B2C1330006313BE /* SWGJSONResponseSerializer.m in Sources */ = {isa = PBXBuildFile; fileRef = CFCEFE501B2C1330006313BE /* SWGJSONResponseSerializer.m */; }; CFD1B6701B05EC7D00DCCD51 /* JSONValueTransformer+ISO8601.m in Sources */ = {isa = PBXBuildFile; fileRef = CFD1B66F1B05EC7D00DCCD51 /* JSONValueTransformer+ISO8601.m */; }; CFD1B6711B05EC7D00DCCD51 /* JSONValueTransformer+ISO8601.m in Sources */ = {isa = PBXBuildFile; fileRef = CFD1B66F1B05EC7D00DCCD51 /* JSONValueTransformer+ISO8601.m */; }; EA66999A1811D2FA00A70D03 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EA6699991811D2FA00A70D03 /* Foundation.framework */; }; @@ -61,7 +63,10 @@ CF0560E91B1855CF00C0D4EC /* SWGConfiguration.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SWGConfiguration.h; sourceTree = ""; }; CF0560EA1B1855CF00C0D4EC /* SWGConfiguration.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SWGConfiguration.m; sourceTree = ""; }; CF31D0981B105E4B00509935 /* SWGApiClientTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SWGApiClientTest.m; sourceTree = ""; }; + CF5B6E2C1B2BD70800862A1C /* UserApiTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UserApiTest.m; sourceTree = ""; }; CFB37D051B2B11DC00D2E5F1 /* StoreApiTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = StoreApiTest.m; sourceTree = ""; }; + CFCEFE4F1B2C1330006313BE /* SWGJSONResponseSerializer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SWGJSONResponseSerializer.h; sourceTree = ""; }; + CFCEFE501B2C1330006313BE /* SWGJSONResponseSerializer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SWGJSONResponseSerializer.m; sourceTree = ""; }; CFD1B66E1B05EC7D00DCCD51 /* JSONValueTransformer+ISO8601.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "JSONValueTransformer+ISO8601.h"; sourceTree = ""; }; CFD1B66F1B05EC7D00DCCD51 /* JSONValueTransformer+ISO8601.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "JSONValueTransformer+ISO8601.m"; sourceTree = ""; }; E2B6DA00BE52336E23783686 /* Pods.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.debug.xcconfig; path = "../Pods/Target Support Files/Pods/Pods.debug.xcconfig"; sourceTree = ""; }; @@ -214,6 +219,7 @@ isa = PBXGroup; children = ( EA8CD3EB1AC274BE00C47D0B /* PetApiTest.h */, + CF5B6E2C1B2BD70800862A1C /* UserApiTest.m */, CFB37D051B2B11DC00D2E5F1 /* StoreApiTest.m */, CF31D0981B105E4B00509935 /* SWGApiClientTest.m */, EA6699C71811D2FB00A70D03 /* PetApiTest.m */, @@ -251,6 +257,8 @@ EAEA85D61811D3AE00F06E69 /* SWGOrder.h */, EAEA85D71811D3AE00F06E69 /* SWGOrder.m */, EAB26B0E1AC8E692002F5C7A /* SWGPet.h */, + CFCEFE4F1B2C1330006313BE /* SWGJSONResponseSerializer.h */, + CFCEFE501B2C1330006313BE /* SWGJSONResponseSerializer.m */, EAEA85D91811D3AE00F06E69 /* SWGPet.m */, EAEA85DA1811D3AE00F06E69 /* SWGPetApi.h */, EAEA85DB1811D3AE00F06E69 /* SWGPetApi.m */, @@ -418,6 +426,7 @@ EAEA85E91811D3AE00F06E69 /* SWGOrder.m in Sources */, EAEA85E81811D3AE00F06E69 /* SWGObject.m in Sources */, EA8B8AA41AC6683700638FBB /* SWGQueryParamCollection.m in Sources */, + CFCEFE511B2C1330006313BE /* SWGJSONResponseSerializer.m in Sources */, EAEA85E71811D3AE00F06E69 /* SWGFile.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -429,6 +438,7 @@ EAB26B0C1AC8DF78002F5C7A /* PetApiTest.h in Sources */, CFD1B6711B05EC7D00DCCD51 /* JSONValueTransformer+ISO8601.m in Sources */, EAB26B0D1AC8DF78002F5C7A /* PetApiTest.m in Sources */, + CF5B6E2D1B2BD70800862A1C /* UserApiTest.m in Sources */, CFB37D061B2B11DD00D2E5F1 /* StoreApiTest.m in Sources */, CF31D0991B105E4B00509935 /* SWGApiClientTest.m in Sources */, ); diff --git a/samples/client/petstore/objc/SwaggerClient/SwaggerClient/ViewController.m b/samples/client/petstore/objc/SwaggerClient/SwaggerClient/ViewController.m index 56d0a8f621f..5ba0fe18382 100644 --- a/samples/client/petstore/objc/SwaggerClient/SwaggerClient/ViewController.m +++ b/samples/client/petstore/objc/SwaggerClient/SwaggerClient/ViewController.m @@ -9,6 +9,7 @@ #import "ViewController.h" #import "SWGPetApi.h" #import "SWGStoreApi.h" +#import "SWGUserApi.h" #import "SWGConfiguration.h" @interface ViewController () @@ -55,6 +56,11 @@ // } ]; */ + SWGUserApi *api = [[SWGUserApi alloc] init]; + [api loginUserWithCompletionBlock:@"username" password:@"password" completionHandler:^(NSString *output, NSError *error) { + NSLog(@"output => %@", output); + NSLog(@"error => %@", error); + }]; } - (void)didReceiveMemoryWarning diff --git a/samples/client/petstore/objc/SwaggerClient/SwaggerClientTests/SWGApiClientTest.m b/samples/client/petstore/objc/SwaggerClient/SwaggerClientTests/SWGApiClientTest.m index 597cf2fb714..c68b3e2a42e 100644 --- a/samples/client/petstore/objc/SwaggerClient/SwaggerClientTests/SWGApiClientTest.m +++ b/samples/client/petstore/objc/SwaggerClient/SwaggerClientTests/SWGApiClientTest.m @@ -160,9 +160,15 @@ XCTAssertEqualObjects([result[@"pet"] _id], @119); // pure object - result = [self.apiClient deserialize:nil class:@"NSObject*"]; + result = [self.apiClient deserialize:@"" class:@"NSObject*"]; XCTAssertTrue([result isKindOfClass:[NSObject class]]); + + // NSString + data = @"test string"; + result = [self.apiClient deserialize:data class:@"NSString*"]; + + XCTAssertTrue([result isKindOfClass:[NSString class]]); } @end diff --git a/samples/client/petstore/objc/client/SWGApiClient.m b/samples/client/petstore/objc/client/SWGApiClient.m index a0c9c63d27c..39ad87c76bb 100644 --- a/samples/client/petstore/objc/client/SWGApiClient.m +++ b/samples/client/petstore/objc/client/SWGApiClient.m @@ -359,6 +359,11 @@ static bool loggingEnabled = true; NSMutableArray *resultArray = nil; NSMutableDictionary *resultDict = nil; + // return nil if data is nil + if (!data) { + return nil; + } + // remove "*" from class, if ends with "*" if ([class hasSuffix:@"*"]) { class = [class substringToIndex:[class length] - 1]; diff --git a/samples/client/petstore/objc/client/SWGJSONResponseSerializer.h b/samples/client/petstore/objc/client/SWGJSONResponseSerializer.h new file mode 100644 index 00000000000..16cda122217 --- /dev/null +++ b/samples/client/petstore/objc/client/SWGJSONResponseSerializer.h @@ -0,0 +1,6 @@ +#import +#import + +@interface SWGJSONResponseSerializer : AFJSONResponseSerializer + +@end diff --git a/samples/client/petstore/objc/client/SWGJSONResponseSerializer.m b/samples/client/petstore/objc/client/SWGJSONResponseSerializer.m new file mode 100644 index 00000000000..80fd09f6954 --- /dev/null +++ b/samples/client/petstore/objc/client/SWGJSONResponseSerializer.m @@ -0,0 +1,28 @@ +#import "SWGJSONResponseSerializer.h" + +static BOOL JSONParseError(NSError *error) { + if ([error.domain isEqualToString:NSCocoaErrorDomain] && error.code == 3840) { + return YES; + } + + return NO; +} + +@implementation SWGJSONResponseSerializer + +- (id) responseObjectForResponse:(NSURLResponse *)response + data:(NSData *)data + error:(NSError *__autoreleasing *)error { + NSDictionary *responseJson = [super responseObjectForResponse:response data:data error:error]; + + // if response data is not a valid json, return string of data. + if (JSONParseError(*error)) { + *error = nil; + NSString *responseString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; + return responseString; + } + + return responseJson; +} + +@end From a4df33d04083a54b6ea7650089a24a0e556fccc4 Mon Sep 17 00:00:00 2001 From: geekerzp Date: Sat, 13 Jun 2015 17:49:39 +0800 Subject: [PATCH 6/7] Add comments for SWGJSONResponseSerializer#responseObjectForResponse method of objective-c client. --- .../objc/SWGJSONResponseSerializer-body.mustache | 11 +++++++++++ .../petstore/objc/client/SWGJSONResponseSerializer.m | 11 +++++++++++ 2 files changed, 22 insertions(+) diff --git a/modules/swagger-codegen/src/main/resources/objc/SWGJSONResponseSerializer-body.mustache b/modules/swagger-codegen/src/main/resources/objc/SWGJSONResponseSerializer-body.mustache index 80fd09f6954..a2dd21bcf5d 100644 --- a/modules/swagger-codegen/src/main/resources/objc/SWGJSONResponseSerializer-body.mustache +++ b/modules/swagger-codegen/src/main/resources/objc/SWGJSONResponseSerializer-body.mustache @@ -10,6 +10,17 @@ static BOOL JSONParseError(NSError *error) { @implementation SWGJSONResponseSerializer +/// +/// When customize a response serializer, +/// the serializer must conform the protocol `AFURLResponseSerialization` +/// and implements the protocol method `responseObjectForResponse:error:` +/// +/// @param response The response to be processed. +/// @param data The response data to be decoded. +/// @param error The error that occurred while attempting to decode the respnse data. +/// +/// @return The object decoded from the specified response data. +/// - (id) responseObjectForResponse:(NSURLResponse *)response data:(NSData *)data error:(NSError *__autoreleasing *)error { diff --git a/samples/client/petstore/objc/client/SWGJSONResponseSerializer.m b/samples/client/petstore/objc/client/SWGJSONResponseSerializer.m index 80fd09f6954..a2dd21bcf5d 100644 --- a/samples/client/petstore/objc/client/SWGJSONResponseSerializer.m +++ b/samples/client/petstore/objc/client/SWGJSONResponseSerializer.m @@ -10,6 +10,17 @@ static BOOL JSONParseError(NSError *error) { @implementation SWGJSONResponseSerializer +/// +/// When customize a response serializer, +/// the serializer must conform the protocol `AFURLResponseSerialization` +/// and implements the protocol method `responseObjectForResponse:error:` +/// +/// @param response The response to be processed. +/// @param data The response data to be decoded. +/// @param error The error that occurred while attempting to decode the respnse data. +/// +/// @return The object decoded from the specified response data. +/// - (id) responseObjectForResponse:(NSURLResponse *)response data:(NSData *)data error:(NSError *__autoreleasing *)error { From 6b6480a026604c8ed1bc6441270eea54a82b1080 Mon Sep 17 00:00:00 2001 From: geekerzp Date: Thu, 18 Jun 2015 10:38:19 +0800 Subject: [PATCH 7/7] Updated xcode project of objc client --- .../codegen/languages/ObjcClientCodegen.java | 2 +- .../resources/objc/SWGApiClient-body.mustache | 2 +- .../objc/SWGApiClient-header.mustache | 1 + .../xcshareddata/SwaggerClient.xccheckout | 41 ++++++++++++++++++ .../UserInterfaceState.xcuserstate | Bin 7666 -> 16336 bytes .../xcdebugger/Breakpoints_v2.xcbkptlist | 17 ++++++++ .../SwaggerClient/ViewController.m | 13 +++--- .../SwaggerClientTests}/StoreApiTest.m | 0 .../SwaggerClientTests}/UserApiTest.m | 0 .../petstore/objc/client/SWGApiClient.h | 1 + .../petstore/objc/client/SWGApiClient.m | 2 +- 11 files changed, 71 insertions(+), 8 deletions(-) create mode 100644 samples/client/petstore/objc/SwaggerClient.xcworkspace/xcshareddata/SwaggerClient.xccheckout create mode 100644 samples/client/petstore/objc/SwaggerClient.xcworkspace/xcuserdata/geekerzp.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist rename samples/client/petstore/objc/{PetstoreClient/PetstoreClientTests => SwaggerClient/SwaggerClientTests}/StoreApiTest.m (100%) rename samples/client/petstore/objc/{PetstoreClient/PetstoreClientTests => SwaggerClient/SwaggerClientTests}/UserApiTest.m (100%) 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 ddd4d0c53ff..03905cbdfaf 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 @@ -153,7 +153,7 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig { 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 diff --git a/modules/swagger-codegen/src/main/resources/objc/SWGApiClient-body.mustache b/modules/swagger-codegen/src/main/resources/objc/SWGApiClient-body.mustache index 39ad87c76bb..1b479d039e6 100644 --- a/modules/swagger-codegen/src/main/resources/objc/SWGApiClient-body.mustache +++ b/modules/swagger-codegen/src/main/resources/objc/SWGApiClient-body.mustache @@ -500,7 +500,7 @@ static bool loggingEnabled = true; // setting response serializer if ([responseContentType isEqualToString:@"application/json"]) { - self.responseSerializer = [AFJSONResponseSerializer serializer]; + self.responseSerializer = [SWGJSONResponseSerializer serializer]; } else { self.responseSerializer = [AFHTTPResponseSerializer serializer]; diff --git a/modules/swagger-codegen/src/main/resources/objc/SWGApiClient-header.mustache b/modules/swagger-codegen/src/main/resources/objc/SWGApiClient-header.mustache index 09cb6fe57bd..691c92cc625 100644 --- a/modules/swagger-codegen/src/main/resources/objc/SWGApiClient-header.mustache +++ b/modules/swagger-codegen/src/main/resources/objc/SWGApiClient-header.mustache @@ -1,6 +1,7 @@ #import #import #import "AFHTTPRequestOperationManager.h" +#import "SWGJSONResponseSerializer.h" {{#models}}{{#model}}#import "{{classname}}.h" {{/model}}{{/models}} diff --git a/samples/client/petstore/objc/SwaggerClient.xcworkspace/xcshareddata/SwaggerClient.xccheckout b/samples/client/petstore/objc/SwaggerClient.xcworkspace/xcshareddata/SwaggerClient.xccheckout new file mode 100644 index 00000000000..325cb92c1b8 --- /dev/null +++ b/samples/client/petstore/objc/SwaggerClient.xcworkspace/xcshareddata/SwaggerClient.xccheckout @@ -0,0 +1,41 @@ + + + + + IDESourceControlProjectFavoriteDictionaryKey + + IDESourceControlProjectIdentifier + 15AAFA18-9D61-437F-988D-A691BA4C08B1 + IDESourceControlProjectName + SwaggerClient + IDESourceControlProjectOriginsDictionary + + E5BBF0AA85077C865C95437976D06D819733A208 + https://github.com/geekerzp/swagger-codegen.git + + IDESourceControlProjectPath + samples/client/petstore/objc/SwaggerClient.xcworkspace + 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/SwaggerClient.xcworkspace/xcuserdata/geekerzp.xcuserdatad/UserInterfaceState.xcuserstate b/samples/client/petstore/objc/SwaggerClient.xcworkspace/xcuserdata/geekerzp.xcuserdatad/UserInterfaceState.xcuserstate index 79012184db63a3743953f712c7514d98f2b40464..d8a48b72bc2eb6cb0a734c22a88f15e99e0edb35 100644 GIT binary patch literal 16336 zcmd6Od3=+__V>&)PrA2Ro2_k+pPo5@i6z}zqd++qe%?*!h)BT<< z8N!!r-Xq0VqDT~lbPc)%-HHa#4zv^9j_yQvqjhK>x)0rt9z~C# zC($$LMf3_fjNU}=qW93p=r}rwzCquj@6b;;8pq&R9Eam^0v2Nlmf{qw!+LDMso03q za5~PyR$PEf@MwG<9*f80N?e7f;OTeG@g}?(Z^PU1F1#1tjqk&c;r;k={2YEBzkpxGuj6;|d-xds6n}<) z!N1~D_&5AJK8?>XVn)J985tvI6igzM#3VCDCXLBvau_R9z?3oPF_p~u%yh=Zv@oqq z8{=jcFbkP>ri1BZ7BSt-5~hz?!Ensg%sS>8W&?90a~rdX*~#3_>|*XoNA$!%a)_1Wl0s5S&LtIO9GOI>lX^0XG!Q3gBu!)?X(t_|oAi*yWC>YE zt|8Zw_2fEoJ-LBwAUBem$jxLk=_mJ*hseWZKY5%SAWxI$$qVG4hvz*?x8>yN|txy_fw5dmnp0`vChS`xJYCeVToReU&}P9%A2N-(}xpKV&~)e`0@T ze_?-RPob;W-$Y16M65_8iV($!lp?JtNu(DUMCqaoky&IB<<3m+>~3#AgrZRlibZiq zjAZrGYH}C4dVRCueMqnB(wo|yKHmU}M+uanWB^H!l(HO-p!E((de!*Sai!(93Ttsi zRf)B*s?=^RuPUpume`7m#*Hs7DlN{>cSsbI##h#RybFC@&L-D*Pg8e?tJ5ExS&4Kg zb30NYHPRq0N2;pM(HSn#?g4nGZRB4G?_LzBx;_% zyR+G|xYpTN;q*@O)wzA{#&*~IP(zj1+2L|XQsKdLZ?ntmY7Q|3W5#(p{a#OdI~Wy* zBxfYI0@>mAnVs%M-L6T^umE?9+vRmg^w7P$$q%OI>=Yf6b4L;ko6S*CR5;#d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e&g72gt1 zi*JkXiWkLyir2&&;!onw;=d)eBuE-bl7b|M)L9CVx=UeFw3HwvNhy+3N|$n_JZXe9 zQW`Cdm3-r+iBg#~ORAR|q(*6>MABkuiL^#~PTDRtNiEVIX`l3x^s;nHIwPHxu1Hs< zYtjwrrgTfXE!~lRmF{YdTC>)w4bs}R!P+j`5N&sDm^NISsvW5<)_S!*?MCe}?FZVk z+V8cOw3oG4wb!&aWQQCn_mZRKSfAWiPLNaOEP0qbT+WvZH;&k!4L|w9OfNqGc zP&Y%@pd;O4-4fk0-3r}$onN<6w@J5Iw?+4w?sMHQibd(7bX9!als-zF60amFDT-6c zQ${Egm13ntDOJjqX-bXaRc0%5l)1`sWwo+ad0N@1Y*IEWTa=y3A?2uYOgXNcP);dt zDQ_zuD(968%2&$Q%2nmM@}qJ~xvkvMqh6zz^s-*j2kX1(L-jrMJ@viyee|(~LSrv0YlrZ-I|On)|=Hoar|%=De8Zyh>^%@N{=bi_I09qEn?M~LxHad1YUUD36J2V(`+#jrK`)&Vr9QiMztmrTR diff --git a/samples/client/petstore/objc/SwaggerClient.xcworkspace/xcuserdata/geekerzp.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/samples/client/petstore/objc/SwaggerClient.xcworkspace/xcuserdata/geekerzp.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist new file mode 100644 index 00000000000..e2573a5943c --- /dev/null +++ b/samples/client/petstore/objc/SwaggerClient.xcworkspace/xcuserdata/geekerzp.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -0,0 +1,17 @@ + + + + + + + + + diff --git a/samples/client/petstore/objc/SwaggerClient/SwaggerClient/ViewController.m b/samples/client/petstore/objc/SwaggerClient/SwaggerClient/ViewController.m index 5ba0fe18382..388cacbb157 100644 --- a/samples/client/petstore/objc/SwaggerClient/SwaggerClient/ViewController.m +++ b/samples/client/petstore/objc/SwaggerClient/SwaggerClient/ViewController.m @@ -56,11 +56,14 @@ // } ]; */ - SWGUserApi *api = [[SWGUserApi alloc] init]; - [api loginUserWithCompletionBlock:@"username" password:@"password" completionHandler:^(NSString *output, NSError *error) { - NSLog(@"output => %@", output); - NSLog(@"error => %@", error); - }]; + SWGPetApi *api = [[SWGPetApi alloc] init]; + [api deletePetWithCompletionBlock:@"hello" + petId:@1434529787992 + completionHandler:^(NSError *error) { + if (error) { + NSLog(@"%@", error); + } + }]; } - (void)didReceiveMemoryWarning diff --git a/samples/client/petstore/objc/PetstoreClient/PetstoreClientTests/StoreApiTest.m b/samples/client/petstore/objc/SwaggerClient/SwaggerClientTests/StoreApiTest.m similarity index 100% rename from samples/client/petstore/objc/PetstoreClient/PetstoreClientTests/StoreApiTest.m rename to samples/client/petstore/objc/SwaggerClient/SwaggerClientTests/StoreApiTest.m diff --git a/samples/client/petstore/objc/PetstoreClient/PetstoreClientTests/UserApiTest.m b/samples/client/petstore/objc/SwaggerClient/SwaggerClientTests/UserApiTest.m similarity index 100% rename from samples/client/petstore/objc/PetstoreClient/PetstoreClientTests/UserApiTest.m rename to samples/client/petstore/objc/SwaggerClient/SwaggerClientTests/UserApiTest.m diff --git a/samples/client/petstore/objc/client/SWGApiClient.h b/samples/client/petstore/objc/client/SWGApiClient.h index 829aec58b96..6ede775cb02 100644 --- a/samples/client/petstore/objc/client/SWGApiClient.h +++ b/samples/client/petstore/objc/client/SWGApiClient.h @@ -1,6 +1,7 @@ #import #import #import "AFHTTPRequestOperationManager.h" +#import "SWGJSONResponseSerializer.h" #import "SWGUser.h" #import "SWGCategory.h" diff --git a/samples/client/petstore/objc/client/SWGApiClient.m b/samples/client/petstore/objc/client/SWGApiClient.m index 39ad87c76bb..1b479d039e6 100644 --- a/samples/client/petstore/objc/client/SWGApiClient.m +++ b/samples/client/petstore/objc/client/SWGApiClient.m @@ -500,7 +500,7 @@ static bool loggingEnabled = true; // setting response serializer if ([responseContentType isEqualToString:@"application/json"]) { - self.responseSerializer = [AFJSONResponseSerializer serializer]; + self.responseSerializer = [SWGJSONResponseSerializer serializer]; } else { self.responseSerializer = [AFHTTPResponseSerializer serializer];