Skip to content

Commit e6d7517

Browse files
committed
Update api-body.mustache, api-header.mustache,
apiBodyResponseWithContainer.mustache and apiNonPrimitiveResponse.mustache templates in objective-c client. * Update `asDictionary` method to `toDictionary` method which provided by JSONModel. * Update `initWithValues` method to `initWithDictionary` method which provided by JSONModel.
1 parent 19c05ee commit e6d7517

File tree

5 files changed

+19
-19
lines changed

5 files changed

+19
-19
lines changed

modules/swagger-codegen/src/main/resources/objc/api-body.mustache

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ static NSString * basePath = @"{{basePath}}";
5555
{{#operation}}
5656
-(NSNumber*) {{nickname}}WithCompletionBlock{{^allParams}}: {{/allParams}}{{#allParams}}{{#secondaryParam}} {{paramName}}{{/secondaryParam}}: ({{{dataType}}}) {{paramName}}
5757
{{/allParams}}
58-
{{#returnBaseType}}{{#hasParams}}completionHandler: {{/hasParams}}(void (^)({{returnType}} output, NSError* error))completionBlock{{/returnBaseType}}
58+
{{#returnBaseType}}{{#hasParams}}completionHandler: {{/hasParams}}(void (^)({{{returnType}}} output, NSError* error))completionBlock{{/returnBaseType}}
5959
{{^returnBaseType}}{{#hasParams}}completionHandler: {{/hasParams}}(void (^)(NSError* error))completionBlock{{/returnBaseType}} {
6060
6161
NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@{{path}}", basePath];
@@ -86,17 +86,17 @@ static NSString * basePath = @"{{basePath}}";
8686
if(__body != nil && [__body isKindOfClass:[NSArray class]]){
8787
NSMutableArray * objs = [[NSMutableArray alloc] init];
8888
for (id dict in (NSArray*)__body) {
89-
if([dict respondsToSelector:@selector(asDictionary)]) {
90-
[objs addObject:[(SWGObject*)dict asDictionary]];
89+
if([dict respondsToSelector:@selector(toDictionary)]) {
90+
[objs addObject:[(SWGObject*)dict toDictionary]];
9191
}
9292
else{
9393
[objs addObject:dict];
9494
}
9595
}
9696
bodyDictionary = objs;
9797
}
98-
else if([__body respondsToSelector:@selector(asDictionary)]) {
99-
bodyDictionary = [(SWGObject*)__body asDictionary];
98+
else if([__body respondsToSelector:@selector(toDictionary)]) {
99+
bodyDictionary = [(SWGObject*)__body toDictionary];
100100
}
101101
else if([__body isKindOfClass:[NSString class]]) {
102102
// convert it to a dictionary

modules/swagger-codegen/src/main/resources/objc/api-header.mustache

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@
2424
@param {{paramName}} {{description}}
2525
{{/allParams}}
2626

27-
return type: {{returnType}}
27+
return type: {{{returnType}}}
2828
*/
2929
-(NSNumber*) {{nickname}}WithCompletionBlock {{^allParams}}:{{/allParams}}{{#allParams}}{{#secondaryParam}} {{paramName}}{{/secondaryParam}}:({{{dataType}}}) {{paramName}} {{#hasMore}}
3030
{{/hasMore}}{{/allParams}}
3131
{{#returnBaseType}}{{#hasParams}}
32-
completionHandler: {{/hasParams}}(void (^)({{returnType}} output, NSError* error))completionBlock;{{/returnBaseType}}
32+
completionHandler: {{/hasParams}}(void (^)({{{returnType}}} output, NSError* error))completionBlock;{{/returnBaseType}}
3333
{{^returnBaseType}}{{#hasParams}}
3434
completionHandler: {{/hasParams}}(void (^)(NSError* error))completionBlock;{{/returnBaseType}}
3535

modules/swagger-codegen/src/main/resources/objc/apiBodyResponseWithContainer.mustache

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@
2525
{{returnBaseType}}* d = [[{{{returnBaseType}}} alloc]initWithString: dict];
2626
{{/returnTypeIsPrimitive}}
2727
{{^returnTypeIsPrimitive}}
28-
{{{returnBaseType}}}* d = [[{{{returnBaseType}}} alloc]initWithValues: dict];
28+
{{{returnBaseType}}}* d = [[{{{returnBaseType}}} alloc] initWithDictionary:dict error:nil];
2929
{{/returnTypeIsPrimitive}}
3030
[objs addObject:d];
3131
}
32-
completionBlock(objs, nil);
32+
completionBlock(({{{returnType}}})objs, nil);
3333
}
3434
{{/returnBaseType}}
3535
{{/isListContainer}}
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{{^returnTypeIsPrimitive}}
22
// comples response type
3-
return [client dictionary: requestUrl
4-
method: @"{{httpMethod}}"
5-
queryParams: queryParams
6-
body: bodyDictionary
3+
return [client dictionary: requestUrl
4+
method: @"{{httpMethod}}"
5+
queryParams: queryParams
6+
body: bodyDictionary
77
headerParams: headerParams
88
requestContentType: requestContentType
99
responseContentType: responseContentType
@@ -15,9 +15,9 @@
1515
}
1616
{{#returnType}}{{returnType}} result = nil;
1717
if (data) {
18-
result = [[{{#instantiationType}}NSClassFromString(@"{{{instantiationType}}}") {{/instantiationType}}{{^instantiationType}}{{{returnBaseType}}} {{/instantiationType}} alloc] {{#returnContainer}}{{#isMapContainer}}initWithDictionary{{/isMapContainer}}{{#isListContainer}}initWithValues{{/isListContainer}}{{/returnContainer}}{{^returnContainer}}initWithValues {{/returnContainer}}: data];
18+
result = [[{{#instantiationType}}NSClassFromString(@"{{{instantiationType}}}") {{/instantiationType}}{{^instantiationType}}{{{returnBaseType}}} {{/instantiationType}} alloc] {{#returnContainer}}{{#isMapContainer}}initWithDictionary{{/isMapContainer}}{{#isListContainer}} initWithDictionary{{/isListContainer}}{{/returnContainer}}{{^returnContainer}} initWithDictionary{{/returnContainer}}:data error:nil];
1919
}
2020
{{#returnType}}completionBlock(result , nil);{{/returnType}}
2121
{{/returnType}}
2222
}];
23-
{{/returnTypeIsPrimitive}}
23+
{{/returnTypeIsPrimitive}}

samples/client/petstore/objc/PetstoreClient/PetstoreClientTests/PetApiTest.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ - (void) testAddPet {
3939
[tag setName:[NSString stringWithFormat:@"tag-%d", i]];
4040
[tags addObject:tag];
4141
}
42-
[petToAdd setTags:tags];
42+
[petToAdd setTags:(NSArray<SWGTag>*)tags];
4343
[petToAdd setStatus:@"lost"];
4444

4545
SWGCategory * category = [[SWGCategory alloc] init];
@@ -75,7 +75,7 @@ - (void) testUpdatePet {
7575
[tag setName:[NSString stringWithFormat:@"tag-%d", i]];
7676
[tags addObject:tag];
7777
}
78-
[petToAdd setTags:tags];
78+
[petToAdd setTags:(NSArray<SWGTag>*)tags];
7979
[petToAdd setStatus:@"lost"];
8080

8181
SWGCategory * category = [[SWGCategory alloc] init];
@@ -103,7 +103,7 @@ - (void) testUpdatePet {
103103
NSLog(@"failed to fetch pet");
104104
}
105105
else {
106-
SWGPet* pet = [[SWGPet alloc] initWithValues:[output asDictionary]];
106+
SWGPet* pet = [[SWGPet alloc] initWithDictionary:[output toDictionary] error:nil];
107107
NSLog(@"got the pet");
108108

109109
[pet setName:@"programmer"];
@@ -122,7 +122,7 @@ - (void) testUpdatePet {
122122
NSLog(@"failed to fetch pet");
123123
}
124124
else {
125-
SWGPet* pet = [[SWGPet alloc] initWithValues:[output asDictionary]];
125+
SWGPet* pet = [[SWGPet alloc] initWithDictionary:[output toDictionary] error:nil];
126126
XCTAssertNotNil([pet _id], @"pet was nil");
127127
XCTAssertEqualObjects([pet name], @"programmer", @"pet name was not updated");
128128
XCTAssertEqualObjects([pet status], @"confused", @"pet status was not updated");

0 commit comments

Comments
 (0)