Skip to content

Commit 4484625

Browse files
committed
updated logic, merged
1 parent 14cbc2d commit 4484625

File tree

6 files changed

+265
-103
lines changed

6 files changed

+265
-103
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,10 @@ static NSString * basePath = @"{{basePath}}";
129129
if(bodyDictionary == nil) {
130130
bodyDictionary = [[NSMutableArray alloc] init];
131131
}
132-
[bodyDictionary addObject:{{paramName}}];
133-
{{paramName}}.paramName = @"{{baseName}}";
132+
if({{paramName}} != nil) {
133+
[bodyDictionary addObject:{{paramName}}];
134+
{{paramName}}.paramName = @"{{baseName}}";
135+
}
134136
{{/isFile}}
135137
if(bodyDictionary == nil) {
136138
bodyDictionary = [[NSMutableArray alloc] init];

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

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ - (void)testGetPetByTags {
154154
}
155155

156156
- (void)testDeletePet {
157-
XCTestExpectation *expectation = [self expectationWithDescription:@"testGetPetById"];
157+
XCTestExpectation *expectation = [self expectationWithDescription:@"testDeletePet"];
158158

159159
SWGPet* pet = [self createPet];
160160

@@ -181,6 +181,42 @@ - (void)testDeletePet {
181181
[self waitForExpectationsWithTimeout:10.0 handler:nil];
182182
}
183183

184+
- (void)testUploadFile {
185+
XCTestExpectation *expectation = [self expectationWithDescription:@"testUploadFile"];
186+
187+
NSString* str = @"teststring";
188+
NSData* data = [str dataUsingEncoding:NSUTF8StringEncoding];
189+
190+
SWGFile * file = [[SWGFile alloc] initWithNameData: @"myFile.txt" mimeType:@"text/plain" data:data];
191+
192+
[api uploadFileWithCompletionBlock:@1 additionalMetadata:@"special-metadata" file:file completionHandler:^(NSError *error) {
193+
if(error) {
194+
// good
195+
XCTFail(@"expected a failure");
196+
197+
}
198+
else {
199+
[expectation fulfill];
200+
}
201+
}];
202+
[self waitForExpectationsWithTimeout:10.0 handler:nil];
203+
}
204+
205+
- (void)TestUploadWithoutFile {
206+
XCTestExpectation *expectation = [self expectationWithDescription:@"testUploadWithoutFile"];
207+
208+
[api uploadFileWithCompletionBlock:@1 additionalMetadata:@"special-metadata" file:nil completionHandler:^(NSError *error) {
209+
if(error) {
210+
XCTFail(@"failed to upload");
211+
212+
}
213+
else {
214+
[expectation fulfill];
215+
}
216+
}];
217+
[self waitForExpectationsWithTimeout:10.0 handler:nil];
218+
}
219+
184220
- (SWGPet*) createPet {
185221
SWGPet * pet = [[SWGPet alloc] init];
186222
pet._id = [[NSNumber alloc] initWithLong:[[NSDate date] timeIntervalSince1970]];

0 commit comments

Comments
 (0)