Merge remote-tracking branch 'upstream/master' into cli-enhancements-2

This commit is contained in:
russellb337 2015-09-04 15:25:10 -07:00
commit 6c079e95d9
17 changed files with 144 additions and 14 deletions

View File

@ -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

View File

@ -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;
}
}

View File

@ -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);
}
}];

View File

@ -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
*/

View File

@ -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];
}

View File

@ -20,6 +20,7 @@
-(void) addHeader:(NSString*)value forKey:(NSString*)key;
-(unsigned long) requestQueueSize;
+({{classname}}*) apiWithHeader:(NSString*)headerValue key:(NSString*)key;
+({{classname}}*) sharedAPI;
{{#operation}}
///
///

View File

@ -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'

View File

@ -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):
"""

View File

@ -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

View File

@ -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
*/

View File

@ -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);
}
}];

View File

@ -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

View File

@ -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];
}

View File

@ -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

View File

@ -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];
}

View File

@ -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*

View File

@ -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*
///