From 031dd20072030c8debe98f671f49b5fa0f9c1d56 Mon Sep 17 00:00:00 2001 From: Tony Tam Date: Wed, 26 Sep 2012 22:15:52 -0700 Subject: [PATCH] removed raw --- src/main/resources/objc/api-body.mustache | 87 ++++++++++++++++--- src/main/resources/objc/model-body.mustache | 10 +-- src/main/resources/objc/model-header.mustache | 3 - 3 files changed, 74 insertions(+), 26 deletions(-) diff --git a/src/main/resources/objc/api-body.mustache b/src/main/resources/objc/api-body.mustache index 7cba977b859..8ae91fc4ebe 100644 --- a/src/main/resources/objc/api-body.mustache +++ b/src/main/resources/objc/api-body.mustache @@ -25,6 +25,13 @@ static NSString * basePath = @"{{basePath}}"; } {{#operation}} +/** + * + * returnTypeIsPrimitive: {{returnTypeIsPrimitive}} + * returnBaseType: {{returnBaseType}} + * returnContainer: {{returnContainer}} + * + **/ -(void) {{nickname}}WithCompletionBlock {{^allParams}}:{{/allParams}}{{#allParams}}{{#secondaryParam}} {{paramName}}{{/secondaryParam}}:({{{dataType}}}) {{paramName}} {{#hasMore}}{{newline}}{{/hasMore}}{{/allParams}}{{newline}} {{#returnBaseType}}completionHandler:(void (^)({{returnType}}, NSError *))completionBlock{{/returnBaseType}} {{^returnBaseType}}completionHandler:(void (^)(NSError *))completionBlock{{/returnBaseType}} { @@ -81,22 +88,13 @@ static NSString * basePath = @"{{basePath}}"; {{/requiredParams}} {{/requiredParamCount}} - {{#returnTypeIsPrimitive}} - [_api stringWithCompletionBlock: requestUrl - method: @"{{httpMethod}}" - queryParams: queryParams - body: bodyDictionary - headerParams: headerParams - completionHandler: ^(NSString *data, NSError *error) { - {{/returnTypeIsPrimitive}} - {{^returnTypeIsPrimitive}} + {{#returnContainer}} [_api dictionaryWithCompletionBlock: requestUrl method: @"{{httpMethod}}" queryParams: queryParams body: bodyDictionary headerParams: headerParams completionHandler: ^(NSDictionary *data, NSError *error) { - {{/returnTypeIsPrimitive}} if (error) { {{#returnBaseType}}completionBlock(nil, error);{{/returnBaseType}} {{^returnBaseType}}completionBlock(error);{{/returnBaseType}} @@ -104,16 +102,19 @@ static NSString * basePath = @"{{basePath}}"; } {{#returnBaseType}} - {{#returnContainer}} if([data isKindOfClass:[NSArray class]]){ NSMutableArray * objs = [[NSMutableArray alloc] initWithCapacity:[data count]]; for (NSDictionary* dict in (NSArray*)data) { + {{#returnTypeIsPrimitive}} + {{returnBaseType}}* d = [[{{returnBaseType}} alloc]initWithString: data]; + {{/returnTypeIsPrimitive}} + {{^returnTypeIsPrimitive}} {{{returnBaseType}}}* d = [[{{{returnBaseType}}} alloc]initWithValues: dict]; + {{/returnTypeIsPrimitive}} [objs addObject:d]; } completionBlock(objs, nil); } - {{/returnContainer}} {{#returnSimpleType}} {{#returnTypeIsPrimitive}}{{#returnBaseType}}completionBlock( [[{{returnBaseType}} alloc]initWithString: data], nil);{{/returnBaseType}} {{/returnTypeIsPrimitive}} @@ -123,9 +124,67 @@ static NSString * basePath = @"{{basePath}}"; {{/returnTypeIsPrimitive}} {{/returnSimpleType}} {{/returnBaseType}} - - {{^returnBaseType}}completionBlock(nil);{{/returnBaseType}}{{newline}} }]; + {{/returnContainer}} + + {{#returnSimpleType}} + {{#returnTypeIsPrimitive}} + {{#returnBaseType}} + [_api stringWithCompletionBlock: requestUrl + method: @"{{httpMethod}}" + queryParams: queryParams + body: bodyDictionary + headerParams: headerParams + completionHandler: ^(NSString *data, NSError *error) { + if (error) { + completionBlock(nil, error); + return; + } + + completionBlock( [[{{returnBaseType}} alloc]initWithString: data], nil); + }]; + {{/returnBaseType}} + {{^returnBaseType}} + [_api stringWithCompletionBlock: requestUrl + method: @"{{httpMethod}}" + queryParams: queryParams + body: bodyDictionary + headerParams: headerParams + completionHandler: ^(NSString *data, NSError *error) { + if (error) { + completionBlock(error); + return; + } + completionBlock(nil); + }]; + {{/returnBaseType}} + {{/returnTypeIsPrimitive}} + {{#returnBaseType}} + [_api dictionaryWithCompletionBlock: requestUrl + method: @"{{httpMethod}}" + queryParams: queryParams + body: bodyDictionary + headerParams: headerParams + completionHandler: ^(NSDictionary *data, NSError *error) { + if (error) { + {{#returnBaseType}}completionBlock(nil, error);{{/returnBaseType}} + {{^returnBaseType}}completionBlock(error);{{/returnBaseType}} + return; + } + + {{#returnBaseType}} + {{#returnSimpleType}} + {{#returnTypeIsPrimitive}}{{#returnBaseType}}completionBlock( [[{{returnBaseType}} alloc]initWithString: data], nil);{{/returnBaseType}} + {{/returnTypeIsPrimitive}} + + {{^returnTypeIsPrimitive}} + {{#returnBaseType}}completionBlock( [[{{returnBaseType}} alloc]initWithValues: data], nil);{{/returnBaseType}} + {{/returnTypeIsPrimitive}} + {{/returnSimpleType}} + {{/returnBaseType}} + }]; + {{/returnBaseType}} + {{/returnSimpleType}} {{newline}} } diff --git a/src/main/resources/objc/model-body.mustache b/src/main/resources/objc/model-body.mustache index 89697d18e11..77c764f7781 100644 --- a/src/main/resources/objc/model-body.mustache +++ b/src/main/resources/objc/model-body.mustache @@ -5,8 +5,6 @@ @implementation {{classname}} -@synthesize raw = _raw; - {{#vars}} @synthesize {{name}} = _{{name}}; {{/vars}} @@ -23,6 +21,7 @@ - (id) initWithValues: (NSDictionary*)dict { {{#vars}} + {{#isPrimitiveType}} _{{name}} = [dict objectForKey:@"{{baseName}}"]; {{/isPrimitiveType}} @@ -38,9 +37,6 @@ } _{{{name}}} = [[NSArray alloc] initWithArray:objs]; } - } - else if([{{name}}_dict isKindOfClass:[NSDictionary class]] && [(NSDictionary*){{name}}_dict count] > 0) { - _{{name}} = [[{{complexType}} alloc]initWithValues:(NSDictionary*){{name}}_dict]; } {{/isContainer}} {{#isNotContainer}} @@ -49,7 +45,6 @@ {{/complexType}} {{/vars}} - self.raw = [[NSDictionary alloc] initWithDictionary:dict]; return self; } @@ -84,9 +79,6 @@ return output; } --(NSDictionary*) asRaw { - return _raw; -} {{/model}} @end {{/models}} diff --git a/src/main/resources/objc/model-header.mustache b/src/main/resources/objc/model-header.mustache index 8d086fa056f..87704ea495b 100644 --- a/src/main/resources/objc/model-header.mustache +++ b/src/main/resources/objc/model-header.mustache @@ -8,13 +8,11 @@ @interface {{classname}} : NIKSwaggerObject { @private - NSDictionary* raw; {{#vars}} {{datatype}} _{{name}}; //{{baseType}} {{/vars}} } -@property(nonatomic) NSDictionary* raw; {{newline}} {{#vars}} @property(nonatomic) {{datatype}} {{name}}; @@ -24,7 +22,6 @@ {{newline}} - (id) initWithValues: (NSDictionary*)dict; - (NSDictionary*) asDictionary; -- (NSDictionary*) asRaw; {{newline}} @end {{/model}}