Update objc client.

* Add comments in SWGConfiguration.h
* Change `Date` to `date` in ObjcClientCodegen.java
* Update comments in model body template
This commit is contained in:
geekerzp 2015-07-23 16:03:38 +08:00
parent 37c79525f7
commit 08ea05f7a1
13 changed files with 161 additions and 47 deletions

View File

@ -57,7 +57,7 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
typeMapping.clear(); typeMapping.clear();
typeMapping.put("enum", "NSString"); typeMapping.put("enum", "NSString");
typeMapping.put("Date", "NSDate"); typeMapping.put("date", "NSDate");
typeMapping.put("DateTime", "NSDate"); typeMapping.put("DateTime", "NSDate");
typeMapping.put("boolean", "NSNumber"); typeMapping.put("boolean", "NSNumber");
typeMapping.put("string", "NSString"); typeMapping.put("string", "NSString");

View File

@ -60,12 +60,20 @@
#pragma mark - Setter Methods #pragma mark - Setter Methods
- (void) setValue:(NSString *)value forApiKeyField:(NSString *)field { - (void) setApiKey:(NSString *)apiKey forApiKeyIdentifier:(NSString *)identifier {
[self.mutableApiKey setValue:value forKey:field]; [self.mutableApiKey setValue:apiKey forKey:identifier];
} }
- (void) setValue:(NSString *)value forApiKeyPrefixField:(NSString *)field { - (void) removeApiKey:(NSString *)identifier {
[self.mutableApiKeyPrefix setValue:value forKey:field]; [self.mutableApiKey removeObjectForKey:identifier];
}
- (void) setApiKeyPrefix:(NSString *)prefix forApiKeyPrefixIdentifier:(NSString *)identifier {
[self.mutableApiKeyPrefix setValue:prefix forKey:identifier];
}
- (void) removeApiKeyPrefix:(NSString *)identifier {
[self.mutableApiKeyPrefix removeObjectForKey:identifier];
} }
- (void) setLoggingFile:(NSString *)loggingFile { - (void) setLoggingFile:(NSString *)loggingFile {
@ -75,10 +83,10 @@
} }
_loggingFile = loggingFile; _loggingFile = loggingFile;
self.loggingFileHanlder = [NSFileHandle fileHandleForWritingAtPath:_loggingFile]; _loggingFileHanlder = [NSFileHandle fileHandleForWritingAtPath:_loggingFile];
if (self.loggingFileHanlder == nil) { if (_loggingFileHanlder == nil) {
[[NSFileManager defaultManager] createFileAtPath:_loggingFile contents:nil attributes:nil]; [[NSFileManager defaultManager] createFileAtPath:_loggingFile contents:nil attributes:nil];
self.loggingFileHanlder = [NSFileHandle fileHandleForWritingAtPath:_loggingFile]; _loggingFileHanlder = [NSFileHandle fileHandleForWritingAtPath:_loggingFile];
} }
} }

View File

@ -1,26 +1,36 @@
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
/** The `{{classPrefix}}Configuration` class manages the configurations for the sdk.
*
* NOTE: This class is auto generated by the swagger code generator program.
* https://github.com/swagger-api/swagger-codegen
* Do not edit the class manually.
*/
@interface {{classPrefix}}Configuration : NSObject @interface {{classPrefix}}Configuration : NSObject
/** /**
* Api key values for Api Key type Authentication * Api key values for Api Key type Authentication
* *
* To add or remove api key, use `setValue:forApiKeyField:`. * To add or remove api key, use `setApiKey:forApiKeyIdentifier:`.
*/ */
@property (readonly, nonatomic, strong) NSDictionary *apiKey; @property (readonly, nonatomic, strong) NSDictionary *apiKey;
/** /**
* Api key prefix values to be prepend to the respective api key * Api key prefix values to be prepend to the respective api key
* *
* To add or remove prefix, use `setValue:forApiKeyPrefixField:`. * To add or remove prefix, use `setApiKeyPrefix:forApiKeyPrefixIdentifier:`.
*/ */
@property (readonly, nonatomic, strong) NSDictionary *apiKeyPrefix; @property (readonly, nonatomic, strong) NSDictionary *apiKeyPrefix;
/** /**
* Usename and Password for Basic type Authentication * Usename for HTTP Basic Authentication
*/
@property (nonatomic) NSString *username;
/**
* Password for HTTP Basic Authentication
*/ */
@property (nonatomic) NSString *username;
@property (nonatomic) NSString *password; @property (nonatomic) NSString *password;
/** /**
@ -31,9 +41,21 @@
/** /**
* Logging Settings * Logging Settings
*/ */
/**
* Debug switch, default false
*/
@property (nonatomic) BOOL debug; @property (nonatomic) BOOL debug;
/**
* Debug file location, default nil
*/
@property (nonatomic) NSString *loggingFile; @property (nonatomic) NSString *loggingFile;
@property (nonatomic) NSFileHandle *loggingFileHanlder;
/**
* Log file handler, this property is used by sdk internally.
*/
@property (nonatomic, readonly) NSFileHandle *loggingFileHanlder;
/** /**
* Get configuration singleton instance * Get configuration singleton instance
@ -41,14 +63,39 @@
+ (instancetype) sharedConfig; + (instancetype) sharedConfig;
/** /**
* Sets field in `apiKey` * Sets field in `apiKey`.
*
* To remove a apiKey for a identifier, just set the apiKey to nil.
*
* @param apiKey The apiKey value.
* @param identifier The apiKey name.
*
*/ */
- (void) setValue:(NSString *)value forApiKeyField:(NSString*)field; - (void) setApiKey:(NSString *)apiKey forApiKeyIdentifier:(NSString*)identifier;
/**
* Remove api key
*
* @param identifier The apiKey name.
*/
- (void) removeApiKey:(NSString *)identifier;
/** /**
* Sets field in `apiKeyPrefix` * Sets field in `apiKeyPrefix`
*
* To remove a apiKeyPrefix for a identifier, just set the apiKeyPrefix to nil.
*
* @param apiKeyPrefix The apiKeyPrefix value.
* @param identifier The apiKeyPrefix name.
*/ */
- (void) setValue:(NSString *)value forApiKeyPrefixField:(NSString *)field; - (void) setApiKeyPrefix:(NSString *)prefix forApiKeyPrefixIdentifier:(NSString *)identifier;
/**
* Remove api key prefix
*
* @param identifier The apiKeyPrefix name.
*/
- (void) removeApiKeyPrefix:(NSString *)identifier;
/** /**
* Get API key (with prefix if set) * Get API key (with prefix if set)

View File

@ -15,7 +15,7 @@
/** /**
* Indicates whether the property with the given name is optional. * Indicates whether the property with the given name is optional.
* If `propertyName` is optional, then return `YES`, or return `NO`. * If `propertyName` is optional, then return `YES`, otherwise return `NO`.
* This method is used by `JSONModel`. * This method is used by `JSONModel`.
*/ */
+ (BOOL)propertyIsOptional:(NSString *)propertyName + (BOOL)propertyIsOptional:(NSString *)propertyName
@ -31,7 +31,7 @@
} }
/** /**
* Return a string that represents the properties json of the model. * Returns a string that represents the properties json of the model.
* This method will be called when logging model object using `NSLog`. * This method will be called when logging model object using `NSLog`.
*/ */
- (NSString *)description { - (NSString *)description {

View File

@ -13,7 +13,7 @@
/** /**
* Indicates whether the property with the given name is optional. * Indicates whether the property with the given name is optional.
* If `propertyName` is optional, then return `YES`, or return `NO`. * If `propertyName` is optional, then return `YES`, otherwise return `NO`.
* This method is used by `JSONModel`. * This method is used by `JSONModel`.
*/ */
+ (BOOL)propertyIsOptional:(NSString *)propertyName + (BOOL)propertyIsOptional:(NSString *)propertyName
@ -29,7 +29,7 @@
} }
/** /**
* Return a string that represents the properties json of the model. * Returns a string that represents the properties json of the model.
* This method will be called when logging model object using `NSLog`. * This method will be called when logging model object using `NSLog`.
*/ */
- (NSString *)description { - (NSString *)description {

View File

@ -1,26 +1,36 @@
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
/** The `SWGConfiguration` class manages the configurations for the sdk.
*
* NOTE: This class is auto generated by the swagger code generator program.
* https://github.com/swagger-api/swagger-codegen
* Do not edit the class manually.
*/
@interface SWGConfiguration : NSObject @interface SWGConfiguration : NSObject
/** /**
* Api key values for Api Key type Authentication * Api key values for Api Key type Authentication
* *
* To add or remove api key, use `setValue:forApiKeyField:`. * To add or remove api key, use `setApiKey:forApiKeyIdentifier:`.
*/ */
@property (readonly, nonatomic, strong) NSDictionary *apiKey; @property (readonly, nonatomic, strong) NSDictionary *apiKey;
/** /**
* Api key prefix values to be prepend to the respective api key * Api key prefix values to be prepend to the respective api key
* *
* To add or remove prefix, use `setValue:forApiKeyPrefixField:`. * To add or remove prefix, use `setApiKeyPrefix:forApiKeyPrefixIdentifier:`.
*/ */
@property (readonly, nonatomic, strong) NSDictionary *apiKeyPrefix; @property (readonly, nonatomic, strong) NSDictionary *apiKeyPrefix;
/** /**
* Usename and Password for Basic type Authentication * Usename for HTTP Basic Authentication
*/
@property (nonatomic) NSString *username;
/**
* Password for HTTP Basic Authentication
*/ */
@property (nonatomic) NSString *username;
@property (nonatomic) NSString *password; @property (nonatomic) NSString *password;
/** /**
@ -31,9 +41,21 @@
/** /**
* Logging Settings * Logging Settings
*/ */
/**
* Debug switch, default false
*/
@property (nonatomic) BOOL debug; @property (nonatomic) BOOL debug;
/**
* Debug file location, default nil
*/
@property (nonatomic) NSString *loggingFile; @property (nonatomic) NSString *loggingFile;
@property (nonatomic) NSFileHandle *loggingFileHanlder;
/**
* Log file handler, this property is used by sdk internally.
*/
@property (nonatomic, readonly) NSFileHandle *loggingFileHanlder;
/** /**
* Get configuration singleton instance * Get configuration singleton instance
@ -41,14 +63,39 @@
+ (instancetype) sharedConfig; + (instancetype) sharedConfig;
/** /**
* Sets field in `apiKey` * Sets field in `apiKey`.
*
* To remove a apiKey for a identifier, just set the apiKey to nil.
*
* @param apiKey The apiKey value.
* @param identifier The apiKey name.
*
*/ */
- (void) setValue:(NSString *)value forApiKeyField:(NSString*)field; - (void) setApiKey:(NSString *)apiKey forApiKeyIdentifier:(NSString*)identifier;
/**
* Remove api key
*
* @param identifier The apiKey name.
*/
- (void) removeApiKey:(NSString *)identifier;
/** /**
* Sets field in `apiKeyPrefix` * Sets field in `apiKeyPrefix`
*
* To remove a apiKeyPrefix for a identifier, just set the apiKeyPrefix to nil.
*
* @param apiKeyPrefix The apiKeyPrefix value.
* @param identifier The apiKeyPrefix name.
*/ */
- (void) setValue:(NSString *)value forApiKeyPrefixField:(NSString *)field; - (void) setApiKeyPrefix:(NSString *)prefix forApiKeyPrefixIdentifier:(NSString *)identifier;
/**
* Remove api key prefix
*
* @param identifier The apiKeyPrefix name.
*/
- (void) removeApiKeyPrefix:(NSString *)identifier;
/** /**
* Get API key (with prefix if set) * Get API key (with prefix if set)

View File

@ -60,12 +60,20 @@
#pragma mark - Setter Methods #pragma mark - Setter Methods
- (void) setValue:(NSString *)value forApiKeyField:(NSString *)field { - (void) setApiKey:(NSString *)apiKey forApiKeyIdentifier:(NSString *)identifier {
[self.mutableApiKey setValue:value forKey:field]; [self.mutableApiKey setValue:apiKey forKey:identifier];
} }
- (void) setValue:(NSString *)value forApiKeyPrefixField:(NSString *)field { - (void) removeApiKey:(NSString *)identifier {
[self.mutableApiKeyPrefix setValue:value forKey:field]; [self.mutableApiKey removeObjectForKey:identifier];
}
- (void) setApiKeyPrefix:(NSString *)prefix forApiKeyPrefixIdentifier:(NSString *)identifier {
[self.mutableApiKeyPrefix setValue:prefix forKey:identifier];
}
- (void) removeApiKeyPrefix:(NSString *)identifier {
[self.mutableApiKeyPrefix removeObjectForKey:identifier];
} }
- (void) setLoggingFile:(NSString *)loggingFile { - (void) setLoggingFile:(NSString *)loggingFile {
@ -75,10 +83,10 @@
} }
_loggingFile = loggingFile; _loggingFile = loggingFile;
self.loggingFileHanlder = [NSFileHandle fileHandleForWritingAtPath:_loggingFile]; _loggingFileHanlder = [NSFileHandle fileHandleForWritingAtPath:_loggingFile];
if (self.loggingFileHanlder == nil) { if (_loggingFileHanlder == nil) {
[[NSFileManager defaultManager] createFileAtPath:_loggingFile contents:nil attributes:nil]; [[NSFileManager defaultManager] createFileAtPath:_loggingFile contents:nil attributes:nil];
self.loggingFileHanlder = [NSFileHandle fileHandleForWritingAtPath:_loggingFile]; _loggingFileHanlder = [NSFileHandle fileHandleForWritingAtPath:_loggingFile];
} }
} }

View File

@ -13,7 +13,7 @@
/** /**
* Indicates whether the property with the given name is optional. * Indicates whether the property with the given name is optional.
* If `propertyName` is optional, then return `YES`, or return `NO`. * If `propertyName` is optional, then return `YES`, otherwise return `NO`.
* This method is used by `JSONModel`. * This method is used by `JSONModel`.
*/ */
+ (BOOL)propertyIsOptional:(NSString *)propertyName + (BOOL)propertyIsOptional:(NSString *)propertyName
@ -29,7 +29,7 @@
} }
/** /**
* Return a string that represents the properties json of the model. * Returns a string that represents the properties json of the model.
* This method will be called when logging model object using `NSLog`. * This method will be called when logging model object using `NSLog`.
*/ */
- (NSString *)description { - (NSString *)description {

View File

@ -13,7 +13,7 @@
/** /**
* Indicates whether the property with the given name is optional. * Indicates whether the property with the given name is optional.
* If `propertyName` is optional, then return `YES`, or return `NO`. * If `propertyName` is optional, then return `YES`, otherwise return `NO`.
* This method is used by `JSONModel`. * This method is used by `JSONModel`.
*/ */
+ (BOOL)propertyIsOptional:(NSString *)propertyName + (BOOL)propertyIsOptional:(NSString *)propertyName
@ -29,7 +29,7 @@
} }
/** /**
* Return a string that represents the properties json of the model. * Returns a string that represents the properties json of the model.
* This method will be called when logging model object using `NSLog`. * This method will be called when logging model object using `NSLog`.
*/ */
- (NSString *)description { - (NSString *)description {

View File

@ -13,7 +13,7 @@
/** /**
* Indicates whether the property with the given name is optional. * Indicates whether the property with the given name is optional.
* If `propertyName` is optional, then return `YES`, or return `NO`. * If `propertyName` is optional, then return `YES`, otherwise return `NO`.
* This method is used by `JSONModel`. * This method is used by `JSONModel`.
*/ */
+ (BOOL)propertyIsOptional:(NSString *)propertyName + (BOOL)propertyIsOptional:(NSString *)propertyName
@ -29,7 +29,7 @@
} }
/** /**
* Return a string that represents the properties json of the model. * Returns a string that represents the properties json of the model.
* This method will be called when logging model object using `NSLog`. * This method will be called when logging model object using `NSLog`.
*/ */
- (NSString *)description { - (NSString *)description {

View File

@ -13,7 +13,7 @@
/** /**
* Indicates whether the property with the given name is optional. * Indicates whether the property with the given name is optional.
* If `propertyName` is optional, then return `YES`, or return `NO`. * If `propertyName` is optional, then return `YES`, otherwise return `NO`.
* This method is used by `JSONModel`. * This method is used by `JSONModel`.
*/ */
+ (BOOL)propertyIsOptional:(NSString *)propertyName + (BOOL)propertyIsOptional:(NSString *)propertyName
@ -29,7 +29,7 @@
} }
/** /**
* Return a string that represents the properties json of the model. * Returns a string that represents the properties json of the model.
* This method will be called when logging model object using `NSLog`. * This method will be called when logging model object using `NSLog`.
*/ */
- (NSString *)description { - (NSString *)description {

View File

@ -8,6 +8,7 @@
#import "SWGViewController.h" #import "SWGViewController.h"
#import <SwaggerClient/SWGPet.h> #import <SwaggerClient/SWGPet.h>
#import <SwaggerClient/SWGConfiguration.h>
@interface SWGViewController () @interface SWGViewController ()
@ -18,8 +19,11 @@
- (void)viewDidLoad - (void)viewDidLoad
{ {
[super viewDidLoad]; [super viewDidLoad];
SWGPet *pet = [self createPet]; SWGConfiguration *config = [SWGConfiguration sharedConfig];
NSLog(@"%@", pet); [config setApiKey:@"hello" forApiKeyIdentifier:@"world"];
[config setApiKey:@"geekerzp" forApiKeyIdentifier:@"zp"];
[config removeApiKey:@"zp"];
NSLog(@"%@", config.apiKey);
} }
- (void)didReceiveMemoryWarning - (void)didReceiveMemoryWarning

View File

@ -61,8 +61,8 @@
- (void)testConfiguration { - (void)testConfiguration {
SWGConfiguration *config = [SWGConfiguration sharedConfig]; SWGConfiguration *config = [SWGConfiguration sharedConfig];
[config setValue:@"123456" forApiKeyField:@"api_key"]; [config setApiKey:@"123456" forApiKeyIdentifier:@"api_key"];
[config setValue:@"PREFIX" forApiKeyPrefixField:@"api_key"]; [config setApiKeyPrefix:@"PREFIX" forApiKeyPrefixIdentifier:@"api_key"];
config.username = @"test_username"; config.username = @"test_username";
config.password = @"test_password"; config.password = @"test_password";