removed raw

This commit is contained in:
Tony Tam 2012-09-26 22:15:52 -07:00
parent 67ce62c622
commit 031dd20072
3 changed files with 74 additions and 26 deletions

View File

@ -25,6 +25,13 @@ static NSString * basePath = @"{{basePath}}";
} }
{{#operation}} {{#operation}}
/**
*
* returnTypeIsPrimitive: {{returnTypeIsPrimitive}}
* returnBaseType: {{returnBaseType}}
* returnContainer: {{returnContainer}}
*
**/
-(void) {{nickname}}WithCompletionBlock {{^allParams}}:{{/allParams}}{{#allParams}}{{#secondaryParam}} {{paramName}}{{/secondaryParam}}:({{{dataType}}}) {{paramName}} {{#hasMore}}{{newline}}{{/hasMore}}{{/allParams}}{{newline}} -(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 (^)({{returnType}}, NSError *))completionBlock{{/returnBaseType}}
{{^returnBaseType}}completionHandler:(void (^)(NSError *))completionBlock{{/returnBaseType}} { {{^returnBaseType}}completionHandler:(void (^)(NSError *))completionBlock{{/returnBaseType}} {
@ -81,22 +88,13 @@ static NSString * basePath = @"{{basePath}}";
{{/requiredParams}} {{/requiredParams}}
{{/requiredParamCount}} {{/requiredParamCount}}
{{#returnTypeIsPrimitive}} {{#returnContainer}}
[_api stringWithCompletionBlock: requestUrl
method: @"{{httpMethod}}"
queryParams: queryParams
body: bodyDictionary
headerParams: headerParams
completionHandler: ^(NSString *data, NSError *error) {
{{/returnTypeIsPrimitive}}
{{^returnTypeIsPrimitive}}
[_api dictionaryWithCompletionBlock: requestUrl [_api dictionaryWithCompletionBlock: requestUrl
method: @"{{httpMethod}}" method: @"{{httpMethod}}"
queryParams: queryParams queryParams: queryParams
body: bodyDictionary body: bodyDictionary
headerParams: headerParams headerParams: headerParams
completionHandler: ^(NSDictionary *data, NSError *error) { completionHandler: ^(NSDictionary *data, NSError *error) {
{{/returnTypeIsPrimitive}}
if (error) { if (error) {
{{#returnBaseType}}completionBlock(nil, error);{{/returnBaseType}} {{#returnBaseType}}completionBlock(nil, error);{{/returnBaseType}}
{{^returnBaseType}}completionBlock(error);{{/returnBaseType}} {{^returnBaseType}}completionBlock(error);{{/returnBaseType}}
@ -104,16 +102,19 @@ static NSString * basePath = @"{{basePath}}";
} }
{{#returnBaseType}} {{#returnBaseType}}
{{#returnContainer}}
if([data isKindOfClass:[NSArray class]]){ if([data isKindOfClass:[NSArray class]]){
NSMutableArray * objs = [[NSMutableArray alloc] initWithCapacity:[data count]]; NSMutableArray * objs = [[NSMutableArray alloc] initWithCapacity:[data count]];
for (NSDictionary* dict in (NSArray*)data) { for (NSDictionary* dict in (NSArray*)data) {
{{#returnTypeIsPrimitive}}
{{returnBaseType}}* d = [[{{returnBaseType}} alloc]initWithString: data];
{{/returnTypeIsPrimitive}}
{{^returnTypeIsPrimitive}}
{{{returnBaseType}}}* d = [[{{{returnBaseType}}} alloc]initWithValues: dict]; {{{returnBaseType}}}* d = [[{{{returnBaseType}}} alloc]initWithValues: dict];
{{/returnTypeIsPrimitive}}
[objs addObject:d]; [objs addObject:d];
} }
completionBlock(objs, nil); completionBlock(objs, nil);
} }
{{/returnContainer}}
{{#returnSimpleType}} {{#returnSimpleType}}
{{#returnTypeIsPrimitive}}{{#returnBaseType}}completionBlock( [[{{returnBaseType}} alloc]initWithString: data], nil);{{/returnBaseType}} {{#returnTypeIsPrimitive}}{{#returnBaseType}}completionBlock( [[{{returnBaseType}} alloc]initWithString: data], nil);{{/returnBaseType}}
{{/returnTypeIsPrimitive}} {{/returnTypeIsPrimitive}}
@ -123,9 +124,67 @@ static NSString * basePath = @"{{basePath}}";
{{/returnTypeIsPrimitive}} {{/returnTypeIsPrimitive}}
{{/returnSimpleType}} {{/returnSimpleType}}
{{/returnBaseType}} {{/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}} {{newline}}
} }

View File

@ -5,8 +5,6 @@
@implementation {{classname}} @implementation {{classname}}
@synthesize raw = _raw;
{{#vars}} {{#vars}}
@synthesize {{name}} = _{{name}}; @synthesize {{name}} = _{{name}};
{{/vars}} {{/vars}}
@ -23,6 +21,7 @@
- (id) initWithValues: (NSDictionary*)dict - (id) initWithValues: (NSDictionary*)dict
{ {
{{#vars}} {{#vars}}
{{#isPrimitiveType}} {{#isPrimitiveType}}
_{{name}} = [dict objectForKey:@"{{baseName}}"]; _{{name}} = [dict objectForKey:@"{{baseName}}"];
{{/isPrimitiveType}} {{/isPrimitiveType}}
@ -39,9 +38,6 @@
_{{{name}}} = [[NSArray alloc] initWithArray:objs]; _{{{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}} {{/isContainer}}
{{#isNotContainer}} {{#isNotContainer}}
_{{name}} = [[{{complexType}} alloc]initWithValues:{{name}}_dict]; _{{name}} = [[{{complexType}} alloc]initWithValues:{{name}}_dict];
@ -49,7 +45,6 @@
{{/complexType}} {{/complexType}}
{{/vars}} {{/vars}}
self.raw = [[NSDictionary alloc] initWithDictionary:dict];
return self; return self;
} }
@ -84,9 +79,6 @@
return output; return output;
} }
-(NSDictionary*) asRaw {
return _raw;
}
{{/model}} {{/model}}
@end @end
{{/models}} {{/models}}

View File

@ -8,13 +8,11 @@
@interface {{classname}} : NIKSwaggerObject { @interface {{classname}} : NIKSwaggerObject {
@private @private
NSDictionary* raw;
{{#vars}} {{#vars}}
{{datatype}} _{{name}}; //{{baseType}} {{datatype}} _{{name}}; //{{baseType}}
{{/vars}} {{/vars}}
} }
@property(nonatomic) NSDictionary* raw;
{{newline}} {{newline}}
{{#vars}} {{#vars}}
@property(nonatomic) {{datatype}} {{name}}; @property(nonatomic) {{datatype}} {{name}};
@ -24,7 +22,6 @@
{{newline}} {{newline}}
- (id) initWithValues: (NSDictionary*)dict; - (id) initWithValues: (NSDictionary*)dict;
- (NSDictionary*) asDictionary; - (NSDictionary*) asDictionary;
- (NSDictionary*) asRaw;
{{newline}} {{newline}}
@end @end
{{/model}} {{/model}}