Skip to content

Commit 0622838

Browse files
committed
Fixed issues about logging in objc client
1 parent b7d64d1 commit 0622838

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ static void (^reachabilityChangeBlock)(int);
6565
error:(NSError*)error {
6666
{{classPrefix}}Configuration *config = [{{classPrefix}}Configuration sharedConfig];
6767

68+
if (!config.debug) {
69+
return;
70+
}
71+
6872
NSString *message = [NSString stringWithFormat:@"\n[DEBUG] Request body \n~BEGIN~\n %@\n~END~\n"\
6973
"[DEBUG] HTTP Response body \n~BEGIN~\n %@\n~END~\n",
7074
[[NSString alloc] initWithData:request.HTTPBody encoding:NSUTF8StringEncoding],
@@ -74,8 +78,7 @@ static void (^reachabilityChangeBlock)(int);
7478
[config.loggingFileHanlder seekToEndOfFile];
7579
[config.loggingFileHanlder writeData:[message dataUsingEncoding:NSUTF8StringEncoding]];
7680
}
77-
78-
if ([[{{classPrefix}}Configuration sharedConfig] debug]){
81+
else {
7982
NSLog(@"%@", message);
8083
}
8184
}

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

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ - (void)logResponse:(AFHTTPRequestOperation *)operation
6565
error:(NSError*)error {
6666
SWGConfiguration *config = [SWGConfiguration sharedConfig];
6767

68+
if (!config.debug) {
69+
return;
70+
}
71+
6872
NSString *message = [NSString stringWithFormat:@"\n[DEBUG] Request body \n~BEGIN~\n %@\n~END~\n"\
6973
"[DEBUG] HTTP Response body \n~BEGIN~\n %@\n~END~\n",
7074
[[NSString alloc] initWithData:request.HTTPBody encoding:NSUTF8StringEncoding],
@@ -74,8 +78,9 @@ - (void)logResponse:(AFHTTPRequestOperation *)operation
7478
[config.loggingFileHanlder seekToEndOfFile];
7579
[config.loggingFileHanlder writeData:[message dataUsingEncoding:NSUTF8StringEncoding]];
7680
}
77-
78-
NSLog(@"%@", message);
81+
else {
82+
NSLog(@"%@", message);
83+
}
7984
}
8085

8186
#pragma mark - Cache Methods
@@ -177,8 +182,9 @@ +(NSNumber*) nextRequestId {
177182

178183
+(NSNumber*) queueRequest {
179184
NSNumber* requestId = [SWGApiClient nextRequestId];
180-
if([[SWGConfiguration sharedConfig] debug])
185+
if([[SWGConfiguration sharedConfig] debug]) {
181186
NSLog(@"added %@ to request queue", requestId);
187+
}
182188
[queuedRequests addObject:requestId];
183189
return requestId;
184190
}
@@ -198,8 +204,9 @@ -(Boolean) executeRequestWithId:(NSNumber*) requestId {
198204
}];
199205

200206
if(matchingItems.count == 1) {
201-
if([[SWGConfiguration sharedConfig] debug])
207+
if([[SWGConfiguration sharedConfig] debug]){
202208
NSLog(@"removing request id %@", requestId);
209+
}
203210
[queuedRequests removeObject:requestId];
204211
return YES;
205212
}
@@ -577,15 +584,21 @@ -(NSNumber*) requestWithCompletionBlock: (NSString*) path
577584
hasHeaderParams = true;
578585
}
579586
if(offlineState) {
580-
NSLog(@"%@ cache forced", resourcePath);
587+
if ([[SWGConfiguration sharedConfig] debug]){
588+
NSLog(@"%@ cache forced", resourcePath);
589+
}
581590
[request setCachePolicy:NSURLRequestReturnCacheDataDontLoad];
582591
}
583592
else if(!hasHeaderParams && [method isEqualToString:@"GET"] && cacheEnabled) {
584-
NSLog(@"%@ cache enabled", resourcePath);
593+
if ([[SWGConfiguration sharedConfig] debug]){
594+
NSLog(@"%@ cache enabled", resourcePath);
595+
}
585596
[request setCachePolicy:NSURLRequestUseProtocolCachePolicy];
586597
}
587598
else {
588-
NSLog(@"%@ cache disabled", resourcePath);
599+
if ([[SWGConfiguration sharedConfig] debug]){
600+
NSLog(@"%@ cache disabled", resourcePath);
601+
}
589602
[request setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData];
590603
}
591604

0 commit comments

Comments
 (0)