Skip to content

Commit 85463f0

Browse files
committed
rebuilt sample
1 parent 30acfc1 commit 85463f0

File tree

6 files changed

+292
-82
lines changed

6 files changed

+292
-82
lines changed

samples/client/petstore/objc/PetstoreClient/PetstoreClient/ViewController.m

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ - (void)viewDidLoad
2222

2323
SWGPetApi * api = [[SWGPetApi alloc] init];
2424

25-
// [api getPetByIdWithCompletionBlock:@10 completionHandler:^(SWGPet *output, NSError *error) {
26-
// NSLog(@"%@", [output asDictionary]);
27-
// [output set_id:@101];
28-
// [api addPetWithCompletionBlock:output completionHandler:^(NSError *error) {
29-
// NSLog(@"Done!");
30-
// }];
31-
32-
// load data into file
33-
// }];
25+
[api getPetByIdWithCompletionBlock:@10 completionHandler:^(SWGPet *output, NSError *error) {
26+
NSLog(@"%@", [output asDictionary]);
27+
[output set_id:@101];
28+
[api addPetWithCompletionBlock:output completionHandler:^(NSError *error) {
29+
NSLog(@"Done!");
30+
}];
31+
32+
// load data into file
33+
}];
3434
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"test-1" ofType:@"png"];
3535
NSData *myData = [NSData dataWithContentsOfFile:filePath];
3636

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
platform :ios, '6.0'
2-
xcodeproj 'swaggerClient/swaggerClient.xcodeproj'
2+
xcodeproj 'PetstoreClient/PetstoreClient.xcodeproj'
33
pod 'AFNetworking', '~> 2.1'

samples/client/petstore/objc/Podfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ DEPENDENCIES:
2727
SPEC CHECKSUMS:
2828
AFNetworking: 8bee59492a6ff15d69130efa4d0dc67e0094a52a
2929

30-
COCOAPODS: 0.35.0
30+
COCOAPODS: 0.36.0

samples/client/petstore/objc/client/SWGPetApi.m

Lines changed: 156 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,26 @@ -(NSNumber*) updatePetWithCompletionBlock: (SWGPet*) body
109109
SWGApiClient* client = [SWGApiClient sharedClientFromPool:basePath];
110110

111111

112+
113+
114+
115+
116+
// it's void
117+
return [client stringWithCompletionBlock: requestUrl
118+
method: @"PUT"
119+
queryParams: queryParams
120+
body: bodyDictionary
121+
headerParams: headerParams
122+
requestContentType: requestContentType
123+
responseContentType: responseContentType
124+
completionBlock: ^(NSString *data, NSError *error) {
125+
if (error) {
126+
completionBlock(error);
127+
return;
128+
}
129+
completionBlock(nil);
130+
}];
131+
112132

113133
}
114134

@@ -170,6 +190,26 @@ -(NSNumber*) addPetWithCompletionBlock: (SWGPet*) body
170190
SWGApiClient* client = [SWGApiClient sharedClientFromPool:basePath];
171191

172192

193+
194+
195+
196+
197+
// it's void
198+
return [client stringWithCompletionBlock: requestUrl
199+
method: @"POST"
200+
queryParams: queryParams
201+
body: bodyDictionary
202+
headerParams: headerParams
203+
requestContentType: requestContentType
204+
responseContentType: responseContentType
205+
completionBlock: ^(NSString *data, NSError *error) {
206+
if (error) {
207+
completionBlock(error);
208+
return;
209+
}
210+
completionBlock(nil);
211+
}];
212+
173213

174214
}
175215

@@ -199,18 +239,18 @@ -(NSNumber*) findPetsByStatusWithCompletionBlock: (NSArray*) status
199239
id bodyDictionary = nil;
200240

201241

202-
bodyDictionary = [[NSMutableArray alloc] init];
203242

204243
NSMutableDictionary * formParams = [[NSMutableDictionary alloc]init];
205244

206245

207-
[bodyDictionary addObject:formParams];
208246

209247

210248

211249

212250
SWGApiClient* client = [SWGApiClient sharedClientFromPool:basePath];
213251

252+
253+
// response is in a container
214254
// array container response type
215255
return [client dictionary: requestUrl
216256
method: @"GET"
@@ -225,8 +265,24 @@ -(NSNumber*) findPetsByStatusWithCompletionBlock: (NSArray*) status
225265
return;
226266
}
227267

268+
if([data isKindOfClass:[NSArray class]]){
269+
NSMutableArray * objs = [[NSMutableArray alloc] initWithCapacity:[data count]];
270+
for (NSDictionary* dict in (NSArray*)data) {
271+
272+
273+
SWGPet* d = [[SWGPet alloc]initWithValues: dict];
274+
275+
[objs addObject:d];
276+
}
277+
completionBlock(objs, nil);
278+
}
279+
280+
228281
}];
229282

283+
284+
285+
230286

231287
}
232288

@@ -256,18 +312,18 @@ -(NSNumber*) findPetsByTagsWithCompletionBlock: (NSArray*) tags
256312
id bodyDictionary = nil;
257313

258314

259-
bodyDictionary = [[NSMutableArray alloc] init];
260315

261316
NSMutableDictionary * formParams = [[NSMutableDictionary alloc]init];
262317

263318

264-
[bodyDictionary addObject:formParams];
265319

266320

267321

268322

269323
SWGApiClient* client = [SWGApiClient sharedClientFromPool:basePath];
270324

325+
326+
// response is in a container
271327
// array container response type
272328
return [client dictionary: requestUrl
273329
method: @"GET"
@@ -282,8 +338,24 @@ -(NSNumber*) findPetsByTagsWithCompletionBlock: (NSArray*) tags
282338
return;
283339
}
284340

341+
if([data isKindOfClass:[NSArray class]]){
342+
NSMutableArray * objs = [[NSMutableArray alloc] initWithCapacity:[data count]];
343+
for (NSDictionary* dict in (NSArray*)data) {
344+
345+
346+
SWGPet* d = [[SWGPet alloc]initWithValues: dict];
347+
348+
[objs addObject:d];
349+
}
350+
completionBlock(objs, nil);
351+
}
352+
353+
285354
}];
286355

356+
357+
358+
287359

288360
}
289361

@@ -312,21 +384,25 @@ -(NSNumber*) getPetByIdWithCompletionBlock: (NSNumber*) petId
312384
id bodyDictionary = nil;
313385

314386

315-
bodyDictionary = [[NSMutableArray alloc] init];
316387

317388
NSMutableDictionary * formParams = [[NSMutableDictionary alloc]init];
318389

319390

320-
[bodyDictionary addObject:formParams];
321391

322392

323393

324394

325395
SWGApiClient* client = [SWGApiClient sharedClientFromPool:basePath];
326396

327397

398+
399+
400+
// non container response
401+
328402

403+
329404

405+
// complex response
330406

331407
// comples response type
332408
return [client dictionary: requestUrl
@@ -342,16 +418,17 @@ -(NSNumber*) getPetByIdWithCompletionBlock: (NSNumber*) petId
342418

343419
return;
344420
}
345-
346-
SWGPet *result = nil;
421+
SWGPet* result = nil;
347422
if (data) {
348-
result = [[SWGPet alloc]initWithValues: data];
423+
result = [[SWGPet alloc] initWithValues : data];
349424
}
350425
completionBlock(result , nil);
351426

352427
}];
353428

354429

430+
431+
355432
}
356433

357434
-(NSNumber*) updatePetWithFormWithCompletionBlock: (NSString*) petId
@@ -381,23 +458,53 @@ -(NSNumber*) updatePetWithFormWithCompletionBlock: (NSString*) petId
381458
id bodyDictionary = nil;
382459

383460

384-
bodyDictionary = [[NSMutableArray alloc] init];
385461

386462
NSMutableDictionary * formParams = [[NSMutableDictionary alloc]init];
387463

388464

465+
389466
formParams[@"name"] = name;
390467

468+
if(bodyDictionary == nil) {
469+
bodyDictionary = [[NSMutableArray alloc] init];
470+
}
471+
[bodyDictionary addObject:formParams];
472+
473+
391474
formParams[@"status"] = status;
392475

476+
if(bodyDictionary == nil) {
477+
bodyDictionary = [[NSMutableArray alloc] init];
478+
}
393479
[bodyDictionary addObject:formParams];
394480

481+
395482

396483

397484

398485
SWGApiClient* client = [SWGApiClient sharedClientFromPool:basePath];
399486

400487

488+
489+
490+
491+
492+
// it's void
493+
return [client stringWithCompletionBlock: requestUrl
494+
method: @"POST"
495+
queryParams: queryParams
496+
body: bodyDictionary
497+
headerParams: headerParams
498+
requestContentType: requestContentType
499+
responseContentType: responseContentType
500+
completionBlock: ^(NSString *data, NSError *error) {
501+
if (error) {
502+
completionBlock(error);
503+
return;
504+
}
505+
completionBlock(nil);
506+
}];
507+
401508

402509
}
403510

@@ -429,19 +536,37 @@ -(NSNumber*) deletePetWithCompletionBlock: (NSString*) api_key
429536
id bodyDictionary = nil;
430537

431538

432-
bodyDictionary = [[NSMutableArray alloc] init];
433539

434540
NSMutableDictionary * formParams = [[NSMutableDictionary alloc]init];
435541

436542

437-
[bodyDictionary addObject:formParams];
438543

439544

440545

441546

442547
SWGApiClient* client = [SWGApiClient sharedClientFromPool:basePath];
443548

444549

550+
551+
552+
553+
554+
// it's void
555+
return [client stringWithCompletionBlock: requestUrl
556+
method: @"DELETE"
557+
queryParams: queryParams
558+
body: bodyDictionary
559+
headerParams: headerParams
560+
requestContentType: requestContentType
561+
responseContentType: responseContentType
562+
completionBlock: ^(NSString *data, NSError *error) {
563+
if (error) {
564+
completionBlock(error);
565+
return;
566+
}
567+
completionBlock(nil);
568+
}];
569+
445570

446571
}
447572

@@ -472,31 +597,44 @@ -(NSNumber*) uploadFileWithCompletionBlock: (NSNumber*) petId
472597
id bodyDictionary = nil;
473598

474599

475-
bodyDictionary = [[NSMutableArray alloc] init];
476600

477601
NSMutableDictionary * formParams = [[NSMutableDictionary alloc]init];
478602

479603

604+
480605
formParams[@"additionalMetadata"] = additionalMetadata;
481606

607+
if(bodyDictionary == nil) {
608+
bodyDictionary = [[NSMutableArray alloc] init];
609+
}
610+
[bodyDictionary addObject:formParams];
611+
612+
482613
requestContentType = @"multipart/form-data";
614+
if(bodyDictionary == nil) {
615+
bodyDictionary = [[NSMutableArray alloc] init];
616+
}
483617
[bodyDictionary addObject:file];
484618
file.paramName = @"file";
485619

620+
if(bodyDictionary == nil) {
621+
bodyDictionary = [[NSMutableArray alloc] init];
622+
}
486623
[bodyDictionary addObject:formParams];
487624

625+
488626

489627

490628

491629
SWGApiClient* client = [SWGApiClient sharedClientFromPool:basePath];
492630

493631

632+
494633

495-
// primitive response type
496-
634+
497635

498-
// no return base type
499-
return [client stringWithCompletionBlock: requestUrl
636+
// it's void
637+
return [client stringWithCompletionBlock: requestUrl
500638
method: @"POST"
501639
queryParams: queryParams
502640
body: bodyDictionary
@@ -510,9 +648,7 @@ -(NSNumber*) uploadFileWithCompletionBlock: (NSNumber*) petId
510648
}
511649
completionBlock(nil);
512650
}];
513-
514-
515-
651+
516652

517653
}
518654

0 commit comments

Comments
 (0)