From a38fbe8d21b81ea59f12ed694b180d44e4244177 Mon Sep 17 00:00:00 2001 From: Tony Tam Date: Tue, 4 Dec 2012 15:39:27 -0800 Subject: [PATCH] updated with latest codegen --- .../petstore/objc/client/NIKApiInvoker.h | 34 +- .../petstore/objc/client/NIKApiInvoker.m | 309 +++++++++------ .../client/petstore/objc/client/NIKCategory.h | 8 +- .../client/petstore/objc/client/NIKCategory.m | 33 +- .../client/petstore/objc/client/NIKOrder.h | 11 +- .../client/petstore/objc/client/NIKOrder.m | 68 ++-- samples/client/petstore/objc/client/NIKPet.h | 12 +- samples/client/petstore/objc/client/NIKPet.m | 104 ++--- .../client/petstore/objc/client/NIKPetApi.h | 48 ++- .../client/petstore/objc/client/NIKPetApi.m | 219 ++++++----- .../client/petstore/objc/client/NIKStoreApi.h | 30 +- .../client/petstore/objc/client/NIKStoreApi.m | 133 +++---- samples/client/petstore/objc/client/NIKTag.h | 8 +- samples/client/petstore/objc/client/NIKTag.m | 33 +- samples/client/petstore/objc/client/NIKUser.h | 14 +- samples/client/petstore/objc/client/NIKUser.m | 87 +++-- .../client/petstore/objc/client/NIKUserApi.h | 83 +++- .../client/petstore/objc/client/NIKUserApi.m | 354 ++++++++---------- .../client/petstore/objc/tests/PetApiTest.m | 2 +- 19 files changed, 865 insertions(+), 725 deletions(-) diff --git a/samples/client/petstore/objc/client/NIKApiInvoker.h b/samples/client/petstore/objc/client/NIKApiInvoker.h index 1e1c28aef37..4737e92b590 100644 --- a/samples/client/petstore/objc/client/NIKApiInvoker.h +++ b/samples/client/petstore/objc/client/NIKApiInvoker.h @@ -8,25 +8,31 @@ } @property(nonatomic, readonly) NSOperationQueue* queue; @property(nonatomic, readonly) NSMutableDictionary * defaultHeaders; +@property(nonatomic, assign) NSURLRequestCachePolicy cachePolicy; + ++ (NIKApiInvoker*)sharedInstance; + +- (void)updateLoadCountWithDelta:(NSInteger)countDelta; +- (void)startLoad; +- (void)stopLoad; --(void) addHeader:(NSString*) value - forKey:(NSString*)key; +-(void) addHeader:(NSString*)value forKey:(NSString*)key; -(NSString*) escapeString:(NSString*) string; --(id) dictionaryWithCompletionBlock:(NSString*) path - method:(NSString*) method - queryParams:(NSDictionary*) queryParams - body:(id)body - headerParams:(NSDictionary*) headerParams - completionHandler:(void (^)(NSDictionary*, NSError *))completionBlock; +-(void) dictionary:(NSString*) path + method:(NSString*) method + queryParams:(NSDictionary*) queryParams + body:(id)body + headerParams:(NSDictionary*) headerParams + completionBlock:(void (^)(NSDictionary*, NSError *))completionBlock; --(id) stringWithCompletionBlock:(NSString*) path - method:(NSString*) method - queryParams:(NSDictionary*) queryParams - body:(id)body - headerParams:(NSDictionary*) headerParams - completionHandler:(void (^)(NSString*, NSError *))completionBlock; +-(void) stringWithCompletionBlock:(NSString*) path + method:(NSString*) method + queryParams:(NSDictionary*) queryParams + body:(id)body + headerParams:(NSDictionary*) headerParams + completionBlock:(void (^)(NSString*, NSError *))completionBlock; @end diff --git a/samples/client/petstore/objc/client/NIKApiInvoker.m b/samples/client/petstore/objc/client/NIKApiInvoker.m index 62962375a06..1873ef724d3 100644 --- a/samples/client/petstore/objc/client/NIKApiInvoker.m +++ b/samples/client/petstore/objc/client/NIKApiInvoker.m @@ -5,10 +5,42 @@ @synthesize queue = _queue; @synthesize defaultHeaders = _defaultHeaders; + +static NSInteger __LoadingObjectsCount = 0; + ++ (NIKApiInvoker*)sharedInstance { + static NIKApiInvoker *_sharedInstance = nil; + if (!_sharedInstance) { + _sharedInstance = [[NIKApiInvoker alloc] init]; + } + return _sharedInstance; +} + +- (void)updateLoadCountWithDelta:(NSInteger)countDelta { + @synchronized(self) { + __LoadingObjectsCount += countDelta; + __LoadingObjectsCount = (__LoadingObjectsCount < 0) ? 0 : __LoadingObjectsCount ; + +#if TARGET_OS_IPHONE + [UIApplication sharedApplication].networkActivityIndicatorVisible = __LoadingObjectsCount > 0; +#endif + } +} + +- (void)startLoad { + [self updateLoadCountWithDelta:1]; +} + +- (void)stopLoad { + [self updateLoadCountWithDelta:-1]; +} + + - (id) init { self = [super init]; _queue = [[NSOperationQueue alloc] init]; _defaultHeaders = [[NSMutableDictionary alloc] init]; + _cachePolicy = NSURLRequestUseProtocolCachePolicy; return self; } @@ -19,19 +51,19 @@ -(NSString*) escapeString:(NSString *)unescaped { return (NSString *)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes( - NULL, - (__bridge CFStringRef) unescaped, - NULL, - (CFStringRef)@"!*'();:@&=+$,/?%#[]", - kCFStringEncodingUTF8)); + NULL, + (__bridge CFStringRef) unescaped, + NULL, + (CFStringRef)@"!*'();:@&=+$,/?%#[]", + kCFStringEncodingUTF8)); } --(id) dictionaryWithCompletionBlock:(NSString*) path - method:(NSString*) method - queryParams:(NSDictionary*) queryParams - body:(id) body - headerParams:(NSDictionary*) headerParams - completionHandler:(void (^)(NSDictionary*, NSError *))completionBlock +-(void) dictionary:(NSString*) path + method:(NSString*) method + queryParams:(NSDictionary*) queryParams + body:(id) body + headerParams:(NSDictionary*) headerParams + completionBlock:(void (^)(NSDictionary*, NSError *))completionBlock { NSMutableString * requestUrl = [NSMutableString stringWithFormat:@"%@", path]; NSString * separator = nil; @@ -52,108 +84,15 @@ counter += 1; } } - NSLog(@"request url: %@", requestUrl); + if ([[NSUserDefaults standardUserDefaults] boolForKey:@"RVBLogging"]) { + NSLog(@"request url: %@", requestUrl); + } NSURL* URL = [NSURL URLWithString:requestUrl]; NSMutableURLRequest* request = [[NSMutableURLRequest alloc] init]; [request setURL:URL]; - [request setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData]; - [request setTimeoutInterval:30]; - - for(NSString * key in [_defaultHeaders keyEnumerator]){ - [request setValue:[_defaultHeaders valueForKey:key] forHTTPHeaderField:key]; - } - if(headerParams != nil){ - for(NSString * key in [headerParams keyEnumerator]){ - [request setValue:[headerParams valueForKey:key] forHTTPHeaderField:key]; - } - } - [request setHTTPMethod:method]; - if(body != nil) { - NSError * error = [NSError new]; - NSData * data = nil; - if([body isKindOfClass:[NSDictionary class]]){ - data = [NSJSONSerialization dataWithJSONObject:body - options:kNilOptions error:&error]; - } - else if ([body isKindOfClass:[NSArray class]]){ - data = [NSJSONSerialization dataWithJSONObject:body - options:kNilOptions error:&error]; - } - else { - data = [body dataUsingEncoding:NSUTF8StringEncoding]; - } - NSString *postLength = [NSString stringWithFormat:@"%ld", [data length]]; - [request setValue:postLength forHTTPHeaderField:@"Content-Length"]; - [request setHTTPBody:data]; - - [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"]; - [request setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData]; - - NSLog(@"request: %@", request); - } - - [NSURLConnection sendAsynchronousRequest:request queue:_queue completionHandler: - ^(NSURLResponse *response, NSData *data, NSError *error) { - long statusCode = [(NSHTTPURLResponse*)response statusCode]; - - if (error) { - completionBlock(nil, error); - return; - } - else if (!NSLocationInRange(statusCode, NSMakeRange(200, 99))){ - error = [NSError errorWithDomain:@"swagger" - code:statusCode - userInfo:[NSJSONSerialization JSONObjectWithData:data - options:kNilOptions - error:&error]]; - completionBlock(nil, error); - return; - } - else { - NSDictionary* results = [NSJSONSerialization JSONObjectWithData:data - options:kNilOptions - error:&error]; - completionBlock(results, nil); - } - }]; - return nil; -} - --(id) stringWithCompletionBlock:(NSString*) path - method:(NSString*) method - queryParams:(NSDictionary*) queryParams - body:(id) body - headerParams:(NSDictionary*) headerParams - completionHandler:(void (^)(NSString*, NSError *))completionBlock -{ - NSMutableString * requestUrl = [NSMutableString stringWithFormat:@"%@", path]; - NSString * separator = nil; - int counter = 0; - if(queryParams != nil){ - for(NSString * key in [queryParams keyEnumerator]){ - if(counter == 0) separator = @"?"; - else separator = @"&"; - NSString * value; - if([[queryParams valueForKey:key] isKindOfClass:[NSString class]]){ - value = [self escapeString:[queryParams valueForKey:key]]; - } - else { - value = [NSString stringWithFormat:@"%@", [queryParams valueForKey:key]]; - } - [requestUrl appendFormat:[NSString stringWithFormat:@"%@%@=%@", separator, - [self escapeString:key], value]]; - counter += 1; - } - } - NSLog(@"request url: %@", requestUrl); - - NSURL* URL = [NSURL URLWithString:requestUrl]; - - NSMutableURLRequest* request = [[NSMutableURLRequest alloc] init]; - [request setURL:URL]; - [request setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData]; + [request setCachePolicy:self.cachePolicy]; [request setTimeoutInterval:30]; for(NSString * key in [_defaultHeaders keyEnumerator]){ @@ -184,14 +123,29 @@ [request setHTTPBody:data]; [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"]; - [request setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData]; - - NSLog(@"request: %@", request); } + // Handle caching on GET requests + if ((_cachePolicy == NSURLRequestReturnCacheDataElseLoad || _cachePolicy == NSURLRequestReturnCacheDataDontLoad) && [method isEqualToString:@"GET"]) { + NSCachedURLResponse *cacheResponse = [[NSURLCache sharedURLCache] cachedResponseForRequest:request]; + NSData *data = [cacheResponse data]; + if (data) { + NSError *error = nil; + NSDictionary* results = [NSJSONSerialization JSONObjectWithData:data + options:kNilOptions + error:&error]; + completionBlock(results, nil); + } + } + + if (_cachePolicy == NSURLRequestReturnCacheDataDontLoad) + return; + + [self startLoad]; + NSDate *date = [NSDate date]; [NSURLConnection sendAsynchronousRequest:request queue:_queue completionHandler: ^(NSURLResponse *response, NSData *data, NSError *error) { - int statusCode = [(NSHTTPURLResponse*)response statusCode]; + long statusCode = [(NSHTTPURLResponse*)response statusCode]; if (error) { completionBlock(nil, error); @@ -207,16 +161,143 @@ return; } else { - NSString* results = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; + NSDictionary* results = [NSJSONSerialization JSONObjectWithData:data + options:kNilOptions + error:&error]; + completionBlock(results, nil); + if ([[NSUserDefaults standardUserDefaults] boolForKey:@"RVBLogging"]) { + NSLog(@"fetched results (%f seconds): %@", [[NSDate date] timeIntervalSinceDate:date], results); + } + } + + [self stopLoad]; + }]; +} +-(void) stringWithCompletionBlock:(NSString*) path + method:(NSString*) method + queryParams:(NSDictionary*) queryParams + body:(id) body + headerParams:(NSDictionary*) headerParams + completionBlock:(void (^)(NSString*, NSError *))completionBlock +{ + NSMutableString * requestUrl = [NSMutableString stringWithFormat:@"%@", path]; + NSString * separator = nil; + int counter = 0; + if(queryParams != nil){ + for(NSString * key in [queryParams keyEnumerator]){ + if(counter == 0) separator = @"?"; + else separator = @"&"; + NSString * value; + if([[queryParams valueForKey:key] isKindOfClass:[NSString class]]){ + value = [self escapeString:[queryParams valueForKey:key]]; + } + else { + value = [NSString stringWithFormat:@"%@", [queryParams valueForKey:key]]; + } + [requestUrl appendString:[NSString stringWithFormat:@"%@%@=%@", separator, + [self escapeString:key], value]]; + counter += 1; + } + } + if ([[NSUserDefaults standardUserDefaults] boolForKey:@"RVBLogging"]) { + NSLog(@"request url: %@", requestUrl); + } + + NSURL* URL = [NSURL URLWithString:requestUrl]; + + NSMutableURLRequest* request = [[NSMutableURLRequest alloc] init]; + [request setURL:URL]; + [request setCachePolicy:self.cachePolicy]; + [request setTimeoutInterval:30]; + + for(NSString * key in [_defaultHeaders keyEnumerator]){ + [request setValue:[_defaultHeaders valueForKey:key] forHTTPHeaderField:key]; + } + if(headerParams != nil){ + for(NSString * key in [headerParams keyEnumerator]){ + [request setValue:[headerParams valueForKey:key] forHTTPHeaderField:key]; + } + } + [request setHTTPMethod:method]; + if(body != nil) { + NSError * error = [NSError new]; + NSData * data = nil; + if([body isKindOfClass:[NSDictionary class]]){ + data = [NSJSONSerialization dataWithJSONObject:body + options:kNilOptions error:&error]; + } + else if ([body isKindOfClass:[NSArray class]]){ + data = [NSJSONSerialization dataWithJSONObject:body + options:kNilOptions error:&error]; + } + else { + data = [body dataUsingEncoding:NSUTF8StringEncoding]; + } + NSString *postLength = [NSString stringWithFormat:@"%d", [data length]]; + [request setValue:postLength forHTTPHeaderField:@"Content-Length"]; + [request setHTTPBody:data]; + + [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"]; + } + + + // Handle caching on GET requests + if ((_cachePolicy == NSURLRequestReturnCacheDataElseLoad || _cachePolicy == NSURLRequestReturnCacheDataDontLoad) && [method isEqualToString:@"GET"]) { + NSCachedURLResponse *cacheResponse = [[NSURLCache sharedURLCache] cachedResponseForRequest:request]; + NSData *data = [cacheResponse data]; + if (data) { + NSString* results = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; + + if(results && [results length] >= 2) { + if(([results characterAtIndex:0] == '\"') && ([results characterAtIndex:([results length] - 1) == '\"'])){ + results = [results substringWithRange:NSMakeRange(1, [results length] -2)]; + } + } + completionBlock(results, nil); + if ([[NSUserDefaults standardUserDefaults] boolForKey:@"RVBLogging"]) { + // NSLog(@"cached results: %@", results); + } + } + + } + + if (_cachePolicy == NSURLRequestReturnCacheDataDontLoad) + return; + + [self startLoad]; + NSDate *date = [NSDate date]; + [NSURLConnection sendAsynchronousRequest:request queue:_queue completionHandler: + ^(NSURLResponse *response, NSData *data, NSError *error) { + int statusCode = [(NSHTTPURLResponse*)response statusCode]; + if (error) { + completionBlock(nil, error); + return; + } + else if (!NSLocationInRange(statusCode, NSMakeRange(200, 99))){ + error = [NSError errorWithDomain:@"swagger" + code:statusCode + userInfo:[NSJSONSerialization JSONObjectWithData:data + options:kNilOptions + error:&error]]; + completionBlock(nil, error); + return; + } + else { + NSString* results = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; + if(results && [results length] >= 2) { if(([results characterAtIndex:0] == '\"') && ([results characterAtIndex:([results length] - 1) == '\"'])){ results = [results substringWithRange:NSMakeRange(1, [results length] -2)]; } + } completionBlock(results, nil); + if ([[NSUserDefaults standardUserDefaults] boolForKey:@"RVBLogging"]) { + NSLog(@"fetched results (%f seconds): %@", [[NSDate date] timeIntervalSinceDate:date], results); + } } + [self stopLoad]; }]; - return nil; } @end \ No newline at end of file diff --git a/samples/client/petstore/objc/client/NIKCategory.h b/samples/client/petstore/objc/client/NIKCategory.h index 37628777518..e6d5eadd775 100644 --- a/samples/client/petstore/objc/client/NIKCategory.h +++ b/samples/client/petstore/objc/client/NIKCategory.h @@ -1,13 +1,7 @@ #import #import "NIKSwaggerObject.h" -@interface NIKCategory : NIKSwaggerObject { -@private - NSNumber* __id; //NSNumber - NSString* _name; //NSString - } - - +@interface NIKCategory : NIKSwaggerObject @property(nonatomic) NSNumber* _id; @property(nonatomic) NSString* name; diff --git a/samples/client/petstore/objc/client/NIKCategory.m b/samples/client/petstore/objc/client/NIKCategory.m index 78cd4ff7915..8af3b825c12 100644 --- a/samples/client/petstore/objc/client/NIKCategory.m +++ b/samples/client/petstore/objc/client/NIKCategory.m @@ -3,27 +3,30 @@ @implementation NIKCategory -@synthesize _id = __id; -@synthesize name = _name; -- (id) _id: (NSNumber*) _id - name: (NSString*) name - { - __id = _id; - _name = name; - return self; - } - -- (id) initWithValues: (NSDictionary*)dict +-(id)_id: (NSNumber*) _id + name: (NSString*) name { - __id = [dict objectForKey:@"id"]; - _name = [dict objectForKey:@"name"]; + __id = _id; + _name = name; + return self; +} + +-(id) initWithValues:(NSDictionary*)dict +{ + self = [super init]; + if(self) { + __id = dict[@"id"]; + _name = dict[@"name"]; + + + } return self; } -(NSDictionary*) asDictionary { NSMutableDictionary* dict = [[NSMutableDictionary alloc] init]; - if(__id != nil) [dict setObject:__id forKey:@"id"]; - if(_name != nil) [dict setObject:_name forKey:@"name"]; + if(__id != nil) dict[@"id"] = __id ; + if(_name != nil) dict[@"name"] = _name ; NSDictionary* output = [dict copy]; return output; } diff --git a/samples/client/petstore/objc/client/NIKOrder.h b/samples/client/petstore/objc/client/NIKOrder.h index 085dcb9c083..506f1fd9e1b 100644 --- a/samples/client/petstore/objc/client/NIKOrder.h +++ b/samples/client/petstore/objc/client/NIKOrder.h @@ -2,16 +2,7 @@ #import "NIKSwaggerObject.h" #import "NIKDate.h" -@interface NIKOrder : NIKSwaggerObject { -@private - NSNumber* __id; //NSNumber - NSNumber* _petId; //NSNumber - NSString* _status; //NSString - NSNumber* _quantity; //NSNumber - NIKDate* _shipDate; //NIKDate - } - - +@interface NIKOrder : NIKSwaggerObject @property(nonatomic) NSNumber* _id; @property(nonatomic) NSNumber* petId; diff --git a/samples/client/petstore/objc/client/NIKOrder.m b/samples/client/petstore/objc/client/NIKOrder.m index ae36e534d6b..fc2c1147271 100644 --- a/samples/client/petstore/objc/client/NIKOrder.m +++ b/samples/client/petstore/objc/client/NIKOrder.m @@ -3,59 +3,59 @@ @implementation NIKOrder -@synthesize _id = __id; -@synthesize petId = _petId; -@synthesize status = _status; -@synthesize quantity = _quantity; -@synthesize shipDate = _shipDate; -- (id) _id: (NSNumber*) _id - petId: (NSNumber*) petId - status: (NSString*) status - quantity: (NSNumber*) quantity - shipDate: (NIKDate*) shipDate - { - __id = _id; - _petId = petId; - _status = status; - _quantity = quantity; - _shipDate = shipDate; - return self; - } - -- (id) initWithValues: (NSDictionary*)dict +-(id)_id: (NSNumber*) _id + petId: (NSNumber*) petId + status: (NSString*) status + quantity: (NSNumber*) quantity + shipDate: (NIKDate*) shipDate { - __id = [dict objectForKey:@"id"]; - _petId = [dict objectForKey:@"petId"]; - _status = [dict objectForKey:@"status"]; - _quantity = [dict objectForKey:@"quantity"]; - id shipDate_dict = [dict objectForKey:@"shipDate"]; - _shipDate = [[NIKDate alloc]initWithValues:shipDate_dict]; + __id = _id; + _petId = petId; + _status = status; + _quantity = quantity; + _shipDate = shipDate; + return self; +} + +-(id) initWithValues:(NSDictionary*)dict +{ + self = [super init]; + if(self) { + __id = dict[@"id"]; + _petId = dict[@"petId"]; + _status = dict[@"status"]; + _quantity = dict[@"quantity"]; + id shipDate_dict = dict[@"shipDate"]; + _shipDate = [[NIKDate alloc]initWithValues:shipDate_dict]; + + + } return self; } -(NSDictionary*) asDictionary { NSMutableDictionary* dict = [[NSMutableDictionary alloc] init]; - if(__id != nil) [dict setObject:__id forKey:@"id"]; - if(_petId != nil) [dict setObject:_petId forKey:@"petId"]; - if(_status != nil) [dict setObject:_status forKey:@"status"]; - if(_quantity != nil) [dict setObject:_quantity forKey:@"quantity"]; + if(__id != nil) dict[@"id"] = __id ; + if(_petId != nil) dict[@"petId"] = _petId ; + if(_status != nil) dict[@"status"] = _status ; + if(_quantity != nil) dict[@"quantity"] = _quantity ; if(_shipDate != nil){ if([_shipDate isKindOfClass:[NSArray class]]){ NSMutableArray * array = [[NSMutableArray alloc] init]; - for( NIKDate * shipDate in (NSArray*)_shipDate) { + for( NIKDate *shipDate in (NSArray*)_shipDate) { [array addObject:[(NIKSwaggerObject*)shipDate asDictionary]]; } - [dict setObject:array forKey:@"shipDate"]; + dict[@"shipDate"] = array; } else if(_shipDate && [_shipDate isKindOfClass:[NIKDate class]]) { NSString * dateString = [(NIKDate*)_shipDate toString]; if(dateString){ - [dict setObject:dateString forKey:@"shipDate"]; + dict[@"shipDate"] = dateString; } } } else { - if(_shipDate != nil) [dict setObject:[(NIKSwaggerObject*)_shipDate asDictionary]forKey:@"shipDate"]; + if(_shipDate != nil) dict[@"shipDate"] = [(NIKSwaggerObject*)_shipDate asDictionary]; } NSDictionary* output = [dict copy]; return output; diff --git a/samples/client/petstore/objc/client/NIKPet.h b/samples/client/petstore/objc/client/NIKPet.h index 7491548570f..6979d11a358 100644 --- a/samples/client/petstore/objc/client/NIKPet.h +++ b/samples/client/petstore/objc/client/NIKPet.h @@ -3,17 +3,7 @@ #import "NIKCategory.h" #import "NIKTag.h" -@interface NIKPet : NIKSwaggerObject { -@private - NSArray* _tags; //Tag - NSNumber* __id; //NSNumber - NIKCategory* _category; //Category - NSString* _status; //NSString - NSString* _name; //NSString - NSArray* _photoUrls; //NSString - } - - +@interface NIKPet : NIKSwaggerObject @property(nonatomic) NSArray* tags; @property(nonatomic) NSNumber* _id; diff --git a/samples/client/petstore/objc/client/NIKPet.m b/samples/client/petstore/objc/client/NIKPet.m index 91e180e56ac..877553d0501 100644 --- a/samples/client/petstore/objc/client/NIKPet.m +++ b/samples/client/petstore/objc/client/NIKPet.m @@ -3,47 +3,55 @@ @implementation NIKPet -@synthesize tags = _tags; -@synthesize _id = __id; -@synthesize category = _category; -@synthesize status = _status; -@synthesize name = _name; -@synthesize photoUrls = _photoUrls; -- (id) tags: (NSArray*) tags - _id: (NSNumber*) _id - category: (NIKCategory*) category - status: (NSString*) status - name: (NSString*) name - photoUrls: (NSArray*) photoUrls - { - _tags = tags; - __id = _id; - _category = category; - _status = status; - _name = name; - _photoUrls = photoUrls; - return self; - } - -- (id) initWithValues: (NSDictionary*)dict +-(id)tags: (NSArray*) tags + _id: (NSNumber*) _id + category: (NIKCategory*) category + status: (NSString*) status + name: (NSString*) name + photoUrls: (NSArray*) photoUrls { - id tags_dict = [dict objectForKey:@"tags"]; - if([tags_dict isKindOfClass:[NSArray class]]) { - if([(NSArray*)tags_dict count] > 0) { + _tags = tags; + __id = _id; + _category = category; + _status = status; + _name = name; + _photoUrls = photoUrls; + return self; +} + +-(id) initWithValues:(NSDictionary*)dict +{ + self = [super init]; + if(self) { + id tags_dict = dict[@"tags"]; + if([tags_dict isKindOfClass:[NSArray class]]) { + NSMutableArray * objs = [[NSMutableArray alloc] initWithCapacity:[(NSArray*)tags_dict count]]; - for (NSDictionary* dict in (NSArray*)tags_dict) { - NIKTag* d = [[NIKTag alloc]initWithValues:dict]; - [objs addObject:d]; + + if([(NSArray*)tags_dict count] > 0) { + for (NSDictionary* dict in (NSArray*)tags_dict) { + NIKTag* d = [[NIKTag alloc] initWithValues:dict]; + [objs addObject:d]; + } + + _tags = [[NSArray alloc] initWithArray:objs]; + } + else { + _tags = [[NSArray alloc] init]; } - _tags = [[NSArray alloc] initWithArray:objs]; } + else { + _tags = [[NSArray alloc] init]; + } + __id = dict[@"id"]; + id category_dict = dict[@"category"]; + _category = [[NIKCategory alloc]initWithValues:category_dict]; + _status = dict[@"status"]; + _name = dict[@"name"]; + _photoUrls = dict[@"photoUrls"]; + + } - __id = [dict objectForKey:@"id"]; - id category_dict = [dict objectForKey:@"category"]; - _category = [[NIKCategory alloc]initWithValues:category_dict]; - _status = [dict objectForKey:@"status"]; - _name = [dict objectForKey:@"name"]; - _photoUrls = [dict objectForKey:@"photoUrls"]; return self; } @@ -52,43 +60,43 @@ if(_tags != nil){ if([_tags isKindOfClass:[NSArray class]]){ NSMutableArray * array = [[NSMutableArray alloc] init]; - for( NIKTag * tags in (NSArray*)_tags) { + for( NIKTag *tags in (NSArray*)_tags) { [array addObject:[(NIKSwaggerObject*)tags asDictionary]]; } - [dict setObject:array forKey:@"tags"]; + dict[@"tags"] = array; } else if(_tags && [_tags isKindOfClass:[NIKDate class]]) { NSString * dateString = [(NIKDate*)_tags toString]; if(dateString){ - [dict setObject:dateString forKey:@"tags"]; + dict[@"tags"] = dateString; } } } else { - if(_tags != nil) [dict setObject:[(NIKSwaggerObject*)_tags asDictionary]forKey:@"tags"]; + if(_tags != nil) dict[@"tags"] = [(NIKSwaggerObject*)_tags asDictionary]; } - if(__id != nil) [dict setObject:__id forKey:@"id"]; + if(__id != nil) dict[@"id"] = __id ; if(_category != nil){ if([_category isKindOfClass:[NSArray class]]){ NSMutableArray * array = [[NSMutableArray alloc] init]; - for( NIKCategory * category in (NSArray*)_category) { + for( NIKCategory *category in (NSArray*)_category) { [array addObject:[(NIKSwaggerObject*)category asDictionary]]; } - [dict setObject:array forKey:@"category"]; + dict[@"category"] = array; } else if(_category && [_category isKindOfClass:[NIKDate class]]) { NSString * dateString = [(NIKDate*)_category toString]; if(dateString){ - [dict setObject:dateString forKey:@"category"]; + dict[@"category"] = dateString; } } } else { - if(_category != nil) [dict setObject:[(NIKSwaggerObject*)_category asDictionary]forKey:@"category"]; + if(_category != nil) dict[@"category"] = [(NIKSwaggerObject*)_category asDictionary]; } - if(_status != nil) [dict setObject:_status forKey:@"status"]; - if(_name != nil) [dict setObject:_name forKey:@"name"]; - if(_photoUrls != nil) [dict setObject:_photoUrls forKey:@"photoUrls"]; + if(_status != nil) dict[@"status"] = _status ; + if(_name != nil) dict[@"name"] = _name ; + if(_photoUrls != nil) dict[@"photoUrls"] = _photoUrls ; NSDictionary* output = [dict copy]; return output; } diff --git a/samples/client/petstore/objc/client/NIKPetApi.h b/samples/client/petstore/objc/client/NIKPetApi.h index 181f457e134..54819e1a232 100644 --- a/samples/client/petstore/objc/client/NIKPetApi.h +++ b/samples/client/petstore/objc/client/NIKPetApi.h @@ -12,17 +12,51 @@ @property(nonatomic, readonly) NSOperationQueue* queue; @property(nonatomic, readonly) NIKApiInvoker* api; --(void) addHeader:(NSString*) value - forKey:(NSString*)key; +-(void) addHeader:(NSString*)value forKey:(NSString*)key; +/** + + Find pet by ID + Returns a pet based on ID + @param petId ID of pet that needs to be fetched + */ -(void) getPetByIdWithCompletionBlock :(NSString*) petId - completionHandler:(void (^)(NIKPet*, NSError *))completionBlock; + completionHandler: (void (^)(NIKPet* output, NSError* error))completionBlock; + +/** + + Add a new pet to the store + + @param body Pet object that needs to be added to the store + */ -(void) addPetWithCompletionBlock :(NIKPet*) body - completionHandler:(void (^)(NSError *))completionBlock; + completionHandler: (void (^)(NSError* error))completionBlock; + +/** + + Update an existing pet + + @param body Pet object that needs to be updated in the store + */ -(void) updatePetWithCompletionBlock :(NIKPet*) body - completionHandler:(void (^)(NSError *))completionBlock; + 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 + */ -(void) findPetsByStatusWithCompletionBlock :(NSString*) status - completionHandler:(void (^)(NSArray*, NSError *))completionBlock; + 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 + */ -(void) findPetsByTagsWithCompletionBlock :(NSString*) tags - completionHandler:(void (^)(NSArray*, NSError *))completionBlock; + completionHandler: (void (^)(NSArray* output, NSError* error))completionBlock; + @end diff --git a/samples/client/petstore/objc/client/NIKPetApi.m b/samples/client/petstore/objc/client/NIKPetApi.m index 7a6cea8a1c2..fe47ab3eaad 100644 --- a/samples/client/petstore/objc/client/NIKPetApi.m +++ b/samples/client/petstore/objc/client/NIKPetApi.m @@ -9,10 +9,20 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api"; @synthesize queue = _queue; @synthesize api = _api; -- (id) init { ++(NIKPetApi*) apiWithHeader:(NSString*)headerValue key:(NSString*)key { + static NIKPetApi* singletonAPI = nil; + + if (singletonAPI == nil) { + singletonAPI = [[NIKPetApi alloc] init]; + [singletonAPI addHeader:headerValue forKey:key]; + } + return singletonAPI; +} + +-(id) init { self = [super init]; _queue = [[NSOperationQueue alloc] init]; - _api = [[NIKApiInvoker alloc] init]; + _api = [NIKApiInvoker sharedInstance]; return self; } @@ -22,15 +32,8 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api"; [_api addHeader:value forKey:key]; } -/** - * - * returnTypeIsPrimitive: - * returnBaseType: NIKPet - * returnContainer: - * - **/ --(void) getPetByIdWithCompletionBlock :(NSString*) petId - completionHandler:(void (^)(NIKPet*, NSError *))completionBlock{ +-(void) getPetByIdWithCompletionBlock:(NSString*) petId + completionHandler: (void (^)(NIKPet* output, NSError* error))completionBlock{ NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/pet.{format}/{petId}", basePath]; @@ -45,29 +48,23 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api"; if(petId == nil) { // error } - [_api dictionaryWithCompletionBlock: requestUrl - method: @"GET" - queryParams: queryParams - body: bodyDictionary - headerParams: headerParams - completionHandler: ^(NSDictionary *data, NSError *error) { + [_api dictionary:requestUrl + method:@"GET" + queryParams:queryParams + body:bodyDictionary + headerParams:headerParams + completionBlock:^(NSDictionary *data, NSError *error) { if (error) { completionBlock(nil, error);return; } - + completionBlock( [[NIKPet alloc]initWithValues: data], nil);}]; + } -/** - * - * returnTypeIsPrimitive: true - * returnBaseType: - * returnContainer: - * - **/ --(void) addPetWithCompletionBlock :(NIKPet*) body - completionHandler:(void (^)(NSError *))completionBlock{ +-(void) addPetWithCompletionBlock:(NIKPet*) body + completionHandler: (void (^)(NSError* error))completionBlock{ NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/pet.{format}", basePath]; @@ -103,12 +100,12 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api"; if(body == nil) { // error } - [_api stringWithCompletionBlock: requestUrl - method: @"POST" - queryParams: queryParams - body: bodyDictionary - headerParams: headerParams - completionHandler: ^(NSString *data, NSError *error) { + [_api stringWithCompletionBlock:requestUrl + method:@"POST" + queryParams:queryParams + body:bodyDictionary + headerParams:headerParams + completionBlock:^(NSString *data, NSError *error) { if (error) { completionBlock(error); return; @@ -116,17 +113,11 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api"; completionBlock(nil); }]; + } -/** - * - * returnTypeIsPrimitive: true - * returnBaseType: - * returnContainer: - * - **/ --(void) updatePetWithCompletionBlock :(NIKPet*) body - completionHandler:(void (^)(NSError *))completionBlock{ +-(void) updatePetWithCompletionBlock:(NIKPet*) body + completionHandler: (void (^)(NSError* error))completionBlock{ NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/pet.{format}", basePath]; @@ -162,12 +153,12 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api"; if(body == nil) { // error } - [_api stringWithCompletionBlock: requestUrl - method: @"PUT" - queryParams: queryParams - body: bodyDictionary - headerParams: headerParams - completionHandler: ^(NSString *data, NSError *error) { + [_api stringWithCompletionBlock:requestUrl + method:@"PUT" + queryParams:queryParams + body:bodyDictionary + headerParams:headerParams + completionBlock:^(NSString *data, NSError *error) { if (error) { completionBlock(error); return; @@ -175,17 +166,11 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api"; completionBlock(nil); }]; + } -/** - * - * returnTypeIsPrimitive: - * returnBaseType: NIKPet - * returnContainer: List - * - **/ --(void) findPetsByStatusWithCompletionBlock :(NSString*) status - completionHandler:(void (^)(NSArray*, NSError *))completionBlock{ +-(void) findPetsByStatusWithCompletionBlock:(NSString*) status + completionHandler: (void (^)(NSArray* output, NSError* error))completionBlock{ NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/pet.{format}/findByStatus", basePath]; @@ -195,18 +180,18 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api"; NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init]; if(status != nil) - [queryParams setValue:status forKey:@"status"]; + queryParams[@"status"] = status; NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init]; id bodyDictionary = nil; if(status == nil) { // error } - [_api dictionaryWithCompletionBlock: requestUrl - method: @"GET" - queryParams: queryParams - body: bodyDictionary - headerParams: headerParams - completionHandler: ^(NSDictionary *data, NSError *error) { + [_api dictionary: requestUrl + method: @"GET" + queryParams: queryParams + body: bodyDictionary + headerParams: headerParams + completionBlock: ^(NSDictionary *data, NSError *error) { if (error) { completionBlock(nil, error);return; } @@ -221,17 +206,11 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api"; } }]; + } -/** - * - * returnTypeIsPrimitive: - * returnBaseType: NIKPet - * returnContainer: List - * - **/ --(void) findPetsByTagsWithCompletionBlock :(NSString*) tags - completionHandler:(void (^)(NSArray*, NSError *))completionBlock{ +-(void) findPetsByTagsWithCompletionBlock:(NSString*) tags + completionHandler: (void (^)(NSArray* output, NSError* error))completionBlock{ NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/pet.{format}/findByTags", basePath]; @@ -241,18 +220,18 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api"; NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init]; if(tags != nil) - [queryParams setValue:tags forKey:@"tags"]; + queryParams[@"tags"] = tags; NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init]; id bodyDictionary = nil; if(tags == nil) { // error } - [_api dictionaryWithCompletionBlock: requestUrl - method: @"GET" - queryParams: queryParams - body: bodyDictionary - headerParams: headerParams - completionHandler: ^(NSDictionary *data, NSError *error) { + [_api dictionary: requestUrl + method: @"GET" + queryParams: queryParams + body: bodyDictionary + headerParams: headerParams + completionBlock: ^(NSDictionary *data, NSError *error) { if (error) { completionBlock(nil, error);return; } @@ -267,9 +246,11 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api"; } }]; + } -(void) getPetByIdAsJsonWithCompletionBlock :(NSString*) petId + completionHandler:(void (^)(NSString*, NSError *))completionBlock{ NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/pet.{format}/{petId}", basePath]; @@ -285,12 +266,12 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api"; if(petId == nil) { // error } - [_api dictionaryWithCompletionBlock: requestUrl - method: @"GET" - queryParams: queryParams - body: bodyDictionary - headerParams: headerParams - completionHandler: ^(NSDictionary *data, NSError *error) { + [_api dictionary:requestUrl + method:@"GET" + queryParams:queryParams + body:bodyDictionary + headerParams:headerParams + completionBlock:^(NSDictionary *data, NSError *error) { if (error) { completionBlock(nil, error);return; } @@ -307,11 +288,14 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api"; NSString * json = [[NSString alloc]initWithData:responseData encoding:NSUTF8StringEncoding]; completionBlock(json, nil); + }]; + } -(void) addPetAsJsonWithCompletionBlock :(NIKPet*) body + completionHandler:(void (^)(NSError *))completionBlock{ NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/pet.{format}", basePath]; @@ -348,22 +332,25 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api"; if(body == nil) { // error } - [_api dictionaryWithCompletionBlock: requestUrl - method: @"POST" - queryParams: queryParams - body: bodyDictionary - headerParams: headerParams - completionHandler: ^(NSDictionary *data, NSError *error) { + [_api dictionary:requestUrl + method:@"POST" + queryParams:queryParams + body:bodyDictionary + headerParams:headerParams + completionBlock:^(NSDictionary *data, NSError *error) { if (error) { completionBlock(error);return; } completionBlock(nil); + }]; + } -(void) updatePetAsJsonWithCompletionBlock :(NIKPet*) body + completionHandler:(void (^)(NSError *))completionBlock{ NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/pet.{format}", basePath]; @@ -400,22 +387,25 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api"; if(body == nil) { // error } - [_api dictionaryWithCompletionBlock: requestUrl - method: @"PUT" - queryParams: queryParams - body: bodyDictionary - headerParams: headerParams - completionHandler: ^(NSDictionary *data, NSError *error) { + [_api dictionary:requestUrl + method:@"PUT" + queryParams:queryParams + body:bodyDictionary + headerParams:headerParams + completionBlock:^(NSDictionary *data, NSError *error) { if (error) { completionBlock(error);return; } completionBlock(nil); + }]; + } -(void) findPetsByStatusAsJsonWithCompletionBlock :(NSString*) status + completionHandler:(void (^)(NSString*, NSError *))completionBlock{ NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/pet.{format}/findByStatus", basePath]; @@ -426,18 +416,18 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api"; NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init]; if(status != nil) - [queryParams setValue:status forKey:@"status"]; + queryParams[@"status"] = status; NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init]; id bodyDictionary = nil; if(status == nil) { // error } - [_api dictionaryWithCompletionBlock: requestUrl - method: @"GET" - queryParams: queryParams - body: bodyDictionary - headerParams: headerParams - completionHandler: ^(NSDictionary *data, NSError *error) { + [_api dictionary:requestUrl + method:@"GET" + queryParams:queryParams + body:bodyDictionary + headerParams:headerParams + completionBlock:^(NSDictionary *data, NSError *error) { if (error) { completionBlock(nil, error);return; } @@ -454,11 +444,14 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api"; NSString * json = [[NSString alloc]initWithData:responseData encoding:NSUTF8StringEncoding]; completionBlock(json, nil); + }]; + } -(void) findPetsByTagsAsJsonWithCompletionBlock :(NSString*) tags + completionHandler:(void (^)(NSString*, NSError *))completionBlock{ NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/pet.{format}/findByTags", basePath]; @@ -469,18 +462,18 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api"; NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init]; if(tags != nil) - [queryParams setValue:tags forKey:@"tags"]; + queryParams[@"tags"] = tags; NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init]; id bodyDictionary = nil; if(tags == nil) { // error } - [_api dictionaryWithCompletionBlock: requestUrl - method: @"GET" - queryParams: queryParams - body: bodyDictionary - headerParams: headerParams - completionHandler: ^(NSDictionary *data, NSError *error) { + [_api dictionary:requestUrl + method:@"GET" + queryParams:queryParams + body:bodyDictionary + headerParams:headerParams + completionBlock:^(NSDictionary *data, NSError *error) { if (error) { completionBlock(nil, error);return; } @@ -497,8 +490,10 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api"; NSString * json = [[NSString alloc]initWithData:responseData encoding:NSUTF8StringEncoding]; completionBlock(json, nil); + }]; + } diff --git a/samples/client/petstore/objc/client/NIKStoreApi.h b/samples/client/petstore/objc/client/NIKStoreApi.h index 5454798e01e..af31ee3d074 100644 --- a/samples/client/petstore/objc/client/NIKStoreApi.h +++ b/samples/client/petstore/objc/client/NIKStoreApi.h @@ -12,13 +12,33 @@ @property(nonatomic, readonly) NSOperationQueue* queue; @property(nonatomic, readonly) NIKApiInvoker* api; --(void) addHeader:(NSString*) value - forKey:(NSString*)key; +-(void) addHeader:(NSString*)value forKey:(NSString*)key; +/** + + Find purchase order by ID + For valid response try integer IDs with value <= 5. Anything above 5 or nonintegers will generate API errors + @param orderId ID of pet that needs to be fetched + */ -(void) getOrderByIdWithCompletionBlock :(NSString*) orderId - completionHandler:(void (^)(NIKOrder*, NSError *))completionBlock; + completionHandler: (void (^)(NIKOrder* 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 + */ -(void) deleteOrderWithCompletionBlock :(NSString*) orderId - completionHandler:(void (^)(NSError *))completionBlock; + completionHandler: (void (^)(NSError* error))completionBlock; + +/** + + Place an order for a pet + + @param body order placed for purchasing the pet + */ -(void) placeOrderWithCompletionBlock :(NIKOrder*) body - completionHandler:(void (^)(NSError *))completionBlock; + completionHandler: (void (^)(NSError* error))completionBlock; + @end diff --git a/samples/client/petstore/objc/client/NIKStoreApi.m b/samples/client/petstore/objc/client/NIKStoreApi.m index 2a393727da5..629a6b7c643 100644 --- a/samples/client/petstore/objc/client/NIKStoreApi.m +++ b/samples/client/petstore/objc/client/NIKStoreApi.m @@ -9,10 +9,20 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api"; @synthesize queue = _queue; @synthesize api = _api; -- (id) init { ++(NIKStoreApi*) apiWithHeader:(NSString*)headerValue key:(NSString*)key { + static NIKStoreApi* singletonAPI = nil; + + if (singletonAPI == nil) { + singletonAPI = [[NIKStoreApi alloc] init]; + [singletonAPI addHeader:headerValue forKey:key]; + } + return singletonAPI; +} + +-(id) init { self = [super init]; _queue = [[NSOperationQueue alloc] init]; - _api = [[NIKApiInvoker alloc] init]; + _api = [NIKApiInvoker sharedInstance]; return self; } @@ -22,15 +32,8 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api"; [_api addHeader:value forKey:key]; } -/** - * - * returnTypeIsPrimitive: - * returnBaseType: NIKOrder - * returnContainer: - * - **/ --(void) getOrderByIdWithCompletionBlock :(NSString*) orderId - completionHandler:(void (^)(NIKOrder*, NSError *))completionBlock{ +-(void) getOrderByIdWithCompletionBlock:(NSString*) orderId + completionHandler: (void (^)(NIKOrder* output, NSError* error))completionBlock{ NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/store.{format}/order/{orderId}", basePath]; @@ -45,29 +48,23 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api"; if(orderId == nil) { // error } - [_api dictionaryWithCompletionBlock: requestUrl - method: @"GET" - queryParams: queryParams - body: bodyDictionary - headerParams: headerParams - completionHandler: ^(NSDictionary *data, NSError *error) { + [_api dictionary:requestUrl + method:@"GET" + queryParams:queryParams + body:bodyDictionary + headerParams:headerParams + completionBlock:^(NSDictionary *data, NSError *error) { if (error) { completionBlock(nil, error);return; } - + completionBlock( [[NIKOrder alloc]initWithValues: data], nil);}]; + } -/** - * - * returnTypeIsPrimitive: true - * returnBaseType: - * returnContainer: - * - **/ --(void) deleteOrderWithCompletionBlock :(NSString*) orderId - completionHandler:(void (^)(NSError *))completionBlock{ +-(void) deleteOrderWithCompletionBlock:(NSString*) orderId + completionHandler: (void (^)(NSError* error))completionBlock{ NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/store.{format}/order/{orderId}", basePath]; @@ -82,12 +79,12 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api"; if(orderId == nil) { // error } - [_api stringWithCompletionBlock: requestUrl - method: @"DELETE" - queryParams: queryParams - body: bodyDictionary - headerParams: headerParams - completionHandler: ^(NSString *data, NSError *error) { + [_api stringWithCompletionBlock:requestUrl + method:@"DELETE" + queryParams:queryParams + body:bodyDictionary + headerParams:headerParams + completionBlock:^(NSString *data, NSError *error) { if (error) { completionBlock(error); return; @@ -95,17 +92,11 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api"; completionBlock(nil); }]; + } -/** - * - * returnTypeIsPrimitive: true - * returnBaseType: - * returnContainer: - * - **/ --(void) placeOrderWithCompletionBlock :(NIKOrder*) body - completionHandler:(void (^)(NSError *))completionBlock{ +-(void) placeOrderWithCompletionBlock:(NIKOrder*) body + completionHandler: (void (^)(NSError* error))completionBlock{ NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/store.{format}/order", basePath]; @@ -141,12 +132,12 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api"; if(body == nil) { // error } - [_api stringWithCompletionBlock: requestUrl - method: @"POST" - queryParams: queryParams - body: bodyDictionary - headerParams: headerParams - completionHandler: ^(NSString *data, NSError *error) { + [_api stringWithCompletionBlock:requestUrl + method:@"POST" + queryParams:queryParams + body:bodyDictionary + headerParams:headerParams + completionBlock:^(NSString *data, NSError *error) { if (error) { completionBlock(error); return; @@ -154,9 +145,11 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api"; completionBlock(nil); }]; + } -(void) getOrderByIdAsJsonWithCompletionBlock :(NSString*) orderId + completionHandler:(void (^)(NSString*, NSError *))completionBlock{ NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/store.{format}/order/{orderId}", basePath]; @@ -172,12 +165,12 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api"; if(orderId == nil) { // error } - [_api dictionaryWithCompletionBlock: requestUrl - method: @"GET" - queryParams: queryParams - body: bodyDictionary - headerParams: headerParams - completionHandler: ^(NSDictionary *data, NSError *error) { + [_api dictionary:requestUrl + method:@"GET" + queryParams:queryParams + body:bodyDictionary + headerParams:headerParams + completionBlock:^(NSDictionary *data, NSError *error) { if (error) { completionBlock(nil, error);return; } @@ -194,11 +187,14 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api"; NSString * json = [[NSString alloc]initWithData:responseData encoding:NSUTF8StringEncoding]; completionBlock(json, nil); + }]; + } -(void) deleteOrderAsJsonWithCompletionBlock :(NSString*) orderId + completionHandler:(void (^)(NSError *))completionBlock{ NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/store.{format}/order/{orderId}", basePath]; @@ -214,22 +210,25 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api"; if(orderId == nil) { // error } - [_api dictionaryWithCompletionBlock: requestUrl - method: @"DELETE" - queryParams: queryParams - body: bodyDictionary - headerParams: headerParams - completionHandler: ^(NSDictionary *data, NSError *error) { + [_api dictionary:requestUrl + method:@"DELETE" + queryParams:queryParams + body:bodyDictionary + headerParams:headerParams + completionBlock:^(NSDictionary *data, NSError *error) { if (error) { completionBlock(error);return; } completionBlock(nil); + }]; + } -(void) placeOrderAsJsonWithCompletionBlock :(NIKOrder*) body + completionHandler:(void (^)(NSError *))completionBlock{ NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/store.{format}/order", basePath]; @@ -266,19 +265,21 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api"; if(body == nil) { // error } - [_api dictionaryWithCompletionBlock: requestUrl - method: @"POST" - queryParams: queryParams - body: bodyDictionary - headerParams: headerParams - completionHandler: ^(NSDictionary *data, NSError *error) { + [_api dictionary:requestUrl + method:@"POST" + queryParams:queryParams + body:bodyDictionary + headerParams:headerParams + completionBlock:^(NSDictionary *data, NSError *error) { if (error) { completionBlock(error);return; } completionBlock(nil); + }]; + } diff --git a/samples/client/petstore/objc/client/NIKTag.h b/samples/client/petstore/objc/client/NIKTag.h index 86a4100da57..9e2982b2bb5 100644 --- a/samples/client/petstore/objc/client/NIKTag.h +++ b/samples/client/petstore/objc/client/NIKTag.h @@ -1,13 +1,7 @@ #import #import "NIKSwaggerObject.h" -@interface NIKTag : NIKSwaggerObject { -@private - NSNumber* __id; //NSNumber - NSString* _name; //NSString - } - - +@interface NIKTag : NIKSwaggerObject @property(nonatomic) NSNumber* _id; @property(nonatomic) NSString* name; diff --git a/samples/client/petstore/objc/client/NIKTag.m b/samples/client/petstore/objc/client/NIKTag.m index 450e16d109e..bf92cb6c513 100644 --- a/samples/client/petstore/objc/client/NIKTag.m +++ b/samples/client/petstore/objc/client/NIKTag.m @@ -3,27 +3,30 @@ @implementation NIKTag -@synthesize _id = __id; -@synthesize name = _name; -- (id) _id: (NSNumber*) _id - name: (NSString*) name - { - __id = _id; - _name = name; - return self; - } - -- (id) initWithValues: (NSDictionary*)dict +-(id)_id: (NSNumber*) _id + name: (NSString*) name { - __id = [dict objectForKey:@"id"]; - _name = [dict objectForKey:@"name"]; + __id = _id; + _name = name; + return self; +} + +-(id) initWithValues:(NSDictionary*)dict +{ + self = [super init]; + if(self) { + __id = dict[@"id"]; + _name = dict[@"name"]; + + + } return self; } -(NSDictionary*) asDictionary { NSMutableDictionary* dict = [[NSMutableDictionary alloc] init]; - if(__id != nil) [dict setObject:__id forKey:@"id"]; - if(_name != nil) [dict setObject:_name forKey:@"name"]; + if(__id != nil) dict[@"id"] = __id ; + if(_name != nil) dict[@"name"] = _name ; NSDictionary* output = [dict copy]; return output; } diff --git a/samples/client/petstore/objc/client/NIKUser.h b/samples/client/petstore/objc/client/NIKUser.h index 9074f8b2f51..aa8a435d4b2 100644 --- a/samples/client/petstore/objc/client/NIKUser.h +++ b/samples/client/petstore/objc/client/NIKUser.h @@ -1,19 +1,7 @@ #import #import "NIKSwaggerObject.h" -@interface NIKUser : NIKSwaggerObject { -@private - NSNumber* __id; //NSNumber - NSString* _lastName; //NSString - NSString* _phone; //NSString - NSString* _username; //NSString - NSString* _email; //NSString - NSNumber* _userStatus; //NSNumber - NSString* _firstName; //NSString - NSString* _password; //NSString - } - - +@interface NIKUser : NIKSwaggerObject @property(nonatomic) NSNumber* _id; @property(nonatomic) NSString* lastName; diff --git a/samples/client/petstore/objc/client/NIKUser.m b/samples/client/petstore/objc/client/NIKUser.m index 2302365399e..f31b3749a68 100644 --- a/samples/client/petstore/objc/client/NIKUser.m +++ b/samples/client/petstore/objc/client/NIKUser.m @@ -3,57 +3,54 @@ @implementation NIKUser -@synthesize _id = __id; -@synthesize lastName = _lastName; -@synthesize phone = _phone; -@synthesize username = _username; -@synthesize email = _email; -@synthesize userStatus = _userStatus; -@synthesize firstName = _firstName; -@synthesize password = _password; -- (id) _id: (NSNumber*) _id - lastName: (NSString*) lastName - phone: (NSString*) phone - username: (NSString*) username - email: (NSString*) email - userStatus: (NSNumber*) userStatus - firstName: (NSString*) firstName - password: (NSString*) password - { - __id = _id; - _lastName = lastName; - _phone = phone; - _username = username; - _email = email; - _userStatus = userStatus; - _firstName = firstName; - _password = password; - return self; - } - -- (id) initWithValues: (NSDictionary*)dict +-(id)_id: (NSNumber*) _id + lastName: (NSString*) lastName + phone: (NSString*) phone + username: (NSString*) username + email: (NSString*) email + userStatus: (NSNumber*) userStatus + firstName: (NSString*) firstName + password: (NSString*) password { - __id = [dict objectForKey:@"id"]; - _lastName = [dict objectForKey:@"lastName"]; - _phone = [dict objectForKey:@"phone"]; - _username = [dict objectForKey:@"username"]; - _email = [dict objectForKey:@"email"]; - _userStatus = [dict objectForKey:@"userStatus"]; - _firstName = [dict objectForKey:@"firstName"]; - _password = [dict objectForKey:@"password"]; + __id = _id; + _lastName = lastName; + _phone = phone; + _username = username; + _email = email; + _userStatus = userStatus; + _firstName = firstName; + _password = password; + return self; +} + +-(id) initWithValues:(NSDictionary*)dict +{ + self = [super init]; + if(self) { + __id = dict[@"id"]; + _lastName = dict[@"lastName"]; + _phone = dict[@"phone"]; + _username = dict[@"username"]; + _email = dict[@"email"]; + _userStatus = dict[@"userStatus"]; + _firstName = dict[@"firstName"]; + _password = dict[@"password"]; + + + } return self; } -(NSDictionary*) asDictionary { NSMutableDictionary* dict = [[NSMutableDictionary alloc] init]; - if(__id != nil) [dict setObject:__id forKey:@"id"]; - if(_lastName != nil) [dict setObject:_lastName forKey:@"lastName"]; - if(_phone != nil) [dict setObject:_phone forKey:@"phone"]; - if(_username != nil) [dict setObject:_username forKey:@"username"]; - if(_email != nil) [dict setObject:_email forKey:@"email"]; - if(_userStatus != nil) [dict setObject:_userStatus forKey:@"userStatus"]; - if(_firstName != nil) [dict setObject:_firstName forKey:@"firstName"]; - if(_password != nil) [dict setObject:_password forKey:@"password"]; + if(__id != nil) dict[@"id"] = __id ; + if(_lastName != nil) dict[@"lastName"] = _lastName ; + if(_phone != nil) dict[@"phone"] = _phone ; + if(_username != nil) dict[@"username"] = _username ; + if(_email != nil) dict[@"email"] = _email ; + if(_userStatus != nil) dict[@"userStatus"] = _userStatus ; + if(_firstName != nil) dict[@"firstName"] = _firstName ; + if(_password != nil) dict[@"password"] = _password ; NSDictionary* output = [dict copy]; return output; } diff --git a/samples/client/petstore/objc/client/NIKUserApi.h b/samples/client/petstore/objc/client/NIKUserApi.h index 09c9f9d68d9..5a9b3ae751d 100644 --- a/samples/client/petstore/objc/client/NIKUserApi.h +++ b/samples/client/petstore/objc/client/NIKUserApi.h @@ -12,23 +12,80 @@ @property(nonatomic, readonly) NSOperationQueue* queue; @property(nonatomic, readonly) NIKApiInvoker* api; --(void) addHeader:(NSString*) value - forKey:(NSString*)key; +-(void) addHeader:(NSString*)value forKey:(NSString*)key; +/** + + Creates list of users with given input array + + @param body List of user object + */ -(void) createUsersWithArrayInputWithCompletionBlock :(NSArray*) body - completionHandler:(void (^)(NSError *))completionBlock; + completionHandler: (void (^)(NSError* error))completionBlock; + +/** + + Create user + This can only be done by the logged in user. + @param body Created user object + */ -(void) createUserWithCompletionBlock :(NIKUser*) body - completionHandler:(void (^)(NSError *))completionBlock; + completionHandler: (void (^)(NSError* error))completionBlock; + +/** + + Creates list of users with given list input + + @param body List of user object + */ -(void) createUsersWithListInputWithCompletionBlock :(NSArray*) body - completionHandler:(void (^)(NSError *))completionBlock; --(void) updateUserWithCompletionBlock :(NSString*) username body:(NIKUser*) body - completionHandler:(void (^)(NSError *))completionBlock; + completionHandler: (void (^)(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 + */ +-(void) updateUserWithCompletionBlock :(NSString*) username + body:(NIKUser*) body + 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 + */ -(void) deleteUserWithCompletionBlock :(NSString*) username - completionHandler:(void (^)(NSError *))completionBlock; + completionHandler: (void (^)(NSError* error))completionBlock; + +/** + + Get user by user name + + @param username The name that needs to be fetched. Use user1 for testing. + */ -(void) getUserByNameWithCompletionBlock :(NSString*) username - completionHandler:(void (^)(NIKUser*, NSError *))completionBlock; --(void) loginUserWithCompletionBlock :(NSString*) username password:(NSString*) password - completionHandler:(void (^)(NSString*, NSError *))completionBlock; --(void) logoutUserWithCompletionBlock : - completionHandler:(void (^)(NSError *))completionBlock; + completionHandler: (void (^)(NIKUser* output, NSError* error))completionBlock; + +/** + + Logs user into the system + + @param username The user name for login + @param password The password for login in clear text + */ +-(void) loginUserWithCompletionBlock :(NSString*) username + password:(NSString*) password + completionHandler: (void (^)(NSString* output, NSError* error))completionBlock; + +/** + + Logs out current logged in user session + + */ +-(void) logoutUserWithCompletionBlock :(void (^)(NSError* error))completionBlock; + @end diff --git a/samples/client/petstore/objc/client/NIKUserApi.m b/samples/client/petstore/objc/client/NIKUserApi.m index 3fb0ee33b6c..9817198ef96 100644 --- a/samples/client/petstore/objc/client/NIKUserApi.m +++ b/samples/client/petstore/objc/client/NIKUserApi.m @@ -9,10 +9,20 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api"; @synthesize queue = _queue; @synthesize api = _api; -- (id) init { ++(NIKUserApi*) apiWithHeader:(NSString*)headerValue key:(NSString*)key { + static NIKUserApi* singletonAPI = nil; + + if (singletonAPI == nil) { + singletonAPI = [[NIKUserApi alloc] init]; + [singletonAPI addHeader:headerValue forKey:key]; + } + return singletonAPI; +} + +-(id) init { self = [super init]; _queue = [[NSOperationQueue alloc] init]; - _api = [[NIKApiInvoker alloc] init]; + _api = [NIKApiInvoker sharedInstance]; return self; } @@ -22,15 +32,8 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api"; [_api addHeader:value forKey:key]; } -/** - * - * returnTypeIsPrimitive: true - * returnBaseType: - * returnContainer: - * - **/ --(void) createUsersWithArrayInputWithCompletionBlock :(NSArray*) body - completionHandler:(void (^)(NSError *))completionBlock{ +-(void) createUsersWithArrayInputWithCompletionBlock:(NSArray*) body + completionHandler: (void (^)(NSError* error))completionBlock{ NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/user.{format}/createWithArray", basePath]; @@ -66,12 +69,12 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api"; if(body == nil) { // error } - [_api stringWithCompletionBlock: requestUrl - method: @"POST" - queryParams: queryParams - body: bodyDictionary - headerParams: headerParams - completionHandler: ^(NSString *data, NSError *error) { + [_api stringWithCompletionBlock:requestUrl + method:@"POST" + queryParams:queryParams + body:bodyDictionary + headerParams:headerParams + completionBlock:^(NSString *data, NSError *error) { if (error) { completionBlock(error); return; @@ -79,17 +82,11 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api"; completionBlock(nil); }]; + } -/** - * - * returnTypeIsPrimitive: true - * returnBaseType: - * returnContainer: - * - **/ --(void) createUserWithCompletionBlock :(NIKUser*) body - completionHandler:(void (^)(NSError *))completionBlock{ +-(void) createUserWithCompletionBlock:(NIKUser*) body + completionHandler: (void (^)(NSError* error))completionBlock{ NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/user.{format}", basePath]; @@ -125,12 +122,12 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api"; if(body == nil) { // error } - [_api stringWithCompletionBlock: requestUrl - method: @"POST" - queryParams: queryParams - body: bodyDictionary - headerParams: headerParams - completionHandler: ^(NSString *data, NSError *error) { + [_api stringWithCompletionBlock:requestUrl + method:@"POST" + queryParams:queryParams + body:bodyDictionary + headerParams:headerParams + completionBlock:^(NSString *data, NSError *error) { if (error) { completionBlock(error); return; @@ -138,17 +135,11 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api"; completionBlock(nil); }]; + } -/** - * - * returnTypeIsPrimitive: true - * returnBaseType: - * returnContainer: - * - **/ --(void) createUsersWithListInputWithCompletionBlock :(NSArray*) body - completionHandler:(void (^)(NSError *))completionBlock{ +-(void) createUsersWithListInputWithCompletionBlock:(NSArray*) body + completionHandler: (void (^)(NSError* error))completionBlock{ NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/user.{format}/createWithList", basePath]; @@ -184,12 +175,12 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api"; if(body == nil) { // error } - [_api stringWithCompletionBlock: requestUrl - method: @"POST" - queryParams: queryParams - body: bodyDictionary - headerParams: headerParams - completionHandler: ^(NSString *data, NSError *error) { + [_api stringWithCompletionBlock:requestUrl + method:@"POST" + queryParams:queryParams + body:bodyDictionary + headerParams:headerParams + completionBlock:^(NSString *data, NSError *error) { if (error) { completionBlock(error); return; @@ -197,17 +188,12 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api"; completionBlock(nil); }]; + } -/** - * - * returnTypeIsPrimitive: true - * returnBaseType: - * returnContainer: - * - **/ --(void) updateUserWithCompletionBlock :(NSString*) username body:(NIKUser*) body - completionHandler:(void (^)(NSError *))completionBlock{ +-(void) updateUserWithCompletionBlock:(NSString*) username + body:(NIKUser*) body + completionHandler: (void (^)(NSError* error))completionBlock{ NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/user.{format}/{username}", basePath]; @@ -247,12 +233,12 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api"; if(body == nil) { // error } - [_api stringWithCompletionBlock: requestUrl - method: @"PUT" - queryParams: queryParams - body: bodyDictionary - headerParams: headerParams - completionHandler: ^(NSString *data, NSError *error) { + [_api stringWithCompletionBlock:requestUrl + method:@"PUT" + queryParams:queryParams + body:bodyDictionary + headerParams:headerParams + completionBlock:^(NSString *data, NSError *error) { if (error) { completionBlock(error); return; @@ -260,17 +246,11 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api"; completionBlock(nil); }]; + } -/** - * - * returnTypeIsPrimitive: true - * returnBaseType: - * returnContainer: - * - **/ --(void) deleteUserWithCompletionBlock :(NSString*) username - completionHandler:(void (^)(NSError *))completionBlock{ +-(void) deleteUserWithCompletionBlock:(NSString*) username + completionHandler: (void (^)(NSError* error))completionBlock{ NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/user.{format}/{username}", basePath]; @@ -285,12 +265,12 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api"; if(username == nil) { // error } - [_api stringWithCompletionBlock: requestUrl - method: @"DELETE" - queryParams: queryParams - body: bodyDictionary - headerParams: headerParams - completionHandler: ^(NSString *data, NSError *error) { + [_api stringWithCompletionBlock:requestUrl + method:@"DELETE" + queryParams:queryParams + body:bodyDictionary + headerParams:headerParams + completionBlock:^(NSString *data, NSError *error) { if (error) { completionBlock(error); return; @@ -298,17 +278,11 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api"; completionBlock(nil); }]; + } -/** - * - * returnTypeIsPrimitive: - * returnBaseType: NIKUser - * returnContainer: - * - **/ --(void) getUserByNameWithCompletionBlock :(NSString*) username - completionHandler:(void (^)(NIKUser*, NSError *))completionBlock{ +-(void) getUserByNameWithCompletionBlock:(NSString*) username + completionHandler: (void (^)(NIKUser* output, NSError* error))completionBlock{ NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/user.{format}/{username}", basePath]; @@ -323,29 +297,24 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api"; if(username == nil) { // error } - [_api dictionaryWithCompletionBlock: requestUrl - method: @"GET" - queryParams: queryParams - body: bodyDictionary - headerParams: headerParams - completionHandler: ^(NSDictionary *data, NSError *error) { + [_api dictionary:requestUrl + method:@"GET" + queryParams:queryParams + body:bodyDictionary + headerParams:headerParams + completionBlock:^(NSDictionary *data, NSError *error) { if (error) { completionBlock(nil, error);return; } - + completionBlock( [[NIKUser alloc]initWithValues: data], nil);}]; + } -/** - * - * returnTypeIsPrimitive: true - * returnBaseType: NSString - * returnContainer: - * - **/ --(void) loginUserWithCompletionBlock :(NSString*) username password:(NSString*) password - completionHandler:(void (^)(NSString*, NSError *))completionBlock{ +-(void) loginUserWithCompletionBlock:(NSString*) username + password:(NSString*) password + completionHandler: (void (^)(NSString* output, NSError* error))completionBlock{ NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/user.{format}/login", basePath]; @@ -355,9 +324,9 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api"; NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init]; if(username != nil) - [queryParams setValue:username forKey:@"username"]; + queryParams[@"username"] = username; if(password != nil) - [queryParams setValue:password forKey:@"password"]; + queryParams[@"password"] = password; NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init]; id bodyDictionary = nil; if(username == nil) { @@ -366,12 +335,12 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api"; if(password == nil) { // error } - [_api stringWithCompletionBlock: requestUrl - method: @"GET" - queryParams: queryParams - body: bodyDictionary - headerParams: headerParams - completionHandler: ^(NSString *data, NSError *error) { + [_api stringWithCompletionBlock:requestUrl + method:@"GET" + queryParams:queryParams + body:bodyDictionary + headerParams:headerParams + completionBlock:^(NSString *data, NSError *error) { if (error) { completionBlock(nil, error); return; @@ -379,29 +348,11 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api"; completionBlock( [[NSString alloc]initWithString: data], nil); }]; - [_api dictionaryWithCompletionBlock: requestUrl - method: @"GET" - queryParams: queryParams - body: bodyDictionary - headerParams: headerParams - completionHandler: ^(NSDictionary *data, NSError *error) { - if (error) { - completionBlock(nil, error);return; - } - - completionBlock( [[NSString alloc]initWithString: data], nil);}]; + } -/** - * - * returnTypeIsPrimitive: true - * returnBaseType: - * returnContainer: - * - **/ --(void) logoutUserWithCompletionBlock : - completionHandler:(void (^)(NSError *))completionBlock{ +-(void) logoutUserWithCompletionBlock: (void (^)(NSError* error))completionBlock{ NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/user.{format}/logout", basePath]; @@ -412,12 +363,12 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api"; NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init]; NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init]; id bodyDictionary = nil; - [_api stringWithCompletionBlock: requestUrl - method: @"GET" - queryParams: queryParams - body: bodyDictionary - headerParams: headerParams - completionHandler: ^(NSString *data, NSError *error) { + [_api stringWithCompletionBlock:requestUrl + method:@"GET" + queryParams:queryParams + body:bodyDictionary + headerParams:headerParams + completionBlock:^(NSString *data, NSError *error) { if (error) { completionBlock(error); return; @@ -425,9 +376,11 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api"; completionBlock(nil); }]; + } -(void) createUsersWithArrayInputAsJsonWithCompletionBlock :(NSArray*) body + completionHandler:(void (^)(NSError *))completionBlock{ NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/user.{format}/createWithArray", basePath]; @@ -464,22 +417,25 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api"; if(body == nil) { // error } - [_api dictionaryWithCompletionBlock: requestUrl - method: @"POST" - queryParams: queryParams - body: bodyDictionary - headerParams: headerParams - completionHandler: ^(NSDictionary *data, NSError *error) { + [_api dictionary:requestUrl + method:@"POST" + queryParams:queryParams + body:bodyDictionary + headerParams:headerParams + completionBlock:^(NSDictionary *data, NSError *error) { if (error) { completionBlock(error);return; } completionBlock(nil); + }]; + } -(void) createUserAsJsonWithCompletionBlock :(NIKUser*) body + completionHandler:(void (^)(NSError *))completionBlock{ NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/user.{format}", basePath]; @@ -516,22 +472,25 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api"; if(body == nil) { // error } - [_api dictionaryWithCompletionBlock: requestUrl - method: @"POST" - queryParams: queryParams - body: bodyDictionary - headerParams: headerParams - completionHandler: ^(NSDictionary *data, NSError *error) { + [_api dictionary:requestUrl + method:@"POST" + queryParams:queryParams + body:bodyDictionary + headerParams:headerParams + completionBlock:^(NSDictionary *data, NSError *error) { if (error) { completionBlock(error);return; } completionBlock(nil); + }]; + } -(void) createUsersWithListInputAsJsonWithCompletionBlock :(NSArray*) body + completionHandler:(void (^)(NSError *))completionBlock{ NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/user.{format}/createWithList", basePath]; @@ -568,22 +527,26 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api"; if(body == nil) { // error } - [_api dictionaryWithCompletionBlock: requestUrl - method: @"POST" - queryParams: queryParams - body: bodyDictionary - headerParams: headerParams - completionHandler: ^(NSDictionary *data, NSError *error) { + [_api dictionary:requestUrl + method:@"POST" + queryParams:queryParams + body:bodyDictionary + headerParams:headerParams + completionBlock:^(NSDictionary *data, NSError *error) { if (error) { completionBlock(error);return; } completionBlock(nil); + }]; + } --(void) updateUserAsJsonWithCompletionBlock :(NSString*) username body:(NIKUser*) body +-(void) updateUserAsJsonWithCompletionBlock :(NSString*) username +body:(NIKUser*) body + completionHandler:(void (^)(NSError *))completionBlock{ NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/user.{format}/{username}", basePath]; @@ -624,22 +587,25 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api"; if(body == nil) { // error } - [_api dictionaryWithCompletionBlock: requestUrl - method: @"PUT" - queryParams: queryParams - body: bodyDictionary - headerParams: headerParams - completionHandler: ^(NSDictionary *data, NSError *error) { + [_api dictionary:requestUrl + method:@"PUT" + queryParams:queryParams + body:bodyDictionary + headerParams:headerParams + completionBlock:^(NSDictionary *data, NSError *error) { if (error) { completionBlock(error);return; } completionBlock(nil); + }]; + } -(void) deleteUserAsJsonWithCompletionBlock :(NSString*) username + completionHandler:(void (^)(NSError *))completionBlock{ NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/user.{format}/{username}", basePath]; @@ -655,22 +621,25 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api"; if(username == nil) { // error } - [_api dictionaryWithCompletionBlock: requestUrl - method: @"DELETE" - queryParams: queryParams - body: bodyDictionary - headerParams: headerParams - completionHandler: ^(NSDictionary *data, NSError *error) { + [_api dictionary:requestUrl + method:@"DELETE" + queryParams:queryParams + body:bodyDictionary + headerParams:headerParams + completionBlock:^(NSDictionary *data, NSError *error) { if (error) { completionBlock(error);return; } completionBlock(nil); + }]; + } -(void) getUserByNameAsJsonWithCompletionBlock :(NSString*) username + completionHandler:(void (^)(NSString*, NSError *))completionBlock{ NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/user.{format}/{username}", basePath]; @@ -686,12 +655,12 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api"; if(username == nil) { // error } - [_api dictionaryWithCompletionBlock: requestUrl - method: @"GET" - queryParams: queryParams - body: bodyDictionary - headerParams: headerParams - completionHandler: ^(NSDictionary *data, NSError *error) { + [_api dictionary:requestUrl + method:@"GET" + queryParams:queryParams + body:bodyDictionary + headerParams:headerParams + completionBlock:^(NSDictionary *data, NSError *error) { if (error) { completionBlock(nil, error);return; } @@ -708,11 +677,15 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api"; NSString * json = [[NSString alloc]initWithData:responseData encoding:NSUTF8StringEncoding]; completionBlock(json, nil); + }]; + } --(void) loginUserAsJsonWithCompletionBlock :(NSString*) username password:(NSString*) password +-(void) loginUserAsJsonWithCompletionBlock :(NSString*) username +password:(NSString*) password + completionHandler:(void (^)(NSString*, NSError *))completionBlock{ NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/user.{format}/login", basePath]; @@ -723,9 +696,9 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api"; NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init]; if(username != nil) - [queryParams setValue:username forKey:@"username"]; + queryParams[@"username"] = username; if(password != nil) - [queryParams setValue:password forKey:@"password"]; + queryParams[@"password"] = password; NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init]; id bodyDictionary = nil; if(username == nil) { @@ -734,12 +707,12 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api"; if(password == nil) { // error } - [_api dictionaryWithCompletionBlock: requestUrl - method: @"GET" - queryParams: queryParams - body: bodyDictionary - headerParams: headerParams - completionHandler: ^(NSDictionary *data, NSError *error) { + [_api dictionary:requestUrl + method:@"GET" + queryParams:queryParams + body:bodyDictionary + headerParams:headerParams + completionBlock:^(NSDictionary *data, NSError *error) { if (error) { completionBlock(nil, error);return; } @@ -756,11 +729,14 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api"; NSString * json = [[NSString alloc]initWithData:responseData encoding:NSUTF8StringEncoding]; completionBlock(json, nil); + }]; + } -(void) logoutUserAsJsonWithCompletionBlock : + completionHandler:(void (^)(NSError *))completionBlock{ NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/user.{format}/logout", basePath]; @@ -772,19 +748,21 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api"; NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init]; NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init]; id bodyDictionary = nil; - [_api dictionaryWithCompletionBlock: requestUrl - method: @"GET" - queryParams: queryParams - body: bodyDictionary - headerParams: headerParams - completionHandler: ^(NSDictionary *data, NSError *error) { + [_api dictionary:requestUrl + method:@"GET" + queryParams:queryParams + body:bodyDictionary + headerParams:headerParams + completionBlock:^(NSDictionary *data, NSError *error) { if (error) { completionBlock(error);return; } completionBlock(nil); + }]; + } diff --git a/samples/client/petstore/objc/tests/PetApiTest.m b/samples/client/petstore/objc/tests/PetApiTest.m index 7ced16415ca..14467e2aa73 100644 --- a/samples/client/petstore/objc/tests/PetApiTest.m +++ b/samples/client/petstore/objc/tests/PetApiTest.m @@ -314,7 +314,7 @@ if([[tag name] isEqualToString:@"tag1"] || [[tag name] isEqualToString:@"tag2"]) hasTag = true; } - STAssertEquals(hasTag, true, @"didn't find tag in pet"); + if(!hasTag) STFail(@"failed to find tag in pet"); } done = true; }