Skip to content

Commit 99271e7

Browse files
committed
added multi-param args
1 parent c9a2a14 commit 99271e7

File tree

7 files changed

+98
-99
lines changed

7 files changed

+98
-99
lines changed

modules/swagger-codegen/src/main/resources/objc/SWGApiClient.m

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#import "SWGApiClient.h"
22
#import "SWGFile.h"
3+
#import "SWGQueryParamCollection.h"
34

45
@implementation SWGApiClient
56

@@ -208,14 +209,45 @@ -(NSString*) pathWithQueryParamsToString:(NSString*) path
208209
if(counter == 0) separator = @"?";
209210
else separator = @"&";
210211
NSString * value;
211-
if([[queryParams valueForKey:key] isKindOfClass:[NSString class]]){
212-
value = [SWGApiClient escape:[queryParams valueForKey:key]];
212+
id queryParam = [queryParams valueForKey:key];
213+
if([queryParam isKindOfClass:[NSString class]]){
214+
[requestUrl appendString:[NSString stringWithFormat:@"%@%@=%@", separator,
215+
[SWGApiClient escape:key], [SWGApiClient escape:[queryParams valueForKey:key]]]];
216+
}
217+
else if([queryParam isKindOfClass:[SWGQueryParamCollection class]]){
218+
SWGQueryParamCollection * coll = (SWGQueryParamCollection*) queryParam;
219+
NSArray* values = [coll values];
220+
NSString* format = [coll format];
221+
222+
if([format isEqualToString:@"csv"]) {
223+
[requestUrl appendString:[NSString stringWithFormat:@"%@%@=%@", separator,
224+
[SWGApiClient escape:key], [NSString stringWithFormat:@"%@", [values componentsJoinedByString:@","]]]];
225+
226+
}
227+
else if([format isEqualToString:@"tsv"]) {
228+
[requestUrl appendString:[NSString stringWithFormat:@"%@%@=%@", separator,
229+
[SWGApiClient escape:key], [NSString stringWithFormat:@"%@", [values componentsJoinedByString:@"\t"]]]];
230+
231+
}
232+
else if([format isEqualToString:@"pipes"]) {
233+
[requestUrl appendString:[NSString stringWithFormat:@"%@%@=%@", separator,
234+
[SWGApiClient escape:key], [NSString stringWithFormat:@"%@", [values componentsJoinedByString:@"|"]]]];
235+
236+
}
237+
else if([format isEqualToString:@"multi"]) {
238+
for(id obj in values) {
239+
[requestUrl appendString:[NSString stringWithFormat:@"%@%@=%@", separator,
240+
[SWGApiClient escape:key], [NSString stringWithFormat:@"%@", obj]]];
241+
counter += 1;
242+
}
243+
244+
}
213245
}
214246
else {
215-
value = [NSString stringWithFormat:@"%@", [queryParams valueForKey:key]];
247+
[requestUrl appendString:[NSString stringWithFormat:@"%@%@=%@", separator,
248+
[SWGApiClient escape:key], [NSString stringWithFormat:@"%@", [queryParams valueForKey:key]]]];
216249
}
217-
[requestUrl appendString:[NSString stringWithFormat:@"%@%@=%@", separator,
218-
[SWGApiClient escape:key], value]];
250+
219251
counter += 1;
220252
}
221253
}

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,9 @@
1616
/**
1717

1818
{{{summary}}}
19-
{{#notes}}
20-
{{{notes}}}
21-
{{/notes}}
19+
{{#notes}}{{{notes}}}{{/notes}}
2220

23-
{{#allParams}}
24-
@param {{paramName}} {{description}}
21+
{{#allParams}}@param {{paramName}} {{description}}
2522
{{/allParams}}
2623

2724
return type: {{returnType}}

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

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ - (void)testCreateAndGetPet {
3232
[expectation fulfill];
3333
}];
3434
}];
35-
[self waitForExpectationsWithTimeout:2.0 handler:nil];
35+
[self waitForExpectationsWithTimeout:10.0 handler:nil];
3636
}
3737

3838
- (void) testUpdatePet {
@@ -84,7 +84,7 @@ - (void) testUpdatePet {
8484
}];
8585
}
8686
}];
87-
[self waitForExpectationsWithTimeout:2.0 handler:nil];
87+
[self waitForExpectationsWithTimeout:10.0 handler:nil];
8888
}
8989

9090
- (void)testGetPetByStatus {
@@ -104,15 +104,18 @@ - (void)testGetPetByStatus {
104104
XCTFail(@"failed to fetch pets");
105105
}
106106
else {
107+
bool found = false;
107108
for(SWGPet* fetched in output) {
108109
if([pet _id] == [fetched _id]) {
109-
[expectation fulfill];
110+
found = true;
110111
}
111112
}
113+
if(found)
114+
[expectation fulfill];
112115
}
113116
}];
114117
}];
115-
[self waitForExpectationsWithTimeout:2.0 handler:nil];
118+
[self waitForExpectationsWithTimeout:10.0 handler:nil];
116119
}
117120

118121
- (void)testGetPetByTags {
@@ -133,20 +136,49 @@ - (void)testGetPetByTags {
133136
XCTFail(@"got error %@", error);
134137
}
135138
if(output){
139+
bool hasTag = false;
136140
for(SWGPet * fetched in output) {
137-
bool hasTag = false;
138141
for(SWGTag * tag in [fetched tags]){
139142
if(fetched._id == pet._id && [[tag name] isEqualToString:@"tony"])
140143
hasTag = true;
141144
}
142145
if(!hasTag)
143146
XCTFail(@"failed to find tag in pet");
144147
}
148+
if(hasTag)
149+
[expectation fulfill];
145150
}
146-
[expectation fulfill];
147151
}];
148152
}];
149-
[self waitForExpectationsWithTimeout:2.0 handler:nil];
153+
[self waitForExpectationsWithTimeout:10.0 handler:nil];
154+
}
155+
156+
- (void)testDeletePet {
157+
XCTestExpectation *expectation = [self expectationWithDescription:@"testGetPetById"];
158+
159+
SWGPet* pet = [self createPet];
160+
161+
[api addPetWithCompletionBlock:pet completionHandler:^(NSError *error) {
162+
if(error){
163+
XCTFail(@"got error %@", error);
164+
}
165+
[api deletePetWithCompletionBlock:@"" petId:[NSString stringWithFormat:@"%@", [pet _id]] completionHandler:^(NSError *error) {
166+
if(error){
167+
XCTFail(@"got error %@", error);
168+
}
169+
[api getPetByIdWithCompletionBlock:[pet _id] completionHandler:^(SWGPet *output, NSError *error) {
170+
if(error) {
171+
// good
172+
[expectation fulfill];
173+
174+
}
175+
else {
176+
XCTFail(@"expected a failure");
177+
}
178+
}];
179+
}];
180+
}];
181+
[self waitForExpectationsWithTimeout:10.0 handler:nil];
150182
}
151183

152184
- (SWGPet*) createPet {

samples/client/petstore/objc/client/SWGApiClient.m

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -209,40 +209,43 @@ -(NSString*) pathWithQueryParamsToString:(NSString*) path
209209
if(counter == 0) separator = @"?";
210210
else separator = @"&";
211211
NSString * value;
212-
id queryParamValue = [queryParams valueForKey:key];
213-
if([queryParamValue isKindOfClass:[NSString class]]){
214-
value = [SWGApiClient escape:[queryParams valueForKey:key]];
212+
id queryParam = [queryParams valueForKey:key];
213+
if([queryParam isKindOfClass:[NSString class]]){
215214
[requestUrl appendString:[NSString stringWithFormat:@"%@%@=%@", separator,
216-
[SWGApiClient escape:key], value]];
215+
[SWGApiClient escape:key], [SWGApiClient escape:[queryParams valueForKey:key]]]];
217216
}
218-
else if ([queryParamValue isKindOfClass:[SWGQueryParamCollection class]]) {
219-
SWGQueryParamCollection* c = (SWGQueryParamCollection* ) queryParamValue;
220-
NSString * format = [c format];
221-
NSArray * values = [c values];
217+
else if([queryParam isKindOfClass:[SWGQueryParamCollection class]]){
218+
SWGQueryParamCollection * coll = (SWGQueryParamCollection*) queryParam;
219+
NSArray* values = [coll values];
220+
NSString* format = [coll format];
221+
222222
if([format isEqualToString:@"csv"]) {
223223
[requestUrl appendString:[NSString stringWithFormat:@"%@%@=%@", separator,
224-
[SWGApiClient escape:key], [values componentsJoinedByString:@","]]];
224+
[SWGApiClient escape:key], [NSString stringWithFormat:@"%@", [values componentsJoinedByString:@","]]]];
225+
225226
}
226227
else if([format isEqualToString:@"tsv"]) {
227228
[requestUrl appendString:[NSString stringWithFormat:@"%@%@=%@", separator,
228-
[SWGApiClient escape:key], [values componentsJoinedByString:@"\t"]]];
229+
[SWGApiClient escape:key], [NSString stringWithFormat:@"%@", [values componentsJoinedByString:@"\t"]]]];
230+
229231
}
230-
else if ([format isEqualToString:@"pipes"]) {
232+
else if([format isEqualToString:@"pipes"]) {
231233
[requestUrl appendString:[NSString stringWithFormat:@"%@%@=%@", separator,
232-
[SWGApiClient escape:key], [values componentsJoinedByString:@"|"]]];
234+
[SWGApiClient escape:key], [NSString stringWithFormat:@"%@", [values componentsJoinedByString:@"|"]]]];
235+
233236
}
234237
else if([format isEqualToString:@"multi"]) {
235238
for(id obj in values) {
236-
237-
[requestUrl appendString: [NSString stringWithFormat:@"%@%@=%@", separator, [SWGApiClient escape:key], obj]];
238-
if(counter > 0) separator = @"&";
239+
[requestUrl appendString:[NSString stringWithFormat:@"%@%@=%@", separator,
240+
[SWGApiClient escape:key], [NSString stringWithFormat:@"%@", obj]]];
241+
counter += 1;
239242
}
243+
240244
}
241245
}
242246
else {
243-
value = [NSString stringWithFormat:@"%@", [queryParams valueForKey:key]];
244247
[requestUrl appendString:[NSString stringWithFormat:@"%@%@=%@", separator,
245-
[SWGApiClient escape:key], value]];
248+
[SWGApiClient escape:key], [NSString stringWithFormat:@"%@", [queryParams valueForKey:key]]]];
246249
}
247250

248251
counter += 1;

samples/client/petstore/objc/client/SWGPetApi.h

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@
1515
1616
Update an existing pet
1717
18-
19-
2018
21-
2219
@param body Pet object that needs to be added to the store
2320
2421
@@ -34,10 +31,7 @@
3431
3532
Add a new pet to the store
3633
37-
38-
3934
40-
4135
@param body Pet object that needs to be added to the store
4236
4337
@@ -52,11 +46,8 @@
5246
/**
5347
5448
Finds Pets by status
55-
5649
Multiple status values can be provided with comma seperated strings
57-
5850
59-
6051
@param status Status values that need to be considered for filter
6152
6253
@@ -71,11 +62,8 @@
7162
/**
7263
7364
Finds Pets by tags
74-
7565
Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing.
76-
7766
78-
7967
@param tags Tags to filter by
8068
8169
@@ -90,11 +78,8 @@
9078
/**
9179
9280
Find pet by ID
93-
9481
Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions
95-
9682
97-
9883
@param petId ID of pet that needs to be fetched
9984
10085
@@ -110,14 +95,9 @@
11095
11196
Updates a pet in the store with form data
11297
113-
114-
11598
116-
11799
@param petId ID of pet that needs to be updated
118-
119100
@param name Updated name of the pet
120-
121101
@param status Updated status of the pet
122102
123103
@@ -135,12 +115,8 @@
135115
136116
Deletes a pet
137117
138-
139-
140118
141-
142119
@param api_key
143-
144120
@param petId Pet id to delete
145121
146122
@@ -157,14 +133,9 @@
157133
158134
uploads an image
159135
160-
161-
162136
163-
164137
@param petId ID of pet to update
165-
166138
@param additionalMetadata Additional data to pass to server
167-
168139
@param file file to upload
169140
170141

samples/client/petstore/objc/client/SWGStoreApi.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313
/**
1414
1515
Returns pet inventories by status
16-
1716
Returns a map of status codes to quantities
18-
1917
2018
2119
@@ -30,10 +28,7 @@
3028
3129
Place an order for a pet
3230
33-
34-
3531
36-
3732
@param body order placed for purchasing the pet
3833
3934
@@ -48,11 +43,8 @@
4843
/**
4944
5045
Find purchase order by ID
51-
5246
For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions
53-
5447
55-
5648
@param orderId ID of pet that needs to be fetched
5749
5850
@@ -67,11 +59,8 @@
6759
/**
6860
6961
Delete purchase order by ID
70-
7162
For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
72-
7363
74-
7564
@param orderId ID of the order that needs to be deleted
7665
7766

0 commit comments

Comments
 (0)