diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/CSharpClientCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/CSharpClientCodegen.java index 09ec05b078b..f10d9a0f299 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/CSharpClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/CSharpClientCodegen.java @@ -137,11 +137,12 @@ public class CSharpClientCodegen extends DefaultCodegen implements CodegenConfig @Override public String apiFileFolder() { - return (outputFolder + File.separator + sourceFolder + File.separator + apiPackage()).replace('.', File.separatorChar); + + return outputFolder + File.separator + (sourceFolder + File.separator + apiPackage()).replace('.', File.separatorChar); } public String modelFileFolder() { - return (outputFolder + File.separator + sourceFolder + File.separator + modelPackage()).replace('.', File.separatorChar); + return outputFolder + File.separator + (sourceFolder + File.separator + modelPackage()).replace('.', File.separatorChar); } @Override diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/ObjcClientCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/ObjcClientCodegen.java index dfb4094f2b6..ef369169827 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/ObjcClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/ObjcClientCodegen.java @@ -23,6 +23,10 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig { protected String podName = "SwaggerClient"; protected String podVersion = "1.0.0"; protected String classPrefix = "SWG"; + protected String authorName = "Swagger"; + protected String authorEmail = "apiteam@swagger.io"; + protected String license = "MIT"; + protected String gitRepoURL = "https://github.com/swagger-api/swagger-codegen"; public ObjcClientCodegen() { super(); @@ -112,6 +116,10 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig { cliOptions.add(new CliOption("classPrefix", "prefix for generated classes (convention: Abbreviation of pod name e.g. `HN` for `HackerNews`), default: `SWG`")); cliOptions.add(new CliOption("podName", "cocoapods package name (convention: CameCase), default: `SwaggerClient`")); cliOptions.add(new CliOption("podVersion", "cocoapods package version, default: `1.0.0`")); + cliOptions.add(new CliOption("authorName", "Name to use in the podspec file, default: `Swagger`")); + cliOptions.add(new CliOption("authorEmail", "Email to use in the podspec file, default: `apiteam@swagger.io`")); + cliOptions.add(new CliOption("gitRepoURL", "URL for the git repo where this podspec should point to, default: `https://github.com/swagger-api/swagger-codegen`")); + cliOptions.add(new CliOption("license", "License to use in the podspec file, default: `MIT`")); } public CodegenType getTag() { @@ -141,10 +149,30 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig { if (additionalProperties.containsKey("classPrefix")) { setClassPrefix((String) additionalProperties.get("classPrefix")); } + + if (additionalProperties.containsKey("authorName")) { + setAuthorName((String) additionalProperties.get("authorName")); + } + + if (additionalProperties.containsKey("authorEmail")) { + setAuthorEmail((String) additionalProperties.get("authorEmail")); + } + + if (additionalProperties.containsKey("gitRepoURL")) { + setGitRepoURL((String) additionalProperties.get("gitRepoURL")); + } + + if (additionalProperties.containsKey("license")) { + setLicense((String) additionalProperties.get("license")); + } additionalProperties.put("podName", podName); additionalProperties.put("podVersion", podVersion); additionalProperties.put("classPrefix", classPrefix); + additionalProperties.put("authorName", authorName); + additionalProperties.put("authorEmail", authorEmail); + additionalProperties.put("gitRepoURL", gitRepoURL); + additionalProperties.put("license", license); String swaggerFolder = podName; @@ -384,4 +412,20 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig { public void setPodVersion(String podVersion) { this.podVersion = podVersion; } + + public void setAuthorEmail(String authorEmail) { + this.authorEmail = authorEmail; + } + + public void setAuthorName(String authorName) { + this.authorName = authorName; + } + + public void setGitRepoURL(String gitRepoURL) { + this.gitRepoURL = gitRepoURL; + } + + public void setLicense(String license) { + this.license = license; + } } diff --git a/modules/swagger-codegen/src/main/resources/objc/ApiClient-body.mustache b/modules/swagger-codegen/src/main/resources/objc/ApiClient-body.mustache index b7643de6ddd..5b2a290ab85 100644 --- a/modules/swagger-codegen/src/main/resources/objc/ApiClient-body.mustache +++ b/modules/swagger-codegen/src/main/resources/objc/ApiClient-body.mustache @@ -9,6 +9,13 @@ static bool cacheEnabled = false; static AFNetworkReachabilityStatus reachabilityStatus = AFNetworkReachabilityStatusNotReachable; static void (^reachabilityChangeBlock)(int); + +@interface {{classPrefix}}ApiClient () + +@property (readwrite, nonatomic) NSDictionary *HTTPResponseHeaders; + +@end + @implementation {{classPrefix}}ApiClient - (instancetype)init { @@ -385,6 +392,8 @@ static void (^reachabilityChangeBlock)(int); if([[{{classPrefix}}Configuration sharedConfig] debug]) { [self logResponse:operation forRequest:request error:nil]; } + NSDictionary *responseHeaders = [[operation response] allHeaderFields]; + self.HTTPResponseHeaders = responseHeaders; completionBlock(response, nil); } } failure:^(AFHTTPRequestOperation *operation, NSError *error) { @@ -398,6 +407,10 @@ static void (^reachabilityChangeBlock)(int); if([[{{classPrefix}}Configuration sharedConfig] debug]) [self logResponse:nil forRequest:request error:augmentedError]; + + NSDictionary *responseHeaders = [[operation response] allHeaderFields]; + self.HTTPResponseHeaders = responseHeaders; + completionBlock(nil, augmentedError); } }]; @@ -441,6 +454,7 @@ static void (^reachabilityChangeBlock)(int); NSURL *file = [NSURL fileURLWithPath:filepath]; [operation.responseData writeToURL:file atomically:YES]; + self.HTTPResponseHeaders = headers; completionBlock(file, nil); } failure:^(AFHTTPRequestOperation *operation, NSError *error) { @@ -455,7 +469,8 @@ static void (^reachabilityChangeBlock)(int); if ([[{{classPrefix}}Configuration sharedConfig] debug]) { [self logResponse:nil forRequest:request error:augmentedError]; } - + NSDictionary *responseHeaders = [[operation response] allHeaderFields]; + self.HTTPResponseHeaders = responseHeaders; completionBlock(nil, augmentedError); } }]; diff --git a/modules/swagger-codegen/src/main/resources/objc/ApiClient-header.mustache b/modules/swagger-codegen/src/main/resources/objc/ApiClient-header.mustache index eba62705879..fef1a2b79e7 100644 --- a/modules/swagger-codegen/src/main/resources/objc/ApiClient-header.mustache +++ b/modules/swagger-codegen/src/main/resources/objc/ApiClient-header.mustache @@ -31,6 +31,9 @@ extern NSString *const {{classPrefix}}ResponseObjectErrorKey; @property(nonatomic, assign) NSTimeInterval timeoutInterval; @property(nonatomic, readonly) NSOperationQueue* queue; +/// In order to ensure the HTTPResponseHeaders are correct, it is recommended to initialize one {{classPrefix}}ApiClient instance per thread. +@property(nonatomic, readonly) NSDictionary* HTTPResponseHeaders; + /** * Clears Cache */ 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 534c887fe7b..1aa22a0a0c6 100644 --- a/modules/swagger-codegen/src/main/resources/objc/api-body.mustache +++ b/modules/swagger-codegen/src/main/resources/objc/api-body.mustache @@ -11,6 +11,8 @@ @implementation {{classname}} +static {{classname}}* singletonAPI = nil; + #pragma mark - Initialize methods - (id) init { @@ -38,7 +40,6 @@ #pragma mark - +({{classname}}*) apiWithHeader:(NSString*)headerValue key:(NSString*)key { - static {{classname}}* singletonAPI = nil; if (singletonAPI == nil) { singletonAPI = [[{{classname}} alloc] init]; @@ -47,6 +48,14 @@ return singletonAPI; } ++({{classname}}*) sharedAPI { + + if (singletonAPI == nil) { + singletonAPI = [[{{classname}} alloc] init]; + } + return singletonAPI; +} + -(void) addHeader:(NSString*)value forKey:(NSString*)key { [self.defaultHeaders setValue:value forKey:key]; } diff --git a/modules/swagger-codegen/src/main/resources/objc/api-header.mustache b/modules/swagger-codegen/src/main/resources/objc/api-header.mustache index d9f691f7227..29c7d9477f2 100644 --- a/modules/swagger-codegen/src/main/resources/objc/api-header.mustache +++ b/modules/swagger-codegen/src/main/resources/objc/api-header.mustache @@ -20,6 +20,7 @@ -(void) addHeader:(NSString*)value forKey:(NSString*)key; -(unsigned long) requestQueueSize; +({{classname}}*) apiWithHeader:(NSString*)headerValue key:(NSString*)key; ++({{classname}}*) sharedAPI; {{#operation}} /// /// diff --git a/modules/swagger-codegen/src/main/resources/objc/podspec.mustache b/modules/swagger-codegen/src/main/resources/objc/podspec.mustache index 9ce03695bcf..338ded84e89 100644 --- a/modules/swagger-codegen/src/main/resources/objc/podspec.mustache +++ b/modules/swagger-codegen/src/main/resources/objc/podspec.mustache @@ -20,6 +20,11 @@ Pod::Spec.new do |s| s.requires_arc = true s.framework = 'SystemConfiguration' + + s.homepage = "{{gitRepoURL}}" + s.license = "{{license}}" + s.source = { :git => "{{gitRepoURL}}.git", :tag => "#{s.version}" } + s.author = { "{{authorName}}" => "{{authorEmail}}" } s.source_files = '{{podName}}/**/*' s.public_header_files = '{{podName}}/**/*.h' diff --git a/modules/swagger-codegen/src/main/resources/python/api_client.mustache b/modules/swagger-codegen/src/main/resources/python/api_client.mustache index 1becd5547dd..84a1dca45ff 100644 --- a/modules/swagger-codegen/src/main/resources/python/api_client.mustache +++ b/modules/swagger-codegen/src/main/resources/python/api_client.mustache @@ -270,7 +270,7 @@ class ApiClient(object): if klass in [int, float, str, bool]: return self.__deserialize_primitive(data, klass) elif klass == object: - return self.__deserialize_object() + return self.__deserialize_object(data) elif klass == date: return self.__deserialize_date(data) elif klass == datetime: @@ -495,13 +495,13 @@ class ApiClient(object): value = data return value - def __deserialize_object(self): + def __deserialize_object(self, value): """ - Deserializes empty object. + Return a original value. :return: object. """ - return object() + return value def __deserialize_date(self, string): """ diff --git a/samples/client/petstore/objc/README.md b/samples/client/petstore/objc/README.md index 4cce2c882bb..10e44984683 100644 --- a/samples/client/petstore/objc/README.md +++ b/samples/client/petstore/objc/README.md @@ -12,6 +12,10 @@ To install it, put the API client library in your project and then simply add th pod "SwaggerClient", :path => "/path/to/lib" ``` +## Recommendation + +It's recommended to create an instance of ApiClient per thread in a multithreaded environment to avoid any potential issue. + ## Author apiteam@swagger.io diff --git a/samples/client/petstore/objc/SwaggerClient/SWGApiClient.h b/samples/client/petstore/objc/SwaggerClient/SWGApiClient.h index 84f28faa8c6..580efa739a0 100644 --- a/samples/client/petstore/objc/SwaggerClient/SWGApiClient.h +++ b/samples/client/petstore/objc/SwaggerClient/SWGApiClient.h @@ -35,6 +35,9 @@ extern NSString *const SWGResponseObjectErrorKey; @property(nonatomic, assign) NSTimeInterval timeoutInterval; @property(nonatomic, readonly) NSOperationQueue* queue; +/// In order to ensure the HTTPResponseHeaders are correct, it is recommended to initialize one SWGApiClient instance per thread. +@property(nonatomic, readonly) NSDictionary* HTTPResponseHeaders; + /** * Clears Cache */ diff --git a/samples/client/petstore/objc/SwaggerClient/SWGApiClient.m b/samples/client/petstore/objc/SwaggerClient/SWGApiClient.m index 906169f4d12..826443453b0 100644 --- a/samples/client/petstore/objc/SwaggerClient/SWGApiClient.m +++ b/samples/client/petstore/objc/SwaggerClient/SWGApiClient.m @@ -9,6 +9,13 @@ static bool cacheEnabled = false; static AFNetworkReachabilityStatus reachabilityStatus = AFNetworkReachabilityStatusNotReachable; static void (^reachabilityChangeBlock)(int); + +@interface SWGApiClient () + +@property (readwrite, nonatomic) NSDictionary *HTTPResponseHeaders; + +@end + @implementation SWGApiClient - (instancetype)init { @@ -385,6 +392,8 @@ static void (^reachabilityChangeBlock)(int); if([[SWGConfiguration sharedConfig] debug]) { [self logResponse:operation forRequest:request error:nil]; } + NSDictionary *responseHeaders = [[operation response] allHeaderFields]; + self.HTTPResponseHeaders = responseHeaders; completionBlock(response, nil); } } failure:^(AFHTTPRequestOperation *operation, NSError *error) { @@ -398,6 +407,10 @@ static void (^reachabilityChangeBlock)(int); if([[SWGConfiguration sharedConfig] debug]) [self logResponse:nil forRequest:request error:augmentedError]; + + NSDictionary *responseHeaders = [[operation response] allHeaderFields]; + self.HTTPResponseHeaders = responseHeaders; + completionBlock(nil, augmentedError); } }]; @@ -441,6 +454,7 @@ static void (^reachabilityChangeBlock)(int); NSURL *file = [NSURL fileURLWithPath:filepath]; [operation.responseData writeToURL:file atomically:YES]; + self.HTTPResponseHeaders = headers; completionBlock(file, nil); } failure:^(AFHTTPRequestOperation *operation, NSError *error) { @@ -455,7 +469,8 @@ static void (^reachabilityChangeBlock)(int); if ([[SWGConfiguration sharedConfig] debug]) { [self logResponse:nil forRequest:request error:augmentedError]; } - + NSDictionary *responseHeaders = [[operation response] allHeaderFields]; + self.HTTPResponseHeaders = responseHeaders; completionBlock(nil, augmentedError); } }]; diff --git a/samples/client/petstore/objc/SwaggerClient/SWGPetApi.h b/samples/client/petstore/objc/SwaggerClient/SWGPetApi.h index f7e67d0aa1f..7ea1821e575 100644 --- a/samples/client/petstore/objc/SwaggerClient/SWGPetApi.h +++ b/samples/client/petstore/objc/SwaggerClient/SWGPetApi.h @@ -18,6 +18,7 @@ -(void) addHeader:(NSString*)value forKey:(NSString*)key; -(unsigned long) requestQueueSize; +(SWGPetApi*) apiWithHeader:(NSString*)headerValue key:(NSString*)key; ++(SWGPetApi*) sharedAPI; /// /// /// Update an existing pet diff --git a/samples/client/petstore/objc/SwaggerClient/SWGPetApi.m b/samples/client/petstore/objc/SwaggerClient/SWGPetApi.m index d79584f90bf..4b8eba70562 100644 --- a/samples/client/petstore/objc/SwaggerClient/SWGPetApi.m +++ b/samples/client/petstore/objc/SwaggerClient/SWGPetApi.m @@ -9,6 +9,8 @@ @implementation SWGPetApi +static SWGPetApi* singletonAPI = nil; + #pragma mark - Initialize methods - (id) init { @@ -36,7 +38,6 @@ #pragma mark - +(SWGPetApi*) apiWithHeader:(NSString*)headerValue key:(NSString*)key { - static SWGPetApi* singletonAPI = nil; if (singletonAPI == nil) { singletonAPI = [[SWGPetApi alloc] init]; @@ -45,6 +46,14 @@ return singletonAPI; } ++(SWGPetApi*) sharedAPI { + + if (singletonAPI == nil) { + singletonAPI = [[SWGPetApi alloc] init]; + } + return singletonAPI; +} + -(void) addHeader:(NSString*)value forKey:(NSString*)key { [self.defaultHeaders setValue:value forKey:key]; } diff --git a/samples/client/petstore/objc/SwaggerClient/SWGStoreApi.h b/samples/client/petstore/objc/SwaggerClient/SWGStoreApi.h index 09e67e38ed0..e1c644ef5f4 100644 --- a/samples/client/petstore/objc/SwaggerClient/SWGStoreApi.h +++ b/samples/client/petstore/objc/SwaggerClient/SWGStoreApi.h @@ -18,6 +18,7 @@ -(void) addHeader:(NSString*)value forKey:(NSString*)key; -(unsigned long) requestQueueSize; +(SWGStoreApi*) apiWithHeader:(NSString*)headerValue key:(NSString*)key; ++(SWGStoreApi*) sharedAPI; /// /// /// Returns pet inventories by status diff --git a/samples/client/petstore/objc/SwaggerClient/SWGStoreApi.m b/samples/client/petstore/objc/SwaggerClient/SWGStoreApi.m index 792147ebed1..5fdf86b43af 100644 --- a/samples/client/petstore/objc/SwaggerClient/SWGStoreApi.m +++ b/samples/client/petstore/objc/SwaggerClient/SWGStoreApi.m @@ -9,6 +9,8 @@ @implementation SWGStoreApi +static SWGStoreApi* singletonAPI = nil; + #pragma mark - Initialize methods - (id) init { @@ -36,7 +38,6 @@ #pragma mark - +(SWGStoreApi*) apiWithHeader:(NSString*)headerValue key:(NSString*)key { - static SWGStoreApi* singletonAPI = nil; if (singletonAPI == nil) { singletonAPI = [[SWGStoreApi alloc] init]; @@ -45,6 +46,14 @@ return singletonAPI; } ++(SWGStoreApi*) sharedAPI { + + if (singletonAPI == nil) { + singletonAPI = [[SWGStoreApi alloc] init]; + } + return singletonAPI; +} + -(void) addHeader:(NSString*)value forKey:(NSString*)key { [self.defaultHeaders setValue:value forKey:key]; } diff --git a/samples/client/petstore/objc/SwaggerClient/SWGUserApi.h b/samples/client/petstore/objc/SwaggerClient/SWGUserApi.h index a6e69a8947d..21f314684fd 100644 --- a/samples/client/petstore/objc/SwaggerClient/SWGUserApi.h +++ b/samples/client/petstore/objc/SwaggerClient/SWGUserApi.h @@ -18,6 +18,7 @@ -(void) addHeader:(NSString*)value forKey:(NSString*)key; -(unsigned long) requestQueueSize; +(SWGUserApi*) apiWithHeader:(NSString*)headerValue key:(NSString*)key; ++(SWGUserApi*) sharedAPI; /// /// /// Create user @@ -98,7 +99,7 @@ /// Get user by user name /// /// -/// @param username The name that needs to be fetched. Use user1 for testing. +/// @param username The name that needs to be fetched. Use user1 for testing. /// /// /// @return SWGUser* diff --git a/samples/client/petstore/objc/SwaggerClient/SWGUserApi.m b/samples/client/petstore/objc/SwaggerClient/SWGUserApi.m index 92dd00fa28d..75cf8d51b0e 100644 --- a/samples/client/petstore/objc/SwaggerClient/SWGUserApi.m +++ b/samples/client/petstore/objc/SwaggerClient/SWGUserApi.m @@ -9,6 +9,8 @@ @implementation SWGUserApi +static SWGUserApi* singletonAPI = nil; + #pragma mark - Initialize methods - (id) init { @@ -36,7 +38,6 @@ #pragma mark - +(SWGUserApi*) apiWithHeader:(NSString*)headerValue key:(NSString*)key { - static SWGUserApi* singletonAPI = nil; if (singletonAPI == nil) { singletonAPI = [[SWGUserApi alloc] init]; @@ -45,6 +46,14 @@ return singletonAPI; } ++(SWGUserApi*) sharedAPI { + + if (singletonAPI == nil) { + singletonAPI = [[SWGUserApi alloc] init]; + } + return singletonAPI; +} + -(void) addHeader:(NSString*)value forKey:(NSString*)key { [self.defaultHeaders setValue:value forKey:key]; } @@ -461,7 +470,7 @@ /// /// Get user by user name /// -/// @param username The name that needs to be fetched. Use user1 for testing. +/// @param username The name that needs to be fetched. Use user1 for testing. /// /// @returns SWGUser* ///