From 3a8b149f09c721649b67447894d124d211d8e1fe Mon Sep 17 00:00:00 2001 From: geekerzp Date: Wed, 20 May 2015 15:52:00 +0800 Subject: [PATCH 1/3] minor improvement to objc api client accept and content-type header --- .../src/main/resources/objc/SWGApiClient.h | 3 + .../src/main/resources/objc/SWGApiClient.m | 38 +++++ .../src/main/resources/objc/api-body.mustache | 16 ++- .../petstore/objc/client/SWGApiClient.h | 3 + .../petstore/objc/client/SWGApiClient.m | 38 +++++ .../client/petstore/objc/client/SWGPetApi.m | 136 +++++++++++------- .../client/petstore/objc/client/SWGStoreApi.m | 64 +++++---- .../client/petstore/objc/client/SWGUserApi.m | 128 ++++++++++------- 8 files changed, 300 insertions(+), 126 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/objc/SWGApiClient.h b/modules/swagger-codegen/src/main/resources/objc/SWGApiClient.h index 300cd859778..3edada7a4c7 100644 --- a/modules/swagger-codegen/src/main/resources/objc/SWGApiClient.h +++ b/modules/swagger-codegen/src/main/resources/objc/SWGApiClient.h @@ -48,6 +48,9 @@ extern NSString *const SWGResponseObjectErrorKey; +(void) configureCacheReachibilityForHost:(NSString*)host; ++(NSString *) selectHeaderAccept:(NSArray *)headerAcceptArray; ++(NSString *) selectHeaderContentType:(NSArray *)headerContentTypeArray; + -(void)setHeaderValue:(NSString*) value forKey:(NSString*) forKey; diff --git a/modules/swagger-codegen/src/main/resources/objc/SWGApiClient.m b/modules/swagger-codegen/src/main/resources/objc/SWGApiClient.m index 6942a21c738..4547e61277a 100644 --- a/modules/swagger-codegen/src/main/resources/objc/SWGApiClient.m +++ b/modules/swagger-codegen/src/main/resources/objc/SWGApiClient.m @@ -79,6 +79,44 @@ static bool loggingEnabled = true; } } +/* + * Detect `Accept` from acceptArray + */ ++ (NSString *) selectHeaderAccept:(NSArray *)acceptArray +{ + // if acceptArray is nil or empty, return `application/json` + if (acceptArray == nil || [acceptArray count] == 0) { + return @"application/json"; + } + + // if `application/json` in acceptArray, return it + if ([acceptArray containsObject:[@"application/json" lowercaseString]]) { + return @"application/json"; + } + else { + return [acceptArray componentsJoinedByString:@", "]; + } +} + +/* + * Detect `Content-Type` from contentTypeArray + */ ++ (NSString *) selectHeaderContentType:(NSArray *)contentTypeArray +{ + // if contentTypeArray is nil or empty, return `application/json` + if (contentTypeArray == nil || [contentTypeArray count] == 0) { + return @"application/json"; + } + + // if `application/json` in contentTypeArray, return it + if ([contentTypeArray containsObject:[@"application/json" lowercaseString]]) { + return @"applications/json"; + } + else { + return contentTypeArray[0]; + } +} + -(void)setHeaderValue:(NSString*) value forKey:(NSString*) forKey { [self.requestSerializer setValue:value forHTTPHeaderField:forKey]; diff --git a/modules/swagger-codegen/src/main/resources/objc/api-body.mustache b/modules/swagger-codegen/src/main/resources/objc/api-body.mustache index 53e6895fe33..37699206f2b 100644 --- a/modules/swagger-codegen/src/main/resources/objc/api-body.mustache +++ b/modules/swagger-codegen/src/main/resources/objc/api-body.mustache @@ -78,12 +78,6 @@ static NSString * basePath = @"{{basePath}}"; {{#pathParams}}[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:[NSString stringWithFormat:@"%@%@%@", @"{", @"{{baseName}}", @"}"]] withString: [SWGApiClient escape:{{paramName}}]]; {{/pathParams}} - NSArray* requestContentTypes = @[{{#consumes}}@"{{mediaType}}"{{#hasMore}}, {{/hasMore}}{{/consumes}}]; - NSString* requestContentType = [requestContentTypes count] > 0 ? requestContentTypes[0] : @"application/json"; - - NSArray* responseContentTypes = @[{{#produces}}@"{{mediaType}}"{{#hasMore}}, {{/hasMore}}{{/produces}}]; - NSString* responseContentType = [responseContentTypes count] > 0 ? responseContentTypes[0] : @"application/json"; - NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init]; {{#queryParams}}if({{paramName}} != nil) { {{#collectionFormat}} @@ -97,6 +91,16 @@ static NSString * basePath = @"{{basePath}}"; {{#headerParams}}if({{paramName}} != nil) headerParams[@"{{baseName}}"] = {{paramName}}; {{/headerParams}} + + // HTTP header `Accept` + NSArray *headerAccept = @[{{#produces}}@"{{mediaType}}"{{#hasMore}}, {{/hasMore}}{{/produces}}]; + headerParams[@"Accept"] = [SWGApiClient selectHeaderAccept:headerAccept]; + NSString *responseContentType = [headerParams[@"Accept"] componentsSeparatedByString:@", "][0]; + + // HTTP header `Content-Type` + NSArray *headerContentType = @[{{#consumes}}@"{{mediaType}}"{{#hasMore}}, {{/hasMore}}{{/consumes}}]; + headerParams[@"Content-Type"] = [SWGApiClient selectHeaderContentType:headerContentType]; + NSString *requestContentType = headerParams[@"Content-Type"]; id bodyDictionary = nil; {{#bodyParam}} diff --git a/samples/client/petstore/objc/client/SWGApiClient.h b/samples/client/petstore/objc/client/SWGApiClient.h index 300cd859778..3edada7a4c7 100644 --- a/samples/client/petstore/objc/client/SWGApiClient.h +++ b/samples/client/petstore/objc/client/SWGApiClient.h @@ -48,6 +48,9 @@ extern NSString *const SWGResponseObjectErrorKey; +(void) configureCacheReachibilityForHost:(NSString*)host; ++(NSString *) selectHeaderAccept:(NSArray *)headerAcceptArray; ++(NSString *) selectHeaderContentType:(NSArray *)headerContentTypeArray; + -(void)setHeaderValue:(NSString*) value forKey:(NSString*) forKey; diff --git a/samples/client/petstore/objc/client/SWGApiClient.m b/samples/client/petstore/objc/client/SWGApiClient.m index 6942a21c738..4547e61277a 100644 --- a/samples/client/petstore/objc/client/SWGApiClient.m +++ b/samples/client/petstore/objc/client/SWGApiClient.m @@ -79,6 +79,44 @@ static bool loggingEnabled = true; } } +/* + * Detect `Accept` from acceptArray + */ ++ (NSString *) selectHeaderAccept:(NSArray *)acceptArray +{ + // if acceptArray is nil or empty, return `application/json` + if (acceptArray == nil || [acceptArray count] == 0) { + return @"application/json"; + } + + // if `application/json` in acceptArray, return it + if ([acceptArray containsObject:[@"application/json" lowercaseString]]) { + return @"application/json"; + } + else { + return [acceptArray componentsJoinedByString:@", "]; + } +} + +/* + * Detect `Content-Type` from contentTypeArray + */ ++ (NSString *) selectHeaderContentType:(NSArray *)contentTypeArray +{ + // if contentTypeArray is nil or empty, return `application/json` + if (contentTypeArray == nil || [contentTypeArray count] == 0) { + return @"application/json"; + } + + // if `application/json` in contentTypeArray, return it + if ([contentTypeArray containsObject:[@"application/json" lowercaseString]]) { + return @"applications/json"; + } + else { + return contentTypeArray[0]; + } +} + -(void)setHeaderValue:(NSString*) value forKey:(NSString*) forKey { [self.requestSerializer setValue:value forHTTPHeaderField:forKey]; diff --git a/samples/client/petstore/objc/client/SWGPetApi.m b/samples/client/petstore/objc/client/SWGPetApi.m index 62bc34acbee..5b34337af07 100644 --- a/samples/client/petstore/objc/client/SWGPetApi.m +++ b/samples/client/petstore/objc/client/SWGPetApi.m @@ -75,17 +75,21 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; - NSArray* requestContentTypes = @[@"application/json", @"application/xml", ]; - NSString* requestContentType = [requestContentTypes count] > 0 ? requestContentTypes[0] : @"application/json"; - - NSArray* responseContentTypes = @[@"application/json", @"application/xml"]; - NSString* responseContentType = [responseContentTypes count] > 0 ? responseContentTypes[0] : @"application/json"; - NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init]; NSMutableDictionary* headerParams = [NSMutableDictionary dictionaryWithDictionary:self.defaultHeaders]; + + // HTTP header `Accept` + NSArray *headerAccept = @[@"application/json", @"application/xml"]; + headerParams[@"Accept"] = [SWGApiClient selectHeaderAccept:headerAccept]; + NSString *responseContentType = [headerParams[@"Accept"] componentsSeparatedByString:@", "][0]; + + // HTTP header `Content-Type` + NSArray *headerContentType = @[@"application/json", @"application/xml", ]; + headerParams[@"Content-Type"] = [SWGApiClient selectHeaderContentType:headerContentType]; + NSString *requestContentType = headerParams[@"Content-Type"]; id bodyDictionary = nil; @@ -166,17 +170,21 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; - NSArray* requestContentTypes = @[@"application/json", @"application/xml", ]; - NSString* requestContentType = [requestContentTypes count] > 0 ? requestContentTypes[0] : @"application/json"; - - NSArray* responseContentTypes = @[@"application/json", @"application/xml"]; - NSString* responseContentType = [responseContentTypes count] > 0 ? responseContentTypes[0] : @"application/json"; - NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init]; NSMutableDictionary* headerParams = [NSMutableDictionary dictionaryWithDictionary:self.defaultHeaders]; + + // HTTP header `Accept` + NSArray *headerAccept = @[@"application/json", @"application/xml"]; + headerParams[@"Accept"] = [SWGApiClient selectHeaderAccept:headerAccept]; + NSString *responseContentType = [headerParams[@"Accept"] componentsSeparatedByString:@", "][0]; + + // HTTP header `Content-Type` + NSArray *headerContentType = @[@"application/json", @"application/xml", ]; + headerParams[@"Content-Type"] = [SWGApiClient selectHeaderContentType:headerContentType]; + NSString *requestContentType = headerParams[@"Content-Type"]; id bodyDictionary = nil; @@ -257,12 +265,6 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; - NSArray* requestContentTypes = @[]; - NSString* requestContentType = [requestContentTypes count] > 0 ? requestContentTypes[0] : @"application/json"; - - NSArray* responseContentTypes = @[@"application/json", @"application/xml"]; - NSString* responseContentType = [responseContentTypes count] > 0 ? responseContentTypes[0] : @"application/json"; - NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init]; if(status != nil) { @@ -274,6 +276,16 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; NSMutableDictionary* headerParams = [NSMutableDictionary dictionaryWithDictionary:self.defaultHeaders]; + + // HTTP header `Accept` + NSArray *headerAccept = @[@"application/json", @"application/xml"]; + headerParams[@"Accept"] = [SWGApiClient selectHeaderAccept:headerAccept]; + NSString *responseContentType = [headerParams[@"Accept"] componentsSeparatedByString:@", "][0]; + + // HTTP header `Content-Type` + NSArray *headerContentType = @[]; + headerParams[@"Content-Type"] = [SWGApiClient selectHeaderContentType:headerContentType]; + NSString *requestContentType = headerParams[@"Content-Type"]; id bodyDictionary = nil; @@ -344,12 +356,6 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; - NSArray* requestContentTypes = @[]; - NSString* requestContentType = [requestContentTypes count] > 0 ? requestContentTypes[0] : @"application/json"; - - NSArray* responseContentTypes = @[@"application/json", @"application/xml"]; - NSString* responseContentType = [responseContentTypes count] > 0 ? responseContentTypes[0] : @"application/json"; - NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init]; if(tags != nil) { @@ -361,6 +367,16 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; NSMutableDictionary* headerParams = [NSMutableDictionary dictionaryWithDictionary:self.defaultHeaders]; + + // HTTP header `Accept` + NSArray *headerAccept = @[@"application/json", @"application/xml"]; + headerParams[@"Accept"] = [SWGApiClient selectHeaderAccept:headerAccept]; + NSString *responseContentType = [headerParams[@"Accept"] componentsSeparatedByString:@", "][0]; + + // HTTP header `Content-Type` + NSArray *headerContentType = @[]; + headerParams[@"Content-Type"] = [SWGApiClient selectHeaderContentType:headerContentType]; + NSString *requestContentType = headerParams[@"Content-Type"]; id bodyDictionary = nil; @@ -432,17 +448,29 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; [requestUrl replaceCharactersInRange: [requestUrl rangeOfString:[NSString stringWithFormat:@"%@%@%@", @"{", @"petId", @"}"]] withString: [SWGApiClient escape:petId]]; - NSArray* requestContentTypes = @[]; - NSString* requestContentType = [requestContentTypes count] > 0 ? requestContentTypes[0] : @"application/json"; - - NSArray* responseContentTypes = @[@"application/json", @"application/xml"]; - NSString* responseContentType = [responseContentTypes count] > 0 ? responseContentTypes[0] : @"application/json"; - NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init]; NSMutableDictionary* headerParams = [NSMutableDictionary dictionaryWithDictionary:self.defaultHeaders]; + + // HTTP header `Accept` + NSArray *headerAccept = @[]; + headerParams[@"Accept"] = [SWGApiClient selectHeaderAccept:headerAccept]; + NSString *responseContentType = [headerParams[@"Accept"] componentsSeparatedByString:@", "][0]; + + // HTTP header `Content-Type` + NSArray *headerContentType = @[]; + headerParams[@"Content-Type"] = [SWGApiClient selectHeaderContentType:headerContentType]; + NSString *requestContentType = headerParams[@"Content-Type"]; + + NSLog(@"--------------------------------"); + NSLog(@"request type: %@", requestContentType); + NSLog(@"response type: %@", responseContentType); + NSLog(@"headers: %@", headerParams); + NSLog(@"--------------------------------"); + + id bodyDictionary = nil; @@ -519,17 +547,21 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; [requestUrl replaceCharactersInRange: [requestUrl rangeOfString:[NSString stringWithFormat:@"%@%@%@", @"{", @"petId", @"}"]] withString: [SWGApiClient escape:petId]]; - NSArray* requestContentTypes = @[@"application/x-www-form-urlencoded", ]; - NSString* requestContentType = [requestContentTypes count] > 0 ? requestContentTypes[0] : @"application/json"; - - NSArray* responseContentTypes = @[@"application/json", @"application/xml"]; - NSString* responseContentType = [responseContentTypes count] > 0 ? responseContentTypes[0] : @"application/json"; - NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init]; NSMutableDictionary* headerParams = [NSMutableDictionary dictionaryWithDictionary:self.defaultHeaders]; + + // HTTP header `Accept` + NSArray *headerAccept = @[@"application/json", @"application/xml"]; + headerParams[@"Accept"] = [SWGApiClient selectHeaderAccept:headerAccept]; + NSString *responseContentType = [headerParams[@"Accept"] componentsSeparatedByString:@", "][0]; + + // HTTP header `Content-Type` + NSArray *headerContentType = @[@"application/x-www-form-urlencoded", ]; + headerParams[@"Content-Type"] = [SWGApiClient selectHeaderContentType:headerContentType]; + NSString *requestContentType = headerParams[@"Content-Type"]; id bodyDictionary = nil; @@ -606,12 +638,6 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; [requestUrl replaceCharactersInRange: [requestUrl rangeOfString:[NSString stringWithFormat:@"%@%@%@", @"{", @"petId", @"}"]] withString: [SWGApiClient escape:petId]]; - NSArray* requestContentTypes = @[]; - NSString* requestContentType = [requestContentTypes count] > 0 ? requestContentTypes[0] : @"application/json"; - - NSArray* responseContentTypes = @[@"application/json", @"application/xml"]; - NSString* responseContentType = [responseContentTypes count] > 0 ? responseContentTypes[0] : @"application/json"; - NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init]; NSMutableDictionary* headerParams = [NSMutableDictionary dictionaryWithDictionary:self.defaultHeaders]; @@ -619,6 +645,16 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; if(apiKey != nil) headerParams[@"api_key"] = apiKey; + + // HTTP header `Accept` + NSArray *headerAccept = @[@"application/json", @"application/xml"]; + headerParams[@"Accept"] = [SWGApiClient selectHeaderAccept:headerAccept]; + NSString *responseContentType = [headerParams[@"Accept"] componentsSeparatedByString:@", "][0]; + + // HTTP header `Content-Type` + NSArray *headerContentType = @[]; + headerParams[@"Content-Type"] = [SWGApiClient selectHeaderContentType:headerContentType]; + NSString *requestContentType = headerParams[@"Content-Type"]; id bodyDictionary = nil; @@ -681,17 +717,21 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; [requestUrl replaceCharactersInRange: [requestUrl rangeOfString:[NSString stringWithFormat:@"%@%@%@", @"{", @"petId", @"}"]] withString: [SWGApiClient escape:petId]]; - NSArray* requestContentTypes = @[@"multipart/form-data", ]; - NSString* requestContentType = [requestContentTypes count] > 0 ? requestContentTypes[0] : @"application/json"; - - NSArray* responseContentTypes = @[@"application/json", @"application/xml"]; - NSString* responseContentType = [responseContentTypes count] > 0 ? responseContentTypes[0] : @"application/json"; - NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init]; NSMutableDictionary* headerParams = [NSMutableDictionary dictionaryWithDictionary:self.defaultHeaders]; + + // HTTP header `Accept` + NSArray *headerAccept = @[@"application/json", @"application/xml"]; + headerParams[@"Accept"] = [SWGApiClient selectHeaderAccept:headerAccept]; + NSString *responseContentType = [headerParams[@"Accept"] componentsSeparatedByString:@", "][0]; + + // HTTP header `Content-Type` + NSArray *headerContentType = @[@"multipart/form-data", ]; + headerParams[@"Content-Type"] = [SWGApiClient selectHeaderContentType:headerContentType]; + NSString *requestContentType = headerParams[@"Content-Type"]; id bodyDictionary = nil; diff --git a/samples/client/petstore/objc/client/SWGStoreApi.m b/samples/client/petstore/objc/client/SWGStoreApi.m index c50cf67c5dc..c3870cbe51f 100644 --- a/samples/client/petstore/objc/client/SWGStoreApi.m +++ b/samples/client/petstore/objc/client/SWGStoreApi.m @@ -72,17 +72,21 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; - NSArray* requestContentTypes = @[]; - NSString* requestContentType = [requestContentTypes count] > 0 ? requestContentTypes[0] : @"application/json"; - - NSArray* responseContentTypes = @[@"application/json", @"application/xml"]; - NSString* responseContentType = [responseContentTypes count] > 0 ? responseContentTypes[0] : @"application/json"; - NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init]; NSMutableDictionary* headerParams = [NSMutableDictionary dictionaryWithDictionary:self.defaultHeaders]; + + // HTTP header `Accept` + NSArray *headerAccept = @[@"application/json", @"application/xml"]; + headerParams[@"Accept"] = [SWGApiClient selectHeaderAccept:headerAccept]; + NSString *responseContentType = [headerParams[@"Accept"] componentsSeparatedByString:@", "][0]; + + // HTTP header `Content-Type` + NSArray *headerContentType = @[]; + headerParams[@"Content-Type"] = [SWGApiClient selectHeaderContentType:headerContentType]; + NSString *requestContentType = headerParams[@"Content-Type"]; id bodyDictionary = nil; @@ -146,17 +150,21 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; - NSArray* requestContentTypes = @[]; - NSString* requestContentType = [requestContentTypes count] > 0 ? requestContentTypes[0] : @"application/json"; - - NSArray* responseContentTypes = @[@"application/json", @"application/xml"]; - NSString* responseContentType = [responseContentTypes count] > 0 ? responseContentTypes[0] : @"application/json"; - NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init]; NSMutableDictionary* headerParams = [NSMutableDictionary dictionaryWithDictionary:self.defaultHeaders]; + + // HTTP header `Accept` + NSArray *headerAccept = @[@"application/json", @"application/xml"]; + headerParams[@"Accept"] = [SWGApiClient selectHeaderAccept:headerAccept]; + NSString *responseContentType = [headerParams[@"Accept"] componentsSeparatedByString:@", "][0]; + + // HTTP header `Content-Type` + NSArray *headerContentType = @[]; + headerParams[@"Content-Type"] = [SWGApiClient selectHeaderContentType:headerContentType]; + NSString *requestContentType = headerParams[@"Content-Type"]; id bodyDictionary = nil; @@ -252,17 +260,21 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; [requestUrl replaceCharactersInRange: [requestUrl rangeOfString:[NSString stringWithFormat:@"%@%@%@", @"{", @"orderId", @"}"]] withString: [SWGApiClient escape:orderId]]; - NSArray* requestContentTypes = @[]; - NSString* requestContentType = [requestContentTypes count] > 0 ? requestContentTypes[0] : @"application/json"; - - NSArray* responseContentTypes = @[@"application/json", @"application/xml"]; - NSString* responseContentType = [responseContentTypes count] > 0 ? responseContentTypes[0] : @"application/json"; - NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init]; NSMutableDictionary* headerParams = [NSMutableDictionary dictionaryWithDictionary:self.defaultHeaders]; + + // HTTP header `Accept` + NSArray *headerAccept = @[@"application/json", @"application/xml"]; + headerParams[@"Accept"] = [SWGApiClient selectHeaderAccept:headerAccept]; + NSString *responseContentType = [headerParams[@"Accept"] componentsSeparatedByString:@", "][0]; + + // HTTP header `Content-Type` + NSArray *headerContentType = @[]; + headerParams[@"Content-Type"] = [SWGApiClient selectHeaderContentType:headerContentType]; + NSString *requestContentType = headerParams[@"Content-Type"]; id bodyDictionary = nil; @@ -335,17 +347,21 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; [requestUrl replaceCharactersInRange: [requestUrl rangeOfString:[NSString stringWithFormat:@"%@%@%@", @"{", @"orderId", @"}"]] withString: [SWGApiClient escape:orderId]]; - NSArray* requestContentTypes = @[]; - NSString* requestContentType = [requestContentTypes count] > 0 ? requestContentTypes[0] : @"application/json"; - - NSArray* responseContentTypes = @[@"application/json", @"application/xml"]; - NSString* responseContentType = [responseContentTypes count] > 0 ? responseContentTypes[0] : @"application/json"; - NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init]; NSMutableDictionary* headerParams = [NSMutableDictionary dictionaryWithDictionary:self.defaultHeaders]; + + // HTTP header `Accept` + NSArray *headerAccept = @[@"application/json", @"application/xml"]; + headerParams[@"Accept"] = [SWGApiClient selectHeaderAccept:headerAccept]; + NSString *responseContentType = [headerParams[@"Accept"] componentsSeparatedByString:@", "][0]; + + // HTTP header `Content-Type` + NSArray *headerContentType = @[]; + headerParams[@"Content-Type"] = [SWGApiClient selectHeaderContentType:headerContentType]; + NSString *requestContentType = headerParams[@"Content-Type"]; id bodyDictionary = nil; diff --git a/samples/client/petstore/objc/client/SWGUserApi.m b/samples/client/petstore/objc/client/SWGUserApi.m index 1316cebd07c..13c37b80023 100644 --- a/samples/client/petstore/objc/client/SWGUserApi.m +++ b/samples/client/petstore/objc/client/SWGUserApi.m @@ -74,17 +74,21 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; - NSArray* requestContentTypes = @[]; - NSString* requestContentType = [requestContentTypes count] > 0 ? requestContentTypes[0] : @"application/json"; - - NSArray* responseContentTypes = @[@"application/json", @"application/xml"]; - NSString* responseContentType = [responseContentTypes count] > 0 ? responseContentTypes[0] : @"application/json"; - NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init]; NSMutableDictionary* headerParams = [NSMutableDictionary dictionaryWithDictionary:self.defaultHeaders]; + + // HTTP header `Accept` + NSArray *headerAccept = @[@"application/json", @"application/xml"]; + headerParams[@"Accept"] = [SWGApiClient selectHeaderAccept:headerAccept]; + NSString *responseContentType = [headerParams[@"Accept"] componentsSeparatedByString:@", "][0]; + + // HTTP header `Content-Type` + NSArray *headerContentType = @[]; + headerParams[@"Content-Type"] = [SWGApiClient selectHeaderContentType:headerContentType]; + NSString *requestContentType = headerParams[@"Content-Type"]; id bodyDictionary = nil; @@ -165,17 +169,21 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; - NSArray* requestContentTypes = @[]; - NSString* requestContentType = [requestContentTypes count] > 0 ? requestContentTypes[0] : @"application/json"; - - NSArray* responseContentTypes = @[@"application/json", @"application/xml"]; - NSString* responseContentType = [responseContentTypes count] > 0 ? responseContentTypes[0] : @"application/json"; - NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init]; NSMutableDictionary* headerParams = [NSMutableDictionary dictionaryWithDictionary:self.defaultHeaders]; + + // HTTP header `Accept` + NSArray *headerAccept = @[@"application/json", @"application/xml"]; + headerParams[@"Accept"] = [SWGApiClient selectHeaderAccept:headerAccept]; + NSString *responseContentType = [headerParams[@"Accept"] componentsSeparatedByString:@", "][0]; + + // HTTP header `Content-Type` + NSArray *headerContentType = @[]; + headerParams[@"Content-Type"] = [SWGApiClient selectHeaderContentType:headerContentType]; + NSString *requestContentType = headerParams[@"Content-Type"]; id bodyDictionary = nil; @@ -256,17 +264,21 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; - NSArray* requestContentTypes = @[]; - NSString* requestContentType = [requestContentTypes count] > 0 ? requestContentTypes[0] : @"application/json"; - - NSArray* responseContentTypes = @[@"application/json", @"application/xml"]; - NSString* responseContentType = [responseContentTypes count] > 0 ? responseContentTypes[0] : @"application/json"; - NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init]; NSMutableDictionary* headerParams = [NSMutableDictionary dictionaryWithDictionary:self.defaultHeaders]; + + // HTTP header `Accept` + NSArray *headerAccept = @[@"application/json", @"application/xml"]; + headerParams[@"Accept"] = [SWGApiClient selectHeaderAccept:headerAccept]; + NSString *responseContentType = [headerParams[@"Accept"] componentsSeparatedByString:@", "][0]; + + // HTTP header `Content-Type` + NSArray *headerContentType = @[]; + headerParams[@"Content-Type"] = [SWGApiClient selectHeaderContentType:headerContentType]; + NSString *requestContentType = headerParams[@"Content-Type"]; id bodyDictionary = nil; @@ -349,12 +361,6 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; - NSArray* requestContentTypes = @[]; - NSString* requestContentType = [requestContentTypes count] > 0 ? requestContentTypes[0] : @"application/json"; - - NSArray* responseContentTypes = @[@"application/json", @"application/xml"]; - NSString* responseContentType = [responseContentTypes count] > 0 ? responseContentTypes[0] : @"application/json"; - NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init]; if(username != nil) { @@ -368,6 +374,16 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; NSMutableDictionary* headerParams = [NSMutableDictionary dictionaryWithDictionary:self.defaultHeaders]; + + // HTTP header `Accept` + NSArray *headerAccept = @[@"application/json", @"application/xml"]; + headerParams[@"Accept"] = [SWGApiClient selectHeaderAccept:headerAccept]; + NSString *responseContentType = [headerParams[@"Accept"] componentsSeparatedByString:@", "][0]; + + // HTTP header `Content-Type` + NSArray *headerContentType = @[]; + headerParams[@"Content-Type"] = [SWGApiClient selectHeaderContentType:headerContentType]; + NSString *requestContentType = headerParams[@"Content-Type"]; id bodyDictionary = nil; @@ -435,17 +451,21 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; - NSArray* requestContentTypes = @[]; - NSString* requestContentType = [requestContentTypes count] > 0 ? requestContentTypes[0] : @"application/json"; - - NSArray* responseContentTypes = @[@"application/json", @"application/xml"]; - NSString* responseContentType = [responseContentTypes count] > 0 ? responseContentTypes[0] : @"application/json"; - NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init]; NSMutableDictionary* headerParams = [NSMutableDictionary dictionaryWithDictionary:self.defaultHeaders]; + + // HTTP header `Accept` + NSArray *headerAccept = @[@"application/json", @"application/xml"]; + headerParams[@"Accept"] = [SWGApiClient selectHeaderAccept:headerAccept]; + NSString *responseContentType = [headerParams[@"Accept"] componentsSeparatedByString:@", "][0]; + + // HTTP header `Content-Type` + NSArray *headerContentType = @[]; + headerParams[@"Content-Type"] = [SWGApiClient selectHeaderContentType:headerContentType]; + NSString *requestContentType = headerParams[@"Content-Type"]; id bodyDictionary = nil; @@ -504,17 +524,21 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; [requestUrl replaceCharactersInRange: [requestUrl rangeOfString:[NSString stringWithFormat:@"%@%@%@", @"{", @"username", @"}"]] withString: [SWGApiClient escape:username]]; - NSArray* requestContentTypes = @[]; - NSString* requestContentType = [requestContentTypes count] > 0 ? requestContentTypes[0] : @"application/json"; - - NSArray* responseContentTypes = @[@"application/json", @"application/xml"]; - NSString* responseContentType = [responseContentTypes count] > 0 ? responseContentTypes[0] : @"application/json"; - NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init]; NSMutableDictionary* headerParams = [NSMutableDictionary dictionaryWithDictionary:self.defaultHeaders]; + + // HTTP header `Accept` + NSArray *headerAccept = @[@"application/json", @"application/xml"]; + headerParams[@"Accept"] = [SWGApiClient selectHeaderAccept:headerAccept]; + NSString *responseContentType = [headerParams[@"Accept"] componentsSeparatedByString:@", "][0]; + + // HTTP header `Content-Type` + NSArray *headerContentType = @[]; + headerParams[@"Content-Type"] = [SWGApiClient selectHeaderContentType:headerContentType]; + NSString *requestContentType = headerParams[@"Content-Type"]; id bodyDictionary = nil; @@ -589,17 +613,21 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; [requestUrl replaceCharactersInRange: [requestUrl rangeOfString:[NSString stringWithFormat:@"%@%@%@", @"{", @"username", @"}"]] withString: [SWGApiClient escape:username]]; - NSArray* requestContentTypes = @[]; - NSString* requestContentType = [requestContentTypes count] > 0 ? requestContentTypes[0] : @"application/json"; - - NSArray* responseContentTypes = @[@"application/json", @"application/xml"]; - NSString* responseContentType = [responseContentTypes count] > 0 ? responseContentTypes[0] : @"application/json"; - NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init]; NSMutableDictionary* headerParams = [NSMutableDictionary dictionaryWithDictionary:self.defaultHeaders]; + + // HTTP header `Accept` + NSArray *headerAccept = @[@"application/json", @"application/xml"]; + headerParams[@"Accept"] = [SWGApiClient selectHeaderAccept:headerAccept]; + NSString *responseContentType = [headerParams[@"Accept"] componentsSeparatedByString:@", "][0]; + + // HTTP header `Content-Type` + NSArray *headerContentType = @[]; + headerParams[@"Content-Type"] = [SWGApiClient selectHeaderContentType:headerContentType]; + NSString *requestContentType = headerParams[@"Content-Type"]; id bodyDictionary = nil; @@ -681,17 +709,21 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; [requestUrl replaceCharactersInRange: [requestUrl rangeOfString:[NSString stringWithFormat:@"%@%@%@", @"{", @"username", @"}"]] withString: [SWGApiClient escape:username]]; - NSArray* requestContentTypes = @[]; - NSString* requestContentType = [requestContentTypes count] > 0 ? requestContentTypes[0] : @"application/json"; - - NSArray* responseContentTypes = @[@"application/json", @"application/xml"]; - NSString* responseContentType = [responseContentTypes count] > 0 ? responseContentTypes[0] : @"application/json"; - NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init]; NSMutableDictionary* headerParams = [NSMutableDictionary dictionaryWithDictionary:self.defaultHeaders]; + + // HTTP header `Accept` + NSArray *headerAccept = @[@"application/json", @"application/xml"]; + headerParams[@"Accept"] = [SWGApiClient selectHeaderAccept:headerAccept]; + NSString *responseContentType = [headerParams[@"Accept"] componentsSeparatedByString:@", "][0]; + + // HTTP header `Content-Type` + NSArray *headerContentType = @[]; + headerParams[@"Content-Type"] = [SWGApiClient selectHeaderContentType:headerContentType]; + NSString *requestContentType = headerParams[@"Content-Type"]; id bodyDictionary = nil; From 3d3cbe115ef0418c3f9ff5cd22b44bcf02630969 Mon Sep 17 00:00:00 2001 From: geekerzp Date: Sat, 23 May 2015 15:22:12 +0800 Subject: [PATCH 2/3] minor improvement to objc client accept and content-type header --- .../src/main/resources/objc/SWGApiClient.m | 49 ++-- .../src/main/resources/objc/api-body.mustache | 22 +- .../PetstoreClient.xcodeproj/project.pbxproj | 4 + .../PetstoreClientTests/SWGApiClientTest.m | 59 +++++ samples/client/petstore/objc/Podfile.lock | 30 +-- .../petstore/objc/client/SWGApiClient.m | 49 ++-- .../client/petstore/objc/client/SWGPetApi.m | 209 ++++++++++-------- .../client/petstore/objc/client/SWGStoreApi.m | 88 +++++--- .../client/petstore/objc/client/SWGUserApi.m | 176 ++++++++++----- 9 files changed, 448 insertions(+), 238 deletions(-) create mode 100644 samples/client/petstore/objc/PetstoreClient/PetstoreClientTests/SWGApiClientTest.m diff --git a/modules/swagger-codegen/src/main/resources/objc/SWGApiClient.m b/modules/swagger-codegen/src/main/resources/objc/SWGApiClient.m index 4547e61277a..15dbee07459 100644 --- a/modules/swagger-codegen/src/main/resources/objc/SWGApiClient.m +++ b/modules/swagger-codegen/src/main/resources/objc/SWGApiClient.m @@ -80,41 +80,48 @@ static bool loggingEnabled = true; } /* - * Detect `Accept` from acceptArray + * Detect `Accept` from accepts */ -+ (NSString *) selectHeaderAccept:(NSArray *)acceptArray ++ (NSString *) selectHeaderAccept:(NSArray *)accepts { - // if acceptArray is nil or empty, return `application/json` - if (acceptArray == nil || [acceptArray count] == 0) { - return @"application/json"; + if (accepts == nil || [accepts count] == 0) { + return @""; } + + NSMutableArray *lowerAccepts = [[NSMutableArray alloc] initWithCapacity:[accepts count]]; + [accepts enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { + [lowerAccepts addObject:[obj lowercaseString]]; + }]; - // if `application/json` in acceptArray, return it - if ([acceptArray containsObject:[@"application/json" lowercaseString]]) { + + if ([lowerAccepts containsObject:@"application/json"]) { return @"application/json"; } else { - return [acceptArray componentsJoinedByString:@", "]; + return [lowerAccepts componentsJoinedByString:@", "]; } } /* - * Detect `Content-Type` from contentTypeArray + * Detect `Content-Type` from contentTypes */ -+ (NSString *) selectHeaderContentType:(NSArray *)contentTypeArray ++ (NSString *) selectHeaderContentType:(NSArray *)contentTypes { - // if contentTypeArray is nil or empty, return `application/json` - if (contentTypeArray == nil || [contentTypeArray count] == 0) { - return @"application/json"; - } + if (contentTypes == nil || [contentTypes count] == 0) { + return @"application/json"; + } + + NSMutableArray *lowerContentTypes = [[NSMutableArray alloc] initWithCapacity:[contentTypes count]]; + [contentTypes enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { + [lowerContentTypes addObject:[obj lowercaseString]]; + }]; - // if `application/json` in contentTypeArray, return it - if ([contentTypeArray containsObject:[@"application/json" lowercaseString]]) { - return @"applications/json"; - } - else { - return contentTypeArray[0]; - } + if ([lowerContentTypes containsObject:@"application/json"]) { + return @"application/json"; + } + else { + return lowerContentTypes[0]; + } } -(void)setHeaderValue:(NSString*) value diff --git a/modules/swagger-codegen/src/main/resources/objc/api-body.mustache b/modules/swagger-codegen/src/main/resources/objc/api-body.mustache index 34e20e36f9a..b18790e3b6f 100644 --- a/modules/swagger-codegen/src/main/resources/objc/api-body.mustache +++ b/modules/swagger-codegen/src/main/resources/objc/api-body.mustache @@ -98,14 +98,22 @@ static NSString * basePath = @"{{basePath}}"; {{/headerParams}} // HTTP header `Accept` - NSArray *headerAccept = @[{{#produces}}@"{{mediaType}}"{{#hasMore}}, {{/hasMore}}{{/produces}}]; - headerParams[@"Accept"] = [SWGApiClient selectHeaderAccept:headerAccept]; - NSString *responseContentType = [headerParams[@"Accept"] componentsSeparatedByString:@", "][0]; + headerParams[@"Accept"] = [SWGApiClient selectHeaderAccept:@[{{#produces}}@"{{mediaType}}"{{#hasMore}}, {{/hasMore}}{{/produces}}]]; + if ([headerParams[@"Accept"] length] == 0) { + [headerParams removeObjectForKey:@"Accept"]; + } - // HTTP header `Content-Type` - NSArray *headerContentType = @[{{#consumes}}@"{{mediaType}}"{{#hasMore}}, {{/hasMore}}{{/consumes}}]; - headerParams[@"Content-Type"] = [SWGApiClient selectHeaderContentType:headerContentType]; - NSString *requestContentType = headerParams[@"Content-Type"]; + // response content type + NSString *responseContentType; + if ([headerParams objectForKey:@"Accept"]) { + responseContentType = [headerParams[@"Accept"] componentsSeparatedByString:@", "][0]; + } + else { + responseContentType = @""; + } + + // request content type + NSString *requestContentType = [SWGApiClient selectHeaderContentType:@[{{#consumes}}@"{{mediaType}}"{{#hasMore}}, {{/hasMore}}{{/consumes}}]]; id bodyDictionary = nil; {{#bodyParam}} diff --git a/samples/client/petstore/objc/PetstoreClient/PetstoreClient.xcodeproj/project.pbxproj b/samples/client/petstore/objc/PetstoreClient/PetstoreClient.xcodeproj/project.pbxproj index a3f7b4cae6b..723caec2cdb 100644 --- a/samples/client/petstore/objc/PetstoreClient/PetstoreClient.xcodeproj/project.pbxproj +++ b/samples/client/petstore/objc/PetstoreClient/PetstoreClient.xcodeproj/project.pbxproj @@ -8,6 +8,7 @@ /* Begin PBXBuildFile section */ BA525648922D4C0E9F44D4F1 /* libPods.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 73DA4F1067C343C3962F1542 /* libPods.a */; }; + CF31D0991B105E4B00509935 /* SWGApiClientTest.m in Sources */ = {isa = PBXBuildFile; fileRef = CF31D0981B105E4B00509935 /* SWGApiClientTest.m */; }; CFD1B6701B05EC7D00DCCD51 /* JSONValueTransformer+ISO8601.m in Sources */ = {isa = PBXBuildFile; fileRef = CFD1B66F1B05EC7D00DCCD51 /* JSONValueTransformer+ISO8601.m */; }; CFD1B6711B05EC7D00DCCD51 /* JSONValueTransformer+ISO8601.m in Sources */ = {isa = PBXBuildFile; fileRef = CFD1B66F1B05EC7D00DCCD51 /* JSONValueTransformer+ISO8601.m */; }; EA66999A1811D2FA00A70D03 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EA6699991811D2FA00A70D03 /* Foundation.framework */; }; @@ -55,6 +56,7 @@ /* Begin PBXFileReference section */ 73DA4F1067C343C3962F1542 /* libPods.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libPods.a; sourceTree = BUILT_PRODUCTS_DIR; }; A425648B5C0A4849C7668069 /* Pods.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.release.xcconfig; path = "../Pods/Target Support Files/Pods/Pods.release.xcconfig"; sourceTree = ""; }; + CF31D0981B105E4B00509935 /* SWGApiClientTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SWGApiClientTest.m; sourceTree = ""; }; CFD1B66E1B05EC7D00DCCD51 /* JSONValueTransformer+ISO8601.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "JSONValueTransformer+ISO8601.h"; sourceTree = ""; }; CFD1B66F1B05EC7D00DCCD51 /* JSONValueTransformer+ISO8601.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "JSONValueTransformer+ISO8601.m"; sourceTree = ""; }; E2B6DA00BE52336E23783686 /* Pods.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.debug.xcconfig; path = "../Pods/Target Support Files/Pods/Pods.debug.xcconfig"; sourceTree = ""; }; @@ -207,6 +209,7 @@ isa = PBXGroup; children = ( EA8CD3EB1AC274BE00C47D0B /* PetApiTest.h */, + CF31D0981B105E4B00509935 /* SWGApiClientTest.m */, EA6699C71811D2FB00A70D03 /* PetApiTest.m */, EA6699C21811D2FB00A70D03 /* Supporting Files */, ); @@ -417,6 +420,7 @@ EAB26B0C1AC8DF78002F5C7A /* PetApiTest.h in Sources */, CFD1B6711B05EC7D00DCCD51 /* JSONValueTransformer+ISO8601.m in Sources */, EAB26B0D1AC8DF78002F5C7A /* PetApiTest.m in Sources */, + CF31D0991B105E4B00509935 /* SWGApiClientTest.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/samples/client/petstore/objc/PetstoreClient/PetstoreClientTests/SWGApiClientTest.m b/samples/client/petstore/objc/PetstoreClient/PetstoreClientTests/SWGApiClientTest.m new file mode 100644 index 00000000000..0464bf569e9 --- /dev/null +++ b/samples/client/petstore/objc/PetstoreClient/PetstoreClientTests/SWGApiClientTest.m @@ -0,0 +1,59 @@ +#import +#import +#import "SWGApiClient.h" + +@interface SWGApiClientTest : XCTestCase + +@end + +@implementation SWGApiClientTest + +- (void)setUp { + [super setUp]; + // Put setup code here. This method is called before the invocation of each test method in the class. +} + +- (void)tearDown { + // Put teardown code here. This method is called after the invocation of each test method in the class. + [super tearDown]; +} + +- (void)testSelectHeaderAccept { + NSArray *accepts = nil; + + accepts = @[@"APPLICATION/JSON", @"APPLICATION/XML"]; + XCTAssertEqualObjects([SWGApiClient selectHeaderAccept:accepts], @"application/json"); + + accepts = @[@"application/json", @"application/xml"]; + XCTAssertEqualObjects([SWGApiClient selectHeaderAccept:accepts], @"application/json"); + + accepts = @[@"APPLICATION/xml", @"APPLICATION/json"]; + XCTAssertEqualObjects([SWGApiClient selectHeaderAccept:accepts], @"application/json"); + + accepts = @[@"text/plain", @"application/xml"]; + XCTAssertEqualObjects([SWGApiClient selectHeaderAccept:accepts], @"text/plain, application/xml"); + + accepts = @[]; + XCTAssertEqualObjects([SWGApiClient selectHeaderAccept:accepts], @""); +} + +- (void)testSelectHeaderContentType { + NSArray *contentTypes = nil; + + contentTypes = @[@"APPLICATION/JSON", @"APPLICATION/XML"]; + XCTAssertEqualObjects([SWGApiClient selectHeaderContentType:contentTypes], @"application/json"); + + contentTypes = @[@"application/json", @"application/xml"]; + XCTAssertEqualObjects([SWGApiClient selectHeaderContentType:contentTypes], @"application/json"); + + contentTypes = @[@"APPLICATION/xml", @"APPLICATION/json"]; + XCTAssertEqualObjects([SWGApiClient selectHeaderContentType:contentTypes], @"application/json"); + + contentTypes = @[@"text/plain", @"application/xml"]; + XCTAssertEqualObjects([SWGApiClient selectHeaderContentType:contentTypes], @"text/plain"); + + contentTypes = @[]; + XCTAssertEqualObjects([SWGApiClient selectHeaderContentType:contentTypes], @"application/json"); +} + +@end diff --git a/samples/client/petstore/objc/Podfile.lock b/samples/client/petstore/objc/Podfile.lock index fe43a2c80eb..6ac776ab37a 100644 --- a/samples/client/petstore/objc/Podfile.lock +++ b/samples/client/petstore/objc/Podfile.lock @@ -1,23 +1,23 @@ PODS: - - AFNetworking (2.5.3): - - AFNetworking/NSURLConnection (= 2.5.3) - - AFNetworking/NSURLSession (= 2.5.3) - - AFNetworking/Reachability (= 2.5.3) - - AFNetworking/Security (= 2.5.3) - - AFNetworking/Serialization (= 2.5.3) - - AFNetworking/UIKit (= 2.5.3) - - AFNetworking/NSURLConnection (2.5.3): + - AFNetworking (2.5.4): + - AFNetworking/NSURLConnection (= 2.5.4) + - AFNetworking/NSURLSession (= 2.5.4) + - AFNetworking/Reachability (= 2.5.4) + - AFNetworking/Security (= 2.5.4) + - AFNetworking/Serialization (= 2.5.4) + - AFNetworking/UIKit (= 2.5.4) + - AFNetworking/NSURLConnection (2.5.4): - AFNetworking/Reachability - AFNetworking/Security - AFNetworking/Serialization - - AFNetworking/NSURLSession (2.5.3): + - AFNetworking/NSURLSession (2.5.4): - AFNetworking/Reachability - AFNetworking/Security - AFNetworking/Serialization - - AFNetworking/Reachability (2.5.3) - - AFNetworking/Security (2.5.3) - - AFNetworking/Serialization (2.5.3) - - AFNetworking/UIKit (2.5.3): + - AFNetworking/Reachability (2.5.4) + - AFNetworking/Security (2.5.4) + - AFNetworking/Serialization (2.5.4) + - AFNetworking/UIKit (2.5.4): - AFNetworking/NSURLConnection - AFNetworking/NSURLSession - ISO8601 (0.2.0) @@ -29,8 +29,8 @@ DEPENDENCIES: - JSONModel (~> 1.0) SPEC CHECKSUMS: - AFNetworking: e1d86c2a96bb5d2e7408da36149806706ee122fe + AFNetworking: 05edc0ac4c4c8cf57bcf4b84be5b0744b6d8e71e ISO8601: 962282de75074c38bbfaa7b133b0e743ed6deb8d JSONModel: ec77e9865236a7a09d9cf7668df6b4b328d9ec1d -COCOAPODS: 0.36.0 +COCOAPODS: 0.37.1 diff --git a/samples/client/petstore/objc/client/SWGApiClient.m b/samples/client/petstore/objc/client/SWGApiClient.m index 4547e61277a..15dbee07459 100644 --- a/samples/client/petstore/objc/client/SWGApiClient.m +++ b/samples/client/petstore/objc/client/SWGApiClient.m @@ -80,41 +80,48 @@ static bool loggingEnabled = true; } /* - * Detect `Accept` from acceptArray + * Detect `Accept` from accepts */ -+ (NSString *) selectHeaderAccept:(NSArray *)acceptArray ++ (NSString *) selectHeaderAccept:(NSArray *)accepts { - // if acceptArray is nil or empty, return `application/json` - if (acceptArray == nil || [acceptArray count] == 0) { - return @"application/json"; + if (accepts == nil || [accepts count] == 0) { + return @""; } + + NSMutableArray *lowerAccepts = [[NSMutableArray alloc] initWithCapacity:[accepts count]]; + [accepts enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { + [lowerAccepts addObject:[obj lowercaseString]]; + }]; - // if `application/json` in acceptArray, return it - if ([acceptArray containsObject:[@"application/json" lowercaseString]]) { + + if ([lowerAccepts containsObject:@"application/json"]) { return @"application/json"; } else { - return [acceptArray componentsJoinedByString:@", "]; + return [lowerAccepts componentsJoinedByString:@", "]; } } /* - * Detect `Content-Type` from contentTypeArray + * Detect `Content-Type` from contentTypes */ -+ (NSString *) selectHeaderContentType:(NSArray *)contentTypeArray ++ (NSString *) selectHeaderContentType:(NSArray *)contentTypes { - // if contentTypeArray is nil or empty, return `application/json` - if (contentTypeArray == nil || [contentTypeArray count] == 0) { - return @"application/json"; - } + if (contentTypes == nil || [contentTypes count] == 0) { + return @"application/json"; + } + + NSMutableArray *lowerContentTypes = [[NSMutableArray alloc] initWithCapacity:[contentTypes count]]; + [contentTypes enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { + [lowerContentTypes addObject:[obj lowercaseString]]; + }]; - // if `application/json` in contentTypeArray, return it - if ([contentTypeArray containsObject:[@"application/json" lowercaseString]]) { - return @"applications/json"; - } - else { - return contentTypeArray[0]; - } + if ([lowerContentTypes containsObject:@"application/json"]) { + return @"application/json"; + } + else { + return lowerContentTypes[0]; + } } -(void)setHeaderValue:(NSString*) value diff --git a/samples/client/petstore/objc/client/SWGPetApi.m b/samples/client/petstore/objc/client/SWGPetApi.m index 2589241dbe4..9f2b79c51f8 100644 --- a/samples/client/petstore/objc/client/SWGPetApi.m +++ b/samples/client/petstore/objc/client/SWGPetApi.m @@ -84,14 +84,22 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; // HTTP header `Accept` - NSArray *headerAccept = @[@"application/json", @"application/xml"]; - headerParams[@"Accept"] = [SWGApiClient selectHeaderAccept:headerAccept]; - NSString *responseContentType = [headerParams[@"Accept"] componentsSeparatedByString:@", "][0]; + headerParams[@"Accept"] = [SWGApiClient selectHeaderAccept:@[@"application/json", @"application/xml"]]; + if ([headerParams[@"Accept"] length] == 0) { + [headerParams removeObjectForKey:@"Accept"]; + } - // HTTP header `Content-Type` - NSArray *headerContentType = @[@"application/json", @"application/xml", ]; - headerParams[@"Content-Type"] = [SWGApiClient selectHeaderContentType:headerContentType]; - NSString *requestContentType = headerParams[@"Content-Type"]; + // response content type + NSString *responseContentType; + if ([headerParams objectForKey:@"Accept"]) { + responseContentType = [headerParams[@"Accept"] componentsSeparatedByString:@", "][0]; + } + else { + responseContentType = @""; + } + + // request content type + NSString *requestContentType = [SWGApiClient selectHeaderContentType:@[@"application/json", @"application/xml"]]; id bodyDictionary = nil; @@ -174,15 +182,6 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; -<<<<<<< HEAD -======= - NSArray* requestContentTypes = @[@"application/json", @"application/xml"]; - NSString* requestContentType = [requestContentTypes count] > 0 ? requestContentTypes[0] : @"application/json"; - - NSArray* responseContentTypes = @[@"application/json", @"application/xml"]; - NSString* responseContentType = [responseContentTypes count] > 0 ? responseContentTypes[0] : @"application/json"; - ->>>>>>> develop_2.0 NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init]; NSMutableDictionary* headerParams = [NSMutableDictionary dictionaryWithDictionary:self.defaultHeaders]; @@ -190,14 +189,22 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; // HTTP header `Accept` - NSArray *headerAccept = @[@"application/json", @"application/xml"]; - headerParams[@"Accept"] = [SWGApiClient selectHeaderAccept:headerAccept]; - NSString *responseContentType = [headerParams[@"Accept"] componentsSeparatedByString:@", "][0]; + headerParams[@"Accept"] = [SWGApiClient selectHeaderAccept:@[@"application/json", @"application/xml"]]; + if ([headerParams[@"Accept"] length] == 0) { + [headerParams removeObjectForKey:@"Accept"]; + } - // HTTP header `Content-Type` - NSArray *headerContentType = @[@"application/json", @"application/xml", ]; - headerParams[@"Content-Type"] = [SWGApiClient selectHeaderContentType:headerContentType]; - NSString *requestContentType = headerParams[@"Content-Type"]; + // response content type + NSString *responseContentType; + if ([headerParams objectForKey:@"Accept"]) { + responseContentType = [headerParams[@"Accept"] componentsSeparatedByString:@", "][0]; + } + else { + responseContentType = @""; + } + + // request content type + NSString *requestContentType = [SWGApiClient selectHeaderContentType:@[@"application/json", @"application/xml"]]; id bodyDictionary = nil; @@ -293,14 +300,22 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; // HTTP header `Accept` - NSArray *headerAccept = @[@"application/json", @"application/xml"]; - headerParams[@"Accept"] = [SWGApiClient selectHeaderAccept:headerAccept]; - NSString *responseContentType = [headerParams[@"Accept"] componentsSeparatedByString:@", "][0]; + headerParams[@"Accept"] = [SWGApiClient selectHeaderAccept:@[@"application/json", @"application/xml"]]; + if ([headerParams[@"Accept"] length] == 0) { + [headerParams removeObjectForKey:@"Accept"]; + } - // HTTP header `Content-Type` - NSArray *headerContentType = @[]; - headerParams[@"Content-Type"] = [SWGApiClient selectHeaderContentType:headerContentType]; - NSString *requestContentType = headerParams[@"Content-Type"]; + // response content type + NSString *responseContentType; + if ([headerParams objectForKey:@"Accept"]) { + responseContentType = [headerParams[@"Accept"] componentsSeparatedByString:@", "][0]; + } + else { + responseContentType = @""; + } + + // request content type + NSString *requestContentType = [SWGApiClient selectHeaderContentType:@[]]; id bodyDictionary = nil; @@ -386,14 +401,22 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; // HTTP header `Accept` - NSArray *headerAccept = @[@"application/json", @"application/xml"]; - headerParams[@"Accept"] = [SWGApiClient selectHeaderAccept:headerAccept]; - NSString *responseContentType = [headerParams[@"Accept"] componentsSeparatedByString:@", "][0]; + headerParams[@"Accept"] = [SWGApiClient selectHeaderAccept:@[@"application/json", @"application/xml"]]; + if ([headerParams[@"Accept"] length] == 0) { + [headerParams removeObjectForKey:@"Accept"]; + } - // HTTP header `Content-Type` - NSArray *headerContentType = @[]; - headerParams[@"Content-Type"] = [SWGApiClient selectHeaderContentType:headerContentType]; - NSString *requestContentType = headerParams[@"Content-Type"]; + // response content type + NSString *responseContentType; + if ([headerParams objectForKey:@"Accept"]) { + responseContentType = [headerParams[@"Accept"] componentsSeparatedByString:@", "][0]; + } + else { + responseContentType = @""; + } + + // request content type + NSString *requestContentType = [SWGApiClient selectHeaderContentType:@[]]; id bodyDictionary = nil; @@ -477,22 +500,22 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; // HTTP header `Accept` - NSArray *headerAccept = @[]; - headerParams[@"Accept"] = [SWGApiClient selectHeaderAccept:headerAccept]; - NSString *responseContentType = [headerParams[@"Accept"] componentsSeparatedByString:@", "][0]; - - // HTTP header `Content-Type` - NSArray *headerContentType = @[]; - headerParams[@"Content-Type"] = [SWGApiClient selectHeaderContentType:headerContentType]; - NSString *requestContentType = headerParams[@"Content-Type"]; - - NSLog(@"--------------------------------"); - NSLog(@"request type: %@", requestContentType); - NSLog(@"response type: %@", responseContentType); - NSLog(@"headers: %@", headerParams); - NSLog(@"--------------------------------"); + headerParams[@"Accept"] = [SWGApiClient selectHeaderAccept:@[@"application/json", @"application/xml"]]; + if ([headerParams[@"Accept"] length] == 0) { + [headerParams removeObjectForKey:@"Accept"]; + } + // response content type + NSString *responseContentType; + if ([headerParams objectForKey:@"Accept"]) { + responseContentType = [headerParams[@"Accept"] componentsSeparatedByString:@", "][0]; + } + else { + responseContentType = @""; + } + // request content type + NSString *requestContentType = [SWGApiClient selectHeaderContentType:@[]]; id bodyDictionary = nil; @@ -574,15 +597,6 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; [requestUrl replaceCharactersInRange: [requestUrl rangeOfString:[NSString stringWithFormat:@"%@%@%@", @"{", @"petId", @"}"]] withString: [SWGApiClient escape:petId]]; -<<<<<<< HEAD -======= - NSArray* requestContentTypes = @[@"application/x-www-form-urlencoded"]; - NSString* requestContentType = [requestContentTypes count] > 0 ? requestContentTypes[0] : @"application/json"; - - NSArray* responseContentTypes = @[@"application/json", @"application/xml"]; - NSString* responseContentType = [responseContentTypes count] > 0 ? responseContentTypes[0] : @"application/json"; - ->>>>>>> develop_2.0 NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init]; NSMutableDictionary* headerParams = [NSMutableDictionary dictionaryWithDictionary:self.defaultHeaders]; @@ -590,14 +604,22 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; // HTTP header `Accept` - NSArray *headerAccept = @[@"application/json", @"application/xml"]; - headerParams[@"Accept"] = [SWGApiClient selectHeaderAccept:headerAccept]; - NSString *responseContentType = [headerParams[@"Accept"] componentsSeparatedByString:@", "][0]; + headerParams[@"Accept"] = [SWGApiClient selectHeaderAccept:@[@"application/json", @"application/xml"]]; + if ([headerParams[@"Accept"] length] == 0) { + [headerParams removeObjectForKey:@"Accept"]; + } - // HTTP header `Content-Type` - NSArray *headerContentType = @[@"application/x-www-form-urlencoded", ]; - headerParams[@"Content-Type"] = [SWGApiClient selectHeaderContentType:headerContentType]; - NSString *requestContentType = headerParams[@"Content-Type"]; + // response content type + NSString *responseContentType; + if ([headerParams objectForKey:@"Accept"]) { + responseContentType = [headerParams[@"Accept"] componentsSeparatedByString:@", "][0]; + } + else { + responseContentType = @""; + } + + // request content type + NSString *requestContentType = [SWGApiClient selectHeaderContentType:@[@"application/x-www-form-urlencoded"]]; id bodyDictionary = nil; @@ -688,14 +710,22 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; // HTTP header `Accept` - NSArray *headerAccept = @[@"application/json", @"application/xml"]; - headerParams[@"Accept"] = [SWGApiClient selectHeaderAccept:headerAccept]; - NSString *responseContentType = [headerParams[@"Accept"] componentsSeparatedByString:@", "][0]; + headerParams[@"Accept"] = [SWGApiClient selectHeaderAccept:@[@"application/json", @"application/xml"]]; + if ([headerParams[@"Accept"] length] == 0) { + [headerParams removeObjectForKey:@"Accept"]; + } - // HTTP header `Content-Type` - NSArray *headerContentType = @[]; - headerParams[@"Content-Type"] = [SWGApiClient selectHeaderContentType:headerContentType]; - NSString *requestContentType = headerParams[@"Content-Type"]; + // response content type + NSString *responseContentType; + if ([headerParams objectForKey:@"Accept"]) { + responseContentType = [headerParams[@"Accept"] componentsSeparatedByString:@", "][0]; + } + else { + responseContentType = @""; + } + + // request content type + NSString *requestContentType = [SWGApiClient selectHeaderContentType:@[]]; id bodyDictionary = nil; @@ -763,15 +793,6 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; [requestUrl replaceCharactersInRange: [requestUrl rangeOfString:[NSString stringWithFormat:@"%@%@%@", @"{", @"petId", @"}"]] withString: [SWGApiClient escape:petId]]; -<<<<<<< HEAD -======= - NSArray* requestContentTypes = @[@"multipart/form-data"]; - NSString* requestContentType = [requestContentTypes count] > 0 ? requestContentTypes[0] : @"application/json"; - - NSArray* responseContentTypes = @[@"application/json", @"application/xml"]; - NSString* responseContentType = [responseContentTypes count] > 0 ? responseContentTypes[0] : @"application/json"; - ->>>>>>> develop_2.0 NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init]; NSMutableDictionary* headerParams = [NSMutableDictionary dictionaryWithDictionary:self.defaultHeaders]; @@ -779,14 +800,22 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; // HTTP header `Accept` - NSArray *headerAccept = @[@"application/json", @"application/xml"]; - headerParams[@"Accept"] = [SWGApiClient selectHeaderAccept:headerAccept]; - NSString *responseContentType = [headerParams[@"Accept"] componentsSeparatedByString:@", "][0]; + headerParams[@"Accept"] = [SWGApiClient selectHeaderAccept:@[@"application/json", @"application/xml"]]; + if ([headerParams[@"Accept"] length] == 0) { + [headerParams removeObjectForKey:@"Accept"]; + } - // HTTP header `Content-Type` - NSArray *headerContentType = @[@"multipart/form-data", ]; - headerParams[@"Content-Type"] = [SWGApiClient selectHeaderContentType:headerContentType]; - NSString *requestContentType = headerParams[@"Content-Type"]; + // response content type + NSString *responseContentType; + if ([headerParams objectForKey:@"Accept"]) { + responseContentType = [headerParams[@"Accept"] componentsSeparatedByString:@", "][0]; + } + else { + responseContentType = @""; + } + + // request content type + NSString *requestContentType = [SWGApiClient selectHeaderContentType:@[@"multipart/form-data"]]; id bodyDictionary = nil; diff --git a/samples/client/petstore/objc/client/SWGStoreApi.m b/samples/client/petstore/objc/client/SWGStoreApi.m index e4ac4f4e8c0..75875ff4eae 100644 --- a/samples/client/petstore/objc/client/SWGStoreApi.m +++ b/samples/client/petstore/objc/client/SWGStoreApi.m @@ -81,14 +81,22 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; // HTTP header `Accept` - NSArray *headerAccept = @[@"application/json", @"application/xml"]; - headerParams[@"Accept"] = [SWGApiClient selectHeaderAccept:headerAccept]; - NSString *responseContentType = [headerParams[@"Accept"] componentsSeparatedByString:@", "][0]; + headerParams[@"Accept"] = [SWGApiClient selectHeaderAccept:@[@"application/json", @"application/xml"]]; + if ([headerParams[@"Accept"] length] == 0) { + [headerParams removeObjectForKey:@"Accept"]; + } - // HTTP header `Content-Type` - NSArray *headerContentType = @[]; - headerParams[@"Content-Type"] = [SWGApiClient selectHeaderContentType:headerContentType]; - NSString *requestContentType = headerParams[@"Content-Type"]; + // response content type + NSString *responseContentType; + if ([headerParams objectForKey:@"Accept"]) { + responseContentType = [headerParams[@"Accept"] componentsSeparatedByString:@", "][0]; + } + else { + responseContentType = @""; + } + + // request content type + NSString *requestContentType = [SWGApiClient selectHeaderContentType:@[]]; id bodyDictionary = nil; @@ -161,14 +169,22 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; // HTTP header `Accept` - NSArray *headerAccept = @[@"application/json", @"application/xml"]; - headerParams[@"Accept"] = [SWGApiClient selectHeaderAccept:headerAccept]; - NSString *responseContentType = [headerParams[@"Accept"] componentsSeparatedByString:@", "][0]; + headerParams[@"Accept"] = [SWGApiClient selectHeaderAccept:@[@"application/json", @"application/xml"]]; + if ([headerParams[@"Accept"] length] == 0) { + [headerParams removeObjectForKey:@"Accept"]; + } - // HTTP header `Content-Type` - NSArray *headerContentType = @[]; - headerParams[@"Content-Type"] = [SWGApiClient selectHeaderContentType:headerContentType]; - NSString *requestContentType = headerParams[@"Content-Type"]; + // response content type + NSString *responseContentType; + if ([headerParams objectForKey:@"Accept"]) { + responseContentType = [headerParams[@"Accept"] componentsSeparatedByString:@", "][0]; + } + else { + responseContentType = @""; + } + + // request content type + NSString *requestContentType = [SWGApiClient selectHeaderContentType:@[]]; id bodyDictionary = nil; @@ -276,14 +292,22 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; // HTTP header `Accept` - NSArray *headerAccept = @[@"application/json", @"application/xml"]; - headerParams[@"Accept"] = [SWGApiClient selectHeaderAccept:headerAccept]; - NSString *responseContentType = [headerParams[@"Accept"] componentsSeparatedByString:@", "][0]; + headerParams[@"Accept"] = [SWGApiClient selectHeaderAccept:@[@"application/json", @"application/xml"]]; + if ([headerParams[@"Accept"] length] == 0) { + [headerParams removeObjectForKey:@"Accept"]; + } - // HTTP header `Content-Type` - NSArray *headerContentType = @[]; - headerParams[@"Content-Type"] = [SWGApiClient selectHeaderContentType:headerContentType]; - NSString *requestContentType = headerParams[@"Content-Type"]; + // response content type + NSString *responseContentType; + if ([headerParams objectForKey:@"Accept"]) { + responseContentType = [headerParams[@"Accept"] componentsSeparatedByString:@", "][0]; + } + else { + responseContentType = @""; + } + + // request content type + NSString *requestContentType = [SWGApiClient selectHeaderContentType:@[]]; id bodyDictionary = nil; @@ -368,14 +392,22 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; // HTTP header `Accept` - NSArray *headerAccept = @[@"application/json", @"application/xml"]; - headerParams[@"Accept"] = [SWGApiClient selectHeaderAccept:headerAccept]; - NSString *responseContentType = [headerParams[@"Accept"] componentsSeparatedByString:@", "][0]; + headerParams[@"Accept"] = [SWGApiClient selectHeaderAccept:@[@"application/json", @"application/xml"]]; + if ([headerParams[@"Accept"] length] == 0) { + [headerParams removeObjectForKey:@"Accept"]; + } - // HTTP header `Content-Type` - NSArray *headerContentType = @[]; - headerParams[@"Content-Type"] = [SWGApiClient selectHeaderContentType:headerContentType]; - NSString *requestContentType = headerParams[@"Content-Type"]; + // response content type + NSString *responseContentType; + if ([headerParams objectForKey:@"Accept"]) { + responseContentType = [headerParams[@"Accept"] componentsSeparatedByString:@", "][0]; + } + else { + responseContentType = @""; + } + + // request content type + NSString *requestContentType = [SWGApiClient selectHeaderContentType:@[]]; id bodyDictionary = nil; diff --git a/samples/client/petstore/objc/client/SWGUserApi.m b/samples/client/petstore/objc/client/SWGUserApi.m index 30af7788af7..3e87268a4c6 100644 --- a/samples/client/petstore/objc/client/SWGUserApi.m +++ b/samples/client/petstore/objc/client/SWGUserApi.m @@ -83,14 +83,22 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; // HTTP header `Accept` - NSArray *headerAccept = @[@"application/json", @"application/xml"]; - headerParams[@"Accept"] = [SWGApiClient selectHeaderAccept:headerAccept]; - NSString *responseContentType = [headerParams[@"Accept"] componentsSeparatedByString:@", "][0]; + headerParams[@"Accept"] = [SWGApiClient selectHeaderAccept:@[@"application/json", @"application/xml"]]; + if ([headerParams[@"Accept"] length] == 0) { + [headerParams removeObjectForKey:@"Accept"]; + } - // HTTP header `Content-Type` - NSArray *headerContentType = @[]; - headerParams[@"Content-Type"] = [SWGApiClient selectHeaderContentType:headerContentType]; - NSString *requestContentType = headerParams[@"Content-Type"]; + // response content type + NSString *responseContentType; + if ([headerParams objectForKey:@"Accept"]) { + responseContentType = [headerParams[@"Accept"] componentsSeparatedByString:@", "][0]; + } + else { + responseContentType = @""; + } + + // request content type + NSString *requestContentType = [SWGApiClient selectHeaderContentType:@[]]; id bodyDictionary = nil; @@ -180,14 +188,22 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; // HTTP header `Accept` - NSArray *headerAccept = @[@"application/json", @"application/xml"]; - headerParams[@"Accept"] = [SWGApiClient selectHeaderAccept:headerAccept]; - NSString *responseContentType = [headerParams[@"Accept"] componentsSeparatedByString:@", "][0]; + headerParams[@"Accept"] = [SWGApiClient selectHeaderAccept:@[@"application/json", @"application/xml"]]; + if ([headerParams[@"Accept"] length] == 0) { + [headerParams removeObjectForKey:@"Accept"]; + } - // HTTP header `Content-Type` - NSArray *headerContentType = @[]; - headerParams[@"Content-Type"] = [SWGApiClient selectHeaderContentType:headerContentType]; - NSString *requestContentType = headerParams[@"Content-Type"]; + // response content type + NSString *responseContentType; + if ([headerParams objectForKey:@"Accept"]) { + responseContentType = [headerParams[@"Accept"] componentsSeparatedByString:@", "][0]; + } + else { + responseContentType = @""; + } + + // request content type + NSString *requestContentType = [SWGApiClient selectHeaderContentType:@[]]; id bodyDictionary = nil; @@ -277,14 +293,22 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; // HTTP header `Accept` - NSArray *headerAccept = @[@"application/json", @"application/xml"]; - headerParams[@"Accept"] = [SWGApiClient selectHeaderAccept:headerAccept]; - NSString *responseContentType = [headerParams[@"Accept"] componentsSeparatedByString:@", "][0]; + headerParams[@"Accept"] = [SWGApiClient selectHeaderAccept:@[@"application/json", @"application/xml"]]; + if ([headerParams[@"Accept"] length] == 0) { + [headerParams removeObjectForKey:@"Accept"]; + } - // HTTP header `Content-Type` - NSArray *headerContentType = @[]; - headerParams[@"Content-Type"] = [SWGApiClient selectHeaderContentType:headerContentType]; - NSString *requestContentType = headerParams[@"Content-Type"]; + // response content type + NSString *responseContentType; + if ([headerParams objectForKey:@"Accept"]) { + responseContentType = [headerParams[@"Accept"] componentsSeparatedByString:@", "][0]; + } + else { + responseContentType = @""; + } + + // request content type + NSString *requestContentType = [SWGApiClient selectHeaderContentType:@[]]; id bodyDictionary = nil; @@ -384,14 +408,22 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; // HTTP header `Accept` - NSArray *headerAccept = @[@"application/json", @"application/xml"]; - headerParams[@"Accept"] = [SWGApiClient selectHeaderAccept:headerAccept]; - NSString *responseContentType = [headerParams[@"Accept"] componentsSeparatedByString:@", "][0]; + headerParams[@"Accept"] = [SWGApiClient selectHeaderAccept:@[@"application/json", @"application/xml"]]; + if ([headerParams[@"Accept"] length] == 0) { + [headerParams removeObjectForKey:@"Accept"]; + } - // HTTP header `Content-Type` - NSArray *headerContentType = @[]; - headerParams[@"Content-Type"] = [SWGApiClient selectHeaderContentType:headerContentType]; - NSString *requestContentType = headerParams[@"Content-Type"]; + // response content type + NSString *responseContentType; + if ([headerParams objectForKey:@"Accept"]) { + responseContentType = [headerParams[@"Accept"] componentsSeparatedByString:@", "][0]; + } + else { + responseContentType = @""; + } + + // request content type + NSString *requestContentType = [SWGApiClient selectHeaderContentType:@[]]; id bodyDictionary = nil; @@ -468,14 +500,22 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; // HTTP header `Accept` - NSArray *headerAccept = @[@"application/json", @"application/xml"]; - headerParams[@"Accept"] = [SWGApiClient selectHeaderAccept:headerAccept]; - NSString *responseContentType = [headerParams[@"Accept"] componentsSeparatedByString:@", "][0]; + headerParams[@"Accept"] = [SWGApiClient selectHeaderAccept:@[@"application/json", @"application/xml"]]; + if ([headerParams[@"Accept"] length] == 0) { + [headerParams removeObjectForKey:@"Accept"]; + } - // HTTP header `Content-Type` - NSArray *headerContentType = @[]; - headerParams[@"Content-Type"] = [SWGApiClient selectHeaderContentType:headerContentType]; - NSString *requestContentType = headerParams[@"Content-Type"]; + // response content type + NSString *responseContentType; + if ([headerParams objectForKey:@"Accept"]) { + responseContentType = [headerParams[@"Accept"] componentsSeparatedByString:@", "][0]; + } + else { + responseContentType = @""; + } + + // request content type + NSString *requestContentType = [SWGApiClient selectHeaderContentType:@[]]; id bodyDictionary = nil; @@ -546,14 +586,22 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; // HTTP header `Accept` - NSArray *headerAccept = @[@"application/json", @"application/xml"]; - headerParams[@"Accept"] = [SWGApiClient selectHeaderAccept:headerAccept]; - NSString *responseContentType = [headerParams[@"Accept"] componentsSeparatedByString:@", "][0]; + headerParams[@"Accept"] = [SWGApiClient selectHeaderAccept:@[@"application/json", @"application/xml"]]; + if ([headerParams[@"Accept"] length] == 0) { + [headerParams removeObjectForKey:@"Accept"]; + } - // HTTP header `Content-Type` - NSArray *headerContentType = @[]; - headerParams[@"Content-Type"] = [SWGApiClient selectHeaderContentType:headerContentType]; - NSString *requestContentType = headerParams[@"Content-Type"]; + // response content type + NSString *responseContentType; + if ([headerParams objectForKey:@"Accept"]) { + responseContentType = [headerParams[@"Accept"] componentsSeparatedByString:@", "][0]; + } + else { + responseContentType = @""; + } + + // request content type + NSString *requestContentType = [SWGApiClient selectHeaderContentType:@[]]; id bodyDictionary = nil; @@ -640,14 +688,22 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; // HTTP header `Accept` - NSArray *headerAccept = @[@"application/json", @"application/xml"]; - headerParams[@"Accept"] = [SWGApiClient selectHeaderAccept:headerAccept]; - NSString *responseContentType = [headerParams[@"Accept"] componentsSeparatedByString:@", "][0]; + headerParams[@"Accept"] = [SWGApiClient selectHeaderAccept:@[@"application/json", @"application/xml"]]; + if ([headerParams[@"Accept"] length] == 0) { + [headerParams removeObjectForKey:@"Accept"]; + } - // HTTP header `Content-Type` - NSArray *headerContentType = @[]; - headerParams[@"Content-Type"] = [SWGApiClient selectHeaderContentType:headerContentType]; - NSString *requestContentType = headerParams[@"Content-Type"]; + // response content type + NSString *responseContentType; + if ([headerParams objectForKey:@"Accept"]) { + responseContentType = [headerParams[@"Accept"] componentsSeparatedByString:@", "][0]; + } + else { + responseContentType = @""; + } + + // request content type + NSString *requestContentType = [SWGApiClient selectHeaderContentType:@[]]; id bodyDictionary = nil; @@ -741,14 +797,22 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; // HTTP header `Accept` - NSArray *headerAccept = @[@"application/json", @"application/xml"]; - headerParams[@"Accept"] = [SWGApiClient selectHeaderAccept:headerAccept]; - NSString *responseContentType = [headerParams[@"Accept"] componentsSeparatedByString:@", "][0]; + headerParams[@"Accept"] = [SWGApiClient selectHeaderAccept:@[@"application/json", @"application/xml"]]; + if ([headerParams[@"Accept"] length] == 0) { + [headerParams removeObjectForKey:@"Accept"]; + } - // HTTP header `Content-Type` - NSArray *headerContentType = @[]; - headerParams[@"Content-Type"] = [SWGApiClient selectHeaderContentType:headerContentType]; - NSString *requestContentType = headerParams[@"Content-Type"]; + // response content type + NSString *responseContentType; + if ([headerParams objectForKey:@"Accept"]) { + responseContentType = [headerParams[@"Accept"] componentsSeparatedByString:@", "][0]; + } + else { + responseContentType = @""; + } + + // request content type + NSString *requestContentType = [SWGApiClient selectHeaderContentType:@[]]; id bodyDictionary = nil; From 2514f3aa08ddccb6a70764f8a91f40b993173590 Mon Sep 17 00:00:00 2001 From: geekerzp Date: Sat, 23 May 2015 15:29:38 +0800 Subject: [PATCH 3/3] update SWGApiClient.h of objc client. --- .../swagger-codegen/src/main/resources/objc/SWGApiClient.h | 4 ++-- samples/client/petstore/objc/client/SWGApiClient.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/objc/SWGApiClient.h b/modules/swagger-codegen/src/main/resources/objc/SWGApiClient.h index 3edada7a4c7..cd6f52db5c6 100644 --- a/modules/swagger-codegen/src/main/resources/objc/SWGApiClient.h +++ b/modules/swagger-codegen/src/main/resources/objc/SWGApiClient.h @@ -48,8 +48,8 @@ extern NSString *const SWGResponseObjectErrorKey; +(void) configureCacheReachibilityForHost:(NSString*)host; -+(NSString *) selectHeaderAccept:(NSArray *)headerAcceptArray; -+(NSString *) selectHeaderContentType:(NSArray *)headerContentTypeArray; ++(NSString *) selectHeaderAccept:(NSArray *)accepts; ++(NSString *) selectHeaderContentType:(NSArray *)contentTypes; -(void)setHeaderValue:(NSString*) value forKey:(NSString*) forKey; diff --git a/samples/client/petstore/objc/client/SWGApiClient.h b/samples/client/petstore/objc/client/SWGApiClient.h index 3edada7a4c7..cd6f52db5c6 100644 --- a/samples/client/petstore/objc/client/SWGApiClient.h +++ b/samples/client/petstore/objc/client/SWGApiClient.h @@ -48,8 +48,8 @@ extern NSString *const SWGResponseObjectErrorKey; +(void) configureCacheReachibilityForHost:(NSString*)host; -+(NSString *) selectHeaderAccept:(NSArray *)headerAcceptArray; -+(NSString *) selectHeaderContentType:(NSArray *)headerContentTypeArray; ++(NSString *) selectHeaderAccept:(NSArray *)accepts; ++(NSString *) selectHeaderContentType:(NSArray *)contentTypes; -(void)setHeaderValue:(NSString*) value forKey:(NSString*) forKey;