Feature/objc tasks 2.3.0 (#3522)

* change api and ApiClient to return cancellable NSURLSessionTasks instead of NSNumber

* define a configuration protocol for custom configurations, which can be passed to api clients instead of a global configuration, provide a default implementation with a singleton option

* integrate a workaround for a current JSONModel concurrency bug

* update to new ISO8601 pod

* add missing call to super

* integrate new templates into codegen

* updates documentation templates

* updates petstore objc generated code

* fixes objc client tests
This commit is contained in:
Wolfgang Berger
2016-08-16 15:15:23 +02:00
committed by wing328
parent 4c8c969515
commit 500f41902e
66 changed files with 4367 additions and 2526 deletions

View File

@@ -245,8 +245,8 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
supportingFiles.add(new SupportingFile("Object-body.mustache", coreFileFolder(), classPrefix + "Object.m"));
supportingFiles.add(new SupportingFile("QueryParamCollection-header.mustache", coreFileFolder(), classPrefix + "QueryParamCollection.h"));
supportingFiles.add(new SupportingFile("QueryParamCollection-body.mustache", coreFileFolder(), classPrefix + "QueryParamCollection.m"));
supportingFiles.add(new SupportingFile("ApiClient-header.mustache", coreFileFolder(), classPrefix + "ApiClient.h"));
supportingFiles.add(new SupportingFile("ApiClient-body.mustache", coreFileFolder(), classPrefix + "ApiClient.m"));
supportingFiles.add(new SupportingFile("ApiClient-header.mustache", coreFileFolder(), classPrefix + "ApiClient.h"));
supportingFiles.add(new SupportingFile("ApiClient-body.mustache", coreFileFolder(), classPrefix + "ApiClient.m"));
supportingFiles.add(new SupportingFile("JSONResponseSerializer-header.mustache", coreFileFolder(), classPrefix + "JSONResponseSerializer.h"));
supportingFiles.add(new SupportingFile("JSONResponseSerializer-body.mustache", coreFileFolder(), classPrefix + "JSONResponseSerializer.m"));
supportingFiles.add(new SupportingFile("JSONRequestSerializer-body.mustache", coreFileFolder(), classPrefix + "JSONRequestSerializer.m"));
@@ -259,8 +259,11 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
supportingFiles.add(new SupportingFile("Logger-header.mustache", coreFileFolder(), classPrefix + "Logger.h"));
supportingFiles.add(new SupportingFile("JSONValueTransformer+ISO8601-body.mustache", coreFileFolder(), "JSONValueTransformer+ISO8601.m"));
supportingFiles.add(new SupportingFile("JSONValueTransformer+ISO8601-header.mustache", coreFileFolder(), "JSONValueTransformer+ISO8601.h"));
supportingFiles.add(new SupportingFile("Configuration-body.mustache", coreFileFolder(), classPrefix + "Configuration.m"));
supportingFiles.add(new SupportingFile("Configuration-header.mustache", coreFileFolder(), classPrefix + "Configuration.h"));
supportingFiles.add(new SupportingFile("Configuration-protocol.mustache", coreFileFolder(), classPrefix + "Configuration.h"));
supportingFiles.add(new SupportingFile("DefaultConfiguration-body.mustache", coreFileFolder(), classPrefix + "DefaultConfiguration.m"));
supportingFiles.add(new SupportingFile("DefaultConfiguration-header.mustache", coreFileFolder(), classPrefix + "DefaultConfiguration.h"));
supportingFiles.add(new SupportingFile("BasicAuthTokenProvider-header.mustache", coreFileFolder(), classPrefix + "BasicAuthTokenProvider.h"));
supportingFiles.add(new SupportingFile("BasicAuthTokenProvider-body.mustache", coreFileFolder(), classPrefix + "BasicAuthTokenProvider.m"));
supportingFiles.add(new SupportingFile("api-protocol.mustache", coreFileFolder(), classPrefix + "Api.h"));
supportingFiles.add(new SupportingFile("podspec.mustache", "", podName + ".podspec"));
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));

View File

@@ -1,10 +1,16 @@
#import <ISO8601/NSDate+ISO8601.h>
#import "{{classPrefix}}ApiClient.h"
#import "{{classPrefix}}JSONRequestSerializer.h"
#import "{{classPrefix}}JSONResponseSerializer.h"
#import "{{classPrefix}}QueryParamCollection.h"
#import "{{classPrefix}}DefaultConfiguration.h"
NSString *const {{classPrefix}}ResponseObjectErrorKey = @"{{classPrefix}}ResponseObject";
static NSUInteger requestId = 0;
static bool offlineState = false;
static NSMutableSet * queuedRequests = nil;
static bool cacheEnabled = false;
static AFNetworkReachabilityStatus reachabilityStatus = AFNetworkReachabilityStatusNotReachable;
static void (^reachabilityChangeBlock)(int);
@@ -36,38 +42,61 @@ static NSString * {{classPrefix}}__fileNameForResponse(NSURLResponse *response)
@interface {{classPrefix}}ApiClient ()
@property (nonatomic, strong) NSDictionary* HTTPResponseHeaders;
@property (nonatomic, strong, readwrite) id<{{classPrefix}}Configuration> configuration;
@end
@implementation {{classPrefix}}ApiClient
#pragma mark - Singleton Methods
+ (instancetype) sharedClient {
static {{classPrefix}}ApiClient *sharedClient = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedClient = [[self alloc] init];
});
return sharedClient;
}
#pragma mark - Initialize Methods
- (instancetype)init {
NSString *baseUrl = [[{{classPrefix}}Configuration sharedConfig] host];
return [self initWithBaseURL:[NSURL URLWithString:baseUrl]];
return [self initWithConfiguration:[{{classPrefix}}DefaultConfiguration sharedConfig]];
}
- (instancetype)initWithBaseURL:(NSURL *)url {
return [self initWithBaseURL:url
configuration:[{{classPrefix}}DefaultConfiguration sharedConfig]];
}
- (instancetype)initWithConfiguration:(id<{{classPrefix}}Configuration>)configuration {
return [self initWithBaseURL:[NSURL URLWithString:configuration.host] configuration:configuration];
}
- (instancetype)initWithBaseURL:(NSURL *)url
configuration:(id<{{classPrefix}}Configuration>)configuration {
self = [super initWithBaseURL:url];
if (self) {
self.timeoutInterval = 60;
_configuration = configuration;
_timeoutInterval = 60;
_responseDeserializer = [[{{classPrefix}}ResponseDeserializer alloc] init];
_sanitizer = [[{{classPrefix}}Sanitizer alloc] init];
self.requestSerializer = [AFJSONRequestSerializer serializer];
self.responseSerializer = [AFJSONResponseSerializer serializer];
self.securityPolicy = [self customSecurityPolicy];
self.responseDeserializer = [[{{classPrefix}}ResponseDeserializer alloc] init];
self.sanitizer = [[{{classPrefix}}Sanitizer alloc] init];
// configure reachability
[self configureCacheReachibility];
}
return self;
}
+ (void)initialize {
if (self == [{{classPrefix}}ApiClient class]) {
queuedRequests = [[NSMutableSet alloc] init];
// initialize URL cache
[self configureCacheWithMemoryAndDiskCapacity:4*1024*1024 diskSize:32*1024*1024];
}
return self;
}
#pragma mark - Setter Methods
@@ -113,43 +142,6 @@ static NSString * {{classPrefix}}__fileNameForResponse(NSURLResponse *response)
[NSURLCache setSharedURLCache:cache];
}
#pragma mark - Request Methods
+(NSUInteger)requestQueueSize {
return [queuedRequests count];
}
+(NSNumber*) nextRequestId {
@synchronized(self) {
return @(++requestId);
}
}
+(NSNumber*) queueRequest {
NSNumber* requestId = [[self class] nextRequestId];
{{classPrefix}}DebugLog(@"added %@ to request queue", requestId);
[queuedRequests addObject:requestId];
return requestId;
}
+(void) cancelRequest:(NSNumber*)requestId {
[queuedRequests removeObject:requestId];
}
-(Boolean) executeRequestWithId:(NSNumber*) requestId {
NSSet* matchingItems = [queuedRequests objectsPassingTest:^BOOL(id obj, BOOL *stop) {
return [obj intValue] == [requestId intValue];
}];
if (matchingItems.count == 1) {
{{classPrefix}}DebugLog(@"removed request id %@", requestId);
[queuedRequests removeObject:requestId];
return YES;
} else {
return NO;
}
}
#pragma mark - Reachability Methods
+(AFNetworkReachabilityStatus) getReachabilityStatus {
@@ -179,23 +171,19 @@ static NSString * {{classPrefix}}__fileNameForResponse(NSURLResponse *response)
[self.reachabilityManager startMonitoring];
}
#pragma mark - Operation Methods
#pragma mark - Task Methods
- (void) operationWithCompletionBlock: (NSURLRequest *)request
requestId: (NSNumber *) requestId
completionBlock: (void (^)(id, NSError *))completionBlock {
__weak __typeof(self)weakSelf = self;
NSURLSessionDataTask* op = [self dataTaskWithRequest:request completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
__strong __typeof(weakSelf)strongSelf = weakSelf;
if (![strongSelf executeRequestWithId:requestId]) {
return;
}
- (NSURLSessionDataTask*) taskWithCompletionBlock: (NSURLRequest *)request
completionBlock: (void (^)(id, NSError *))completionBlock {
NSURLSessionDataTask *task = [self dataTaskWithRequest:request completionHandler:^(NSURLResponse * _Nonnull response, id _Nullable responseObject, NSError * _Nullable error) {
{{classPrefix}}DebugLogResponse(response, responseObject,request,error);
strongSelf.HTTPResponseHeaders = {{classPrefix}}__headerFieldsForResponse(response);
if(!error) {
completionBlock(responseObject, nil);
return;
}
NSMutableDictionary *userInfo = [error.userInfo mutableCopy];
if (responseObject) {
// Add in the (parsed) response body.
@@ -204,20 +192,18 @@ static NSString * {{classPrefix}}__fileNameForResponse(NSURLResponse *response)
NSError *augmentedError = [error initWithDomain:error.domain code:error.code userInfo:userInfo];
completionBlock(nil, augmentedError);
}];
[op resume];
return task;
}
- (void) downloadOperationWithCompletionBlock: (NSURLRequest *)request
requestId: (NSNumber *) requestId
completionBlock: (void (^)(id, NSError *))completionBlock {
__weak __typeof(self)weakSelf = self;
NSURLSessionDataTask* op = [self dataTaskWithRequest:request completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
__strong __typeof(weakSelf)strongSelf = weakSelf;
if (![strongSelf executeRequestWithId:requestId]) {
return;
}
strongSelf.HTTPResponseHeaders = {{classPrefix}}__headerFieldsForResponse(response);
- (NSURLSessionDataTask*) downloadTaskWithCompletionBlock: (NSURLRequest *)request
completionBlock: (void (^)(id, NSError *))completionBlock {
id<{{classPrefix}}Configuration> config = self.configuration;
NSURLSessionDataTask* task = [self dataTaskWithRequest:request completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
{{classPrefix}}DebugLogResponse(response, responseObject,request,error);
if(error) {
NSMutableDictionary *userInfo = [error.userInfo mutableCopy];
if (responseObject) {
@@ -226,8 +212,9 @@ static NSString * {{classPrefix}}__fileNameForResponse(NSURLResponse *response)
NSError *augmentedError = [error initWithDomain:error.domain code:error.code userInfo:userInfo];
completionBlock(nil, augmentedError);
}
NSString *directory = [self configuration].tempFolderPath ?: NSTemporaryDirectory();
NSString * filename = {{classPrefix}}__fileNameForResponse(response);
NSString *directory = config.tempFolderPath ?: NSTemporaryDirectory();
NSString *filename = {{classPrefix}}__fileNameForResponse(response);
NSString *filepath = [directory stringByAppendingPathComponent:filename];
NSURL *file = [NSURL fileURLWithPath:filepath];
@@ -236,24 +223,26 @@ static NSString * {{classPrefix}}__fileNameForResponse(NSURLResponse *response)
completionBlock(file, nil);
}];
[op resume];
return task;
}
#pragma mark - Perform Request Methods
#pragma mark - Perform Request Methods
- (NSURLSessionTask*) requestWithPath: (NSString*) path
method: (NSString*) method
pathParams: (NSDictionary *) pathParams
queryParams: (NSDictionary*) queryParams
formParams: (NSDictionary *) formParams
files: (NSDictionary *) files
body: (id) body
headerParams: (NSDictionary*) headerParams
authSettings: (NSArray *) authSettings
requestContentType: (NSString*) requestContentType
responseContentType: (NSString*) responseContentType
responseType: (NSString *) responseType
completionBlock: (void (^)(id, NSError *))completionBlock {
-(NSNumber*) requestWithPath: (NSString*) path
method: (NSString*) method
pathParams: (NSDictionary *) pathParams
queryParams: (NSDictionary*) queryParams
formParams: (NSDictionary *) formParams
files: (NSDictionary *) files
body: (id) body
headerParams: (NSDictionary*) headerParams
authSettings: (NSArray *) authSettings
requestContentType: (NSString*) requestContentType
responseContentType: (NSString*) responseContentType
responseType: (NSString *) responseType
completionBlock: (void (^)(id, NSError *))completionBlock {
// setting request serializer
if ([requestContentType isEqualToString:@"application/json"]) {
self.requestSerializer = [{{classPrefix}}JSONRequestSerializer serializer];
@@ -359,14 +348,16 @@ static NSString * {{classPrefix}}__fileNameForResponse(NSURLResponse *response)
[self postProcessRequest:request];
NSNumber* requestId = [{{classPrefix}}ApiClient queueRequest];
NSURLSessionTask *task = nil;
if ([responseType isEqualToString:@"NSURL*"] || [responseType isEqualToString:@"NSURL"]) {
[self downloadOperationWithCompletionBlock:request requestId:requestId completionBlock:^(id data, NSError *error) {
task = [self downloadTaskWithCompletionBlock:request completionBlock:^(id data, NSError *error) {
completionBlock(data, error);
}];
}
else {
[self operationWithCompletionBlock:request requestId:requestId completionBlock:^(id data, NSError *error) {
task = [self taskWithCompletionBlock:request completionBlock:^(id data, NSError *error) {
NSError * serializationError;
id response = [self.responseDeserializer deserialize:data class:responseType error:&serializationError];
if(!response && !error){
@@ -375,7 +366,10 @@ static NSString * {{classPrefix}}__fileNameForResponse(NSURLResponse *response)
completionBlock(response, error);
}];
}
return requestId;
[task resume];
return task;
}
//Added for easier override to modify request
@@ -455,10 +449,11 @@ static NSString * {{classPrefix}}__fileNameForResponse(NSURLResponse *response)
NSMutableDictionary *headersWithAuth = [NSMutableDictionary dictionaryWithDictionary:*headers];
NSMutableDictionary *querysWithAuth = [NSMutableDictionary dictionaryWithDictionary:*querys];
NSDictionary* configurationAuthSettings = [[self configuration] authSettings];
id<{{classPrefix}}Configuration> config = self.configuration;
for (NSString *auth in authSettings) {
NSDictionary *authSetting = configurationAuthSettings[auth];
NSDictionary *authSetting = config.authSettings[auth];
if(!authSetting) { // auth setting is set only if the key is non-empty
continue;
}
@@ -479,11 +474,11 @@ static NSString * {{classPrefix}}__fileNameForResponse(NSURLResponse *response)
- (AFSecurityPolicy *) customSecurityPolicy {
AFSecurityPolicy *securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeNone];
{{classPrefix}}Configuration *config = [self configuration];
id<{{classPrefix}}Configuration> config = self.configuration;
if (config.sslCaCert) {
NSData *certData = [NSData dataWithContentsOfFile:config.sslCaCert];
[securityPolicy setPinnedCertificates:@[certData]];
[securityPolicy setPinnedCertificates:[NSSet setWithObject:certData]];
}
if (config.verifySSL) {
@@ -497,8 +492,4 @@ static NSString * {{classPrefix}}__fileNameForResponse(NSURLResponse *response)
return securityPolicy;
}
- ({{classPrefix}}Configuration*) configuration {
return [{{classPrefix}}Configuration sharedConfig];
}
@end

View File

@@ -1,22 +1,10 @@
#import <Foundation/Foundation.h>
#import <ISO8601/ISO8601.h>
#import <AFNetworking/AFNetworking.h>
#import "{{classPrefix}}JSONResponseSerializer.h"
#import "{{classPrefix}}JSONRequestSerializer.h"
#import "{{classPrefix}}QueryParamCollection.h"
#import "{{classPrefix}}Configuration.h"
#import "{{classPrefix}}ResponseDeserializer.h"
#import "{{classPrefix}}Sanitizer.h"
#import "{{classPrefix}}Logger.h"
{{>licenceInfo}}
{{#models}}{{#model}}#import "{{classname}}.h"
{{/model}}{{/models}}
{{^models}}#import "{{classPrefix}}Object.h"{{/models}}
@class {{classPrefix}}Configuration;
/**
* A key for `NSError` user info dictionaries.
*
@@ -24,15 +12,15 @@
*/
extern NSString *const {{classPrefix}}ResponseObjectErrorKey;
@interface {{classPrefix}}ApiClient : AFHTTPSessionManager
@property (nonatomic, strong, readonly) id<{{classPrefix}}Configuration> configuration;
@property(nonatomic, assign) NSURLRequestCachePolicy cachePolicy;
@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;
@property(nonatomic, strong) id<{{classPrefix}}ResponseDeserializer> responseDeserializer;
@property(nonatomic, strong) id<{{classPrefix}}Sanitizer> sanitizer;
@@ -48,13 +36,6 @@ extern NSString *const {{classPrefix}}ResponseObjectErrorKey;
*/
+(void)setCacheEnabled:(BOOL) enabled;
/**
* Gets the request queue size
*
* @return The size of `queuedRequests` static variable.
*/
+(NSUInteger)requestQueueSize;
/**
* Sets the client unreachable
*
@@ -83,27 +64,6 @@ extern NSString *const {{classPrefix}}ResponseObjectErrorKey;
*/
+(AFNetworkReachabilityStatus) getReachabilityStatus;
/**
* Gets the next request id
*
* @return The next executed request id.
*/
+(NSNumber*) nextRequestId;
/**
* Generates request id and add it to the queue
*
* @return The next executed request id.
*/
+(NSNumber*) queueRequest;
/**
* Removes request id from the queue
*
* @param requestId The request which will be removed.
*/
+(void) cancelRequest:(NSNumber*)requestId;
/**
* Customizes the behavior when the reachability changed
*
@@ -111,6 +71,11 @@ extern NSString *const {{classPrefix}}ResponseObjectErrorKey;
*/
+(void) setReachabilityChangeBlock:(void(^)(int))changeBlock;
/**
* Gets client singleton instance
*/
+ (instancetype) sharedClient;
/**
* Sets the api client reachability strategy
*/
@@ -136,6 +101,14 @@ extern NSString *const {{classPrefix}}ResponseObjectErrorKey;
queryParams:(NSDictionary **)querys
WithAuthSettings:(NSArray *)authSettings;
/**
* Initializes the session manager with a configuration.
*
* @param configuration The configuration implementation
*/
- (instancetype)initWithConfiguration:(id<{{classPrefix}}Configuration>)configuration;
/**
* Performs request
*
@@ -150,21 +123,21 @@ extern NSString *const {{classPrefix}}ResponseObjectErrorKey;
* @param responseContentType Response content-type.
* @param completionBlock The block will be executed when the request completed.
*
* @return The request id.
* @return The created session task.
*/
-(NSNumber*) requestWithPath:(NSString*) path
method:(NSString*) method
pathParams:(NSDictionary *) pathParams
queryParams:(NSDictionary*) queryParams
formParams:(NSDictionary *) formParams
files:(NSDictionary *) files
body:(id) body
headerParams:(NSDictionary*) headerParams
authSettings:(NSArray *) authSettings
requestContentType:(NSString*) requestContentType
responseContentType:(NSString*) responseContentType
responseType:(NSString *) responseType
completionBlock:(void (^)(id, NSError *))completionBlock;
- (NSURLSessionTask*) requestWithPath: (NSString*) path
method: (NSString*) method
pathParams: (NSDictionary *) pathParams
queryParams: (NSDictionary*) queryParams
formParams: (NSDictionary *) formParams
files: (NSDictionary *) files
body: (id) body
headerParams: (NSDictionary*) headerParams
authSettings: (NSArray *) authSettings
requestContentType: (NSString*) requestContentType
responseContentType: (NSString*) responseContentType
responseType: (NSString *) responseType
completionBlock: (void (^)(id, NSError *))completionBlock;
/**
* Custom security policy
@@ -173,12 +146,4 @@ extern NSString *const {{classPrefix}}ResponseObjectErrorKey;
*/
- (AFSecurityPolicy *) customSecurityPolicy;
/**
* {{classPrefix}}Configuration return sharedConfig
*
* @return {{classPrefix}}Configuration
*/
- ({{classPrefix}}Configuration*) configuration;
@end

View File

@@ -0,0 +1,19 @@
#import "{{classPrefix}}BasicAuthTokenProvider.h"
@implementation {{classPrefix}}BasicAuthTokenProvider
+ (NSString *)createBasicAuthTokenWithUsername:(NSString *)username password:(NSString *)password {
// return empty string if username and password are empty
if (username.length == 0 && password.length == 0){
return @"";
}
NSString *basicAuthCredentials = [NSString stringWithFormat:@"%@:%@", username, password];
NSData *data = [basicAuthCredentials dataUsingEncoding:NSUTF8StringEncoding];
basicAuthCredentials = [NSString stringWithFormat:@"Basic %@", [data base64EncodedStringWithOptions:0]];
return basicAuthCredentials;
}
@end

View File

@@ -0,0 +1,14 @@
/** The `{{classPrefix}}BasicAuthTokenProvider` class creates a basic auth token from username and password.
*
* 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.
*/
#import <Foundation/Foundation.h>
@interface {{classPrefix}}BasicAuthTokenProvider : NSObject
+ (NSString *)createBasicAuthTokenWithUsername:(NSString *)username password:(NSString *)password;
@end

View File

@@ -0,0 +1,75 @@
#import <Foundation/Foundation.h>
#import "{{classPrefix}}Logger.h"
{{>licenceInfo}}
@protocol {{classPrefix}}Configuration <NSObject>
/**
* Api logger
*/
@property (readonly, nonatomic) {{classPrefix}}Logger *logger;
/**
* Base url
*/
@property (readonly, nonatomic) NSString *host;
/**
* Api key values for Api Key type Authentication
*/
@property (readonly, nonatomic) NSDictionary *apiKey;
/**
* Api key prefix values to be prepend to the respective api key
*/
@property (readonly, nonatomic) NSDictionary *apiKeyPrefix;
/**
* Username for HTTP Basic Authentication
*/
@property (readonly, nonatomic) NSString *username;
/**
* Password for HTTP Basic Authentication
*/
@property (readonly, nonatomic) NSString *password;
/**
* Access token for OAuth
*/
@property (readonly, nonatomic) NSString *accessToken;
/**
* Temp folder for file download
*/
@property (readonly, nonatomic) NSString *tempFolderPath;
/**
* Debug switch, default false
*/
@property (readonly, nonatomic) BOOL debug;
/**
* SSL/TLS verification
* Set this to NO to skip verifying SSL certificate when calling API from https server
*/
@property (readonly, nonatomic) BOOL verifySSL;
/**
* SSL/TLS verification
* Set this to customize the certificate file to verify the peer
*/
@property (readonly, nonatomic) NSString *sslCaCert;
/**
* Authentication Settings
*/
@property (readonly, nonatomic) NSDictionary *authSettings;
/**
* Default headers for all services
*/
@property (readonly, nonatomic, strong) NSDictionary *defaultHeaders;
@end

View File

@@ -1,6 +1,7 @@
#import "{{classPrefix}}Configuration.h"
#import "{{classPrefix}}DefaultConfiguration.h"
#import "{{classPrefix}}BasicAuthTokenProvider.h"
@interface {{classPrefix}}Configuration ()
@interface {{classPrefix}}DefaultConfiguration ()
@property (nonatomic, strong) NSMutableDictionary *mutableDefaultHeaders;
@property (nonatomic, strong) NSMutableDictionary *mutableApiKey;
@@ -8,12 +9,12 @@
@end
@implementation {{classPrefix}}Configuration
@implementation {{classPrefix}}DefaultConfiguration
#pragma mark - Singleton Methods
+ (instancetype) sharedConfig {
static {{classPrefix}}Configuration *shardConfig = nil;
static {{classPrefix}}DefaultConfiguration *shardConfig = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
shardConfig = [[self alloc] init];
@@ -26,17 +27,16 @@
- (instancetype) init {
self = [super init];
if (self) {
self.apiClient = nil;
self.host = @"{{basePath}}";
self.username = @"";
self.password = @"";
self.accessToken= @"";
self.verifySSL = YES;
self.mutableApiKey = [NSMutableDictionary dictionary];
self.mutableApiKeyPrefix = [NSMutableDictionary dictionary];
self.mutableDefaultHeaders = [NSMutableDictionary dictionary];
self.mutableDefaultHeaders[@"User-Agent"] = {{#httpUserAgent}}@"{{httpUserAgent}}"{{/httpUserAgent}}{{^httpUserAgent}}[NSString stringWithFormat:@"Swagger-Codegen/{{version}}/objc (%@; iOS %@; Scale/%0.2f)",[[UIDevice currentDevice] model], [[UIDevice currentDevice] systemVersion], [[UIScreen mainScreen] scale]]{{/httpUserAgent}};
self.logger = [{{classPrefix}}Logger sharedLogger];
_host = @"{{basePath}}";
_username = @"";
_password = @"";
_accessToken= @"";
_verifySSL = YES;
_mutableApiKey = [NSMutableDictionary dictionary];
_mutableApiKeyPrefix = [NSMutableDictionary dictionary];
_mutableDefaultHeaders = [NSMutableDictionary dictionary];
{{#httpUserAgent}}_mutableDefaultHeaders[@"User-Agent"] = @"{{httpUserAgent}}"{{/httpUserAgent}};
_logger = [{{classPrefix}}Logger sharedLogger];
}
return self;
}
@@ -58,16 +58,9 @@
}
- (NSString *) getBasicAuthToken {
// return empty string if username and password are empty
if (self.username.length == 0 && self.password.length == 0){
return @"";
}
NSString *basicAuthCredentials = [NSString stringWithFormat:@"%@:%@", self.username, self.password];
NSData *data = [basicAuthCredentials dataUsingEncoding:NSUTF8StringEncoding];
basicAuthCredentials = [NSString stringWithFormat:@"Basic %@", [data base64EncodedStringWithOptions:0]];
return basicAuthCredentials;
NSString *basicAuthToken = [{{classPrefix}}BasicAuthTokenProvider createBasicAuthTokenWithUsername:self.username password:self.password];
return basicAuthToken;
}
- (NSString *) getAccessToken {

View File

@@ -1,23 +1,16 @@
#import <Foundation/Foundation.h>
#import "{{classPrefix}}ApiClient.h"
#import "{{classPrefix}}Logger.h"
#import "{{classPrefix}}Configuration.h"
{{>licenceInfo}}
@class {{classPrefix}}ApiClient;
@interface {{classPrefix}}DefaultConfiguration : NSObject <{{classPrefix}}Configuration>
@interface {{classPrefix}}Configuration : NSObject
/**
* Default api logger
*/
@property (nonatomic, strong) {{classPrefix}}Logger * logger;
/**
* Default api client
*/
@property (nonatomic) {{classPrefix}}ApiClient *apiClient;
/**
* Default base url
*/

View File

@@ -1,3 +1,4 @@
#import <ISO8601/NSDate+ISO8601.h>
#import "JSONValueTransformer+ISO8601.h"
@implementation JSONValueTransformer (ISO8601)

View File

@@ -1,5 +1,4 @@
#import <Foundation/Foundation.h>
#import <ISO8601/ISO8601.h>
#import <JSONModel/JSONValueTransformer.h>
{{>licenceInfo}}

View File

@@ -2,6 +2,35 @@
@implementation {{classPrefix}}Object
/**
* Workaround for JSONModel multithreading issues
* https://github.com/icanzilb/JSONModel/issues/441
*/
- (instancetype)initWithDictionary:(NSDictionary *)dict error:(NSError **)err {
static NSMutableSet *classNames;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
classNames = [NSMutableSet new];
});
BOOL initSync;
@synchronized([self class])
{
NSString *className = NSStringFromClass([self class]);
initSync = ![classNames containsObject:className];
if(initSync)
{
[classNames addObject:className];
self = [super initWithDictionary:dict error:err];
}
}
if(!initSync)
{
self = [super initWithDictionary:dict error:err];
}
return self;
}
/**
* Gets the string presentation of the object.
* This method will be called when logging model object using `NSLog`.

View File

@@ -5,11 +5,15 @@
@synthesize values = _values;
@synthesize format = _format;
- (id) initWithValuesAndFormat: (NSArray*) values
format: (NSString*) format {
_values = values;
_format = format;
- (id)initWithValuesAndFormat:(NSArray *)values
format:(NSString *)format {
self = [super init];
if (self) {
_values = values;
_format = format;
}
return self;
}

View File

@@ -45,7 +45,7 @@ Import the following:
```objc
#import <{{podName}}/{{{classPrefix}}}ApiClient.h>
#import <{{podName}}/{{{classPrefix}}}Configuration.h>
#import <{{podName}}/{{{classPrefix}}}DefaultConfiguration.h>
// load models
{{#models}}{{#model}}#import <{{podName}}/{{{classname}}}.h>
{{/model}}{{/models}}// load API classes for accessing endpoints
@@ -64,7 +64,7 @@ Please follow the [installation procedure](#installation--usage) and then run th
```objc
{{#apiInfo}}{{#apis}}{{#-first}}{{#operations}}{{#operation}}{{#-first}}
{{#hasAuthMethods}}
{{classPrefix}}Configuration *apiConfig = [{{classPrefix}}Configuration sharedConfig];
{{classPrefix}}DefaultConfiguration *apiConfig = [{{classPrefix}}DefaultConfiguration sharedConfig];
{{#authMethods}}{{#isBasic}}// Configure HTTP basic authorization (authentication scheme: {{{name}}})
[apiConfig setUsername:@"YOUR_USERNAME"];
[apiConfig setPassword:@"YOUR_PASSWORD"];

View File

@@ -7,7 +7,7 @@
@interface {{classname}} ()
@property (nonatomic, strong) NSMutableDictionary *defaultHeaders;
@property (nonatomic, strong, readwrite) NSMutableDictionary *defaultHeaders;
@end
@@ -21,19 +21,11 @@ NSInteger k{{classname}}MissingParamErrorCode = 234513;
#pragma mark - Initialize methods
- (instancetype) init {
self = [super init];
if (self) {
{{classPrefix}}Configuration *config = [{{classPrefix}}Configuration sharedConfig];
if (config.apiClient == nil) {
config.apiClient = [[{{classPrefix}}ApiClient alloc] init];
}
_apiClient = config.apiClient;
_defaultHeaders = [NSMutableDictionary dictionary];
}
return self;
return [self initWithApiClient:[{{classPrefix}}ApiClient sharedClient]];
}
- (id) initWithApiClient:({{classPrefix}}ApiClient *)apiClient {
-(instancetype) initWithApiClient:({{classPrefix}}ApiClient *)apiClient {
self = [super init];
if (self) {
_apiClient = apiClient;
@@ -44,15 +36,6 @@ NSInteger k{{classname}}MissingParamErrorCode = 234513;
#pragma mark -
+ (instancetype)sharedAPI {
static {{classname}} *sharedAPI;
static dispatch_once_t once;
dispatch_once(&once, ^{
sharedAPI = [[self alloc] init];
});
return sharedAPI;
}
-(NSString*) defaultHeaderForKey:(NSString*)key {
return self.defaultHeaders[key];
}
@@ -65,10 +48,6 @@ NSInteger k{{classname}}MissingParamErrorCode = 234513;
[self.defaultHeaders setValue:value forKey:key];
}
-(NSUInteger) requestQueueSize {
return [{{classPrefix}}ApiClient requestQueueSize];
}
#pragma mark - Api Methods
{{#operation}}
@@ -79,7 +58,7 @@ NSInteger k{{classname}}MissingParamErrorCode = 234513;
///
/// {{/allParams}} @returns {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}
///
-(NSNumber*) {{#vendorExtensions.x-objc-operationId}}{{vendorExtensions.x-objc-operationId}}{{/vendorExtensions.x-objc-operationId}}{{^vendorExtensions.x-objc-operationId}}{{nickname}}{{#hasParams}}With{{vendorExtensions.firstParamAltName}}{{/hasParams}}{{^hasParams}}WithCompletionHandler: {{/hasParams}}{{/vendorExtensions.x-objc-operationId}}{{#allParams}}{{#secondaryParam}}
-(NSURLSessionTask*) {{#vendorExtensions.x-objc-operationId}}{{vendorExtensions.x-objc-operationId}}{{/vendorExtensions.x-objc-operationId}}{{^vendorExtensions.x-objc-operationId}}{{nickname}}{{#hasParams}}With{{vendorExtensions.firstParamAltName}}{{/hasParams}}{{^hasParams}}WithCompletionHandler: {{/hasParams}}{{/vendorExtensions.x-objc-operationId}}{{#allParams}}{{#secondaryParam}}
{{paramName}}{{/secondaryParam}}: ({{{dataType}}}) {{paramName}}{{/allParams}}
{{#hasParams}}completionHandler: {{/hasParams}}(void (^)({{#returnBaseType}}{{{returnType}}} output, {{/returnBaseType}}NSError* error)) handler {
{{#allParams}}
@@ -175,8 +154,7 @@ NSInteger k{{classname}}MissingParamErrorCode = 234513;
if(handler) {
handler({{#returnType}}({{{ returnType }}})data, {{/returnType}}error);
}
}
];
}];
}
{{/operation}}

View File

@@ -11,7 +11,7 @@
extern NSString* k{{classname}}ErrorDomain;
extern NSInteger k{{classname}}MissingParamErrorCode;
+(instancetype) sharedAPI;
-(instancetype) initWithApiClient:({{classPrefix}}ApiClient *)apiClient NS_DESIGNATED_INITIALIZER;
{{#operations}}
{{#operation}}
@@ -23,7 +23,7 @@ extern NSInteger k{{classname}}MissingParamErrorCode;
/// code:{{{code}}} message:"{{{message}}}"{{#hasMore}},{{/hasMore}}{{/responses}}
///
/// @return {{{returnType}}}
-(NSNumber*) {{#vendorExtensions.x-objc-operationId}}{{vendorExtensions.x-objc-operationId}}{{/vendorExtensions.x-objc-operationId}}{{^vendorExtensions.x-objc-operationId}}{{nickname}}{{#hasParams}}With{{vendorExtensions.firstParamAltName}}{{/hasParams}}{{^hasParams}}WithCompletionHandler: {{/hasParams}}{{/vendorExtensions.x-objc-operationId}}{{#allParams}}{{#secondaryParam}}
-(NSURLSessionTask*) {{#vendorExtensions.x-objc-operationId}}{{vendorExtensions.x-objc-operationId}}{{/vendorExtensions.x-objc-operationId}}{{^vendorExtensions.x-objc-operationId}}{{nickname}}{{#hasParams}}With{{vendorExtensions.firstParamAltName}}{{/hasParams}}{{^hasParams}}WithCompletionHandler: {{/hasParams}}{{/vendorExtensions.x-objc-operationId}}{{#allParams}}{{#secondaryParam}}
{{paramName}}{{/secondaryParam}}: ({{{dataType}}}) {{paramName}}{{/allParams}}
{{#hasParams}}completionHandler: {{/hasParams}}(void (^)({{#returnBaseType}}{{{returnType}}} output, {{/returnBaseType}}NSError* error)) handler;

View File

@@ -6,15 +6,13 @@
@protocol {{classPrefix}}Api <NSObject>
@property(nonatomic, assign) {{classPrefix}}ApiClient *apiClient;
@property(readonly, nonatomic, strong) {{classPrefix}}ApiClient *apiClient;
-(id) initWithApiClient:({{classPrefix}}ApiClient *)apiClient;
-(instancetype) initWithApiClient:({{classPrefix}}ApiClient *)apiClient;
-(void) addHeader:(NSString*)value forKey:(NSString*)key DEPRECATED_MSG_ATTRIBUTE("setDefaultHeaderValue:forKey:");
-(void) setDefaultHeaderValue:(NSString*) value forKey:(NSString*)key;
-(NSString*) defaultHeaderForKey:(NSString*)key;
-(NSUInteger) requestQueueSize;
@end

View File

@@ -12,7 +12,7 @@ Method | HTTP request | Description
{{#operation}}
# **{{{operationId}}}**
```objc
-(NSNumber*) {{#vendorExtensions.x-objc-operationId}}{{vendorExtensions.x-objc-operationId}}{{/vendorExtensions.x-objc-operationId}}{{^vendorExtensions.x-objc-operationId}}{{nickname}}{{#hasParams}}With{{vendorExtensions.firstParamAltName}}{{/hasParams}}{{^hasParams}}WithCompletionHandler: {{/hasParams}}{{/vendorExtensions.x-objc-operationId}}{{#allParams}}{{#secondaryParam}}
-(NSURLSessionTask*) {{#vendorExtensions.x-objc-operationId}}{{vendorExtensions.x-objc-operationId}}{{/vendorExtensions.x-objc-operationId}}{{^vendorExtensions.x-objc-operationId}}{{nickname}}{{#hasParams}}With{{vendorExtensions.firstParamAltName}}{{/hasParams}}{{^hasParams}}WithCompletionHandler: {{/hasParams}}{{/vendorExtensions.x-objc-operationId}}{{#allParams}}{{#secondaryParam}}
{{paramName}}{{/secondaryParam}}: ({{{dataType}}}) {{paramName}}{{/allParams}}
{{#hasParams}}completionHandler: {{/hasParams}}(void (^)({{#returnBaseType}}{{{returnType}}} output, {{/returnBaseType}}NSError* error)) handler;
```
@@ -24,7 +24,7 @@ Method | HTTP request | Description
### Example
```objc
{{#hasAuthMethods}}
{{classPrefix}}Configuration *apiConfig = [{{classPrefix}}Configuration sharedConfig];
{{classPrefix}}DefaultConfiguration *apiConfig = [{{classPrefix}}DefaultConfiguration sharedConfig];
{{#authMethods}}{{#isBasic}}// Configure HTTP basic authorization (authentication scheme: {{{name}}})
[apiConfig setUsername:@"YOUR_USERNAME"];
[apiConfig setPassword:@"YOUR_PASSWORD"];

View File

@@ -32,6 +32,6 @@ Pod::Spec.new do |s|
s.dependency 'AFNetworking', '~> 3'
s.dependency 'JSONModel', '~> 1.2'
s.dependency 'ISO8601', '~> 0.5'
s.dependency 'ISO8601', '~> 0.6'
end

View File

@@ -6,7 +6,7 @@ This ObjC package is automatically generated by the [Swagger Codegen](https://gi
- API version: 1.0.0
- Package version:
- Build date: 2016-07-19T16:53:26.476+08:00
- Build date: 2016-08-04T12:24:23.866+02:00
- Build package: class io.swagger.codegen.languages.ObjcClientCodegen
## Requirements
@@ -40,7 +40,7 @@ Import the following:
```objc
#import <SwaggerClient/SWGApiClient.h>
#import <SwaggerClient/SWGConfiguration.h>
#import <SwaggerClient/SWGDefaultConfiguration.h>
// load models
#import <SwaggerClient/SWGCategory.h>
#import <SwaggerClient/SWGOrder.h>
@@ -64,7 +64,7 @@ Please follow the [installation procedure](#installation--usage) and then run th
```objc
SWGConfiguration *apiConfig = [SWGConfiguration sharedConfig];
SWGDefaultConfiguration *apiConfig = [SWGDefaultConfiguration sharedConfig];
// Configure OAuth2 access token for authorization: (authentication scheme: petstore_auth)
[apiConfig setAccessToken:@"YOUR_ACCESS_TOKEN"];
@@ -124,12 +124,6 @@ Class | Method | HTTP request | Description
## Documentation For Authorization
## api_key
- **Type**: API key
- **API key parameter name**: api_key
- **Location**: HTTP header
## petstore_auth
- **Type**: OAuth
@@ -139,6 +133,12 @@ Class | Method | HTTP request | Description
- **write:pets**: modify pets in your account
- **read:pets**: read your pets
## api_key
- **Type**: API key
- **API key parameter name**: api_key
- **Location**: HTTP header
## Author

View File

@@ -32,6 +32,6 @@ Pod::Spec.new do |s|
s.dependency 'AFNetworking', '~> 3'
s.dependency 'JSONModel', '~> 1.2'
s.dependency 'ISO8601', '~> 0.5'
s.dependency 'ISO8601', '~> 0.6'
end

View File

@@ -32,7 +32,7 @@
extern NSString* kSWGPetApiErrorDomain;
extern NSInteger kSWGPetApiMissingParamErrorCode;
+(instancetype) sharedAPI;
-(instancetype) initWithApiClient:(SWGApiClient *)apiClient NS_DESIGNATED_INITIALIZER;
/// Add a new pet to the store
///
@@ -42,7 +42,7 @@ extern NSInteger kSWGPetApiMissingParamErrorCode;
/// code:405 message:"Invalid input"
///
/// @return
-(NSNumber*) addPetWithBody: (SWGPet*) body
-(NSURLSessionTask*) addPetWithBody: (SWGPet*) body
completionHandler: (void (^)(NSError* error)) handler;
@@ -55,7 +55,7 @@ extern NSInteger kSWGPetApiMissingParamErrorCode;
/// code:400 message:"Invalid pet value"
///
/// @return
-(NSNumber*) deletePetWithPetId: (NSNumber*) petId
-(NSURLSessionTask*) deletePetWithPetId: (NSNumber*) petId
apiKey: (NSString*) apiKey
completionHandler: (void (^)(NSError* error)) handler;
@@ -69,7 +69,7 @@ extern NSInteger kSWGPetApiMissingParamErrorCode;
/// code:400 message:"Invalid status value"
///
/// @return NSArray<SWGPet>*
-(NSNumber*) findPetsByStatusWithStatus: (NSArray<NSString*>*) status
-(NSURLSessionTask*) findPetsByStatusWithStatus: (NSArray<NSString*>*) status
completionHandler: (void (^)(NSArray<SWGPet>* output, NSError* error)) handler;
@@ -82,7 +82,7 @@ extern NSInteger kSWGPetApiMissingParamErrorCode;
/// code:400 message:"Invalid tag value"
///
/// @return NSArray<SWGPet>*
-(NSNumber*) findPetsByTagsWithTags: (NSArray<NSString*>*) tags
-(NSURLSessionTask*) findPetsByTagsWithTags: (NSArray<NSString*>*) tags
completionHandler: (void (^)(NSArray<SWGPet>* output, NSError* error)) handler;
@@ -96,7 +96,7 @@ extern NSInteger kSWGPetApiMissingParamErrorCode;
/// code:404 message:"Pet not found"
///
/// @return SWGPet*
-(NSNumber*) getPetByIdWithPetId: (NSNumber*) petId
-(NSURLSessionTask*) getPetByIdWithPetId: (NSNumber*) petId
completionHandler: (void (^)(SWGPet* output, NSError* error)) handler;
@@ -110,7 +110,7 @@ extern NSInteger kSWGPetApiMissingParamErrorCode;
/// code:405 message:"Validation exception"
///
/// @return
-(NSNumber*) updatePetWithBody: (SWGPet*) body
-(NSURLSessionTask*) updatePetWithBody: (SWGPet*) body
completionHandler: (void (^)(NSError* error)) handler;
@@ -124,7 +124,7 @@ extern NSInteger kSWGPetApiMissingParamErrorCode;
/// code:405 message:"Invalid input"
///
/// @return
-(NSNumber*) updatePetWithFormWithPetId: (NSString*) petId
-(NSURLSessionTask*) updatePetWithFormWithPetId: (NSString*) petId
name: (NSString*) name
status: (NSString*) status
completionHandler: (void (^)(NSError* error)) handler;
@@ -140,7 +140,7 @@ extern NSInteger kSWGPetApiMissingParamErrorCode;
/// code:0 message:"successful operation"
///
/// @return
-(NSNumber*) uploadFileWithPetId: (NSNumber*) petId
-(NSURLSessionTask*) uploadFileWithPetId: (NSNumber*) petId
additionalMetadata: (NSString*) additionalMetadata
file: (NSURL*) file
completionHandler: (void (^)(NSError* error)) handler;

View File

@@ -5,7 +5,7 @@
@interface SWGPetApi ()
@property (nonatomic, strong) NSMutableDictionary *defaultHeaders;
@property (nonatomic, strong, readwrite) NSMutableDictionary *defaultHeaders;
@end
@@ -19,19 +19,11 @@ NSInteger kSWGPetApiMissingParamErrorCode = 234513;
#pragma mark - Initialize methods
- (instancetype) init {
self = [super init];
if (self) {
SWGConfiguration *config = [SWGConfiguration sharedConfig];
if (config.apiClient == nil) {
config.apiClient = [[SWGApiClient alloc] init];
}
_apiClient = config.apiClient;
_defaultHeaders = [NSMutableDictionary dictionary];
}
return self;
return [self initWithApiClient:[SWGApiClient sharedClient]];
}
- (id) initWithApiClient:(SWGApiClient *)apiClient {
-(instancetype) initWithApiClient:(SWGApiClient *)apiClient {
self = [super init];
if (self) {
_apiClient = apiClient;
@@ -42,15 +34,6 @@ NSInteger kSWGPetApiMissingParamErrorCode = 234513;
#pragma mark -
+ (instancetype)sharedAPI {
static SWGPetApi *sharedAPI;
static dispatch_once_t once;
dispatch_once(&once, ^{
sharedAPI = [[self alloc] init];
});
return sharedAPI;
}
-(NSString*) defaultHeaderForKey:(NSString*)key {
return self.defaultHeaders[key];
}
@@ -63,10 +46,6 @@ NSInteger kSWGPetApiMissingParamErrorCode = 234513;
[self.defaultHeaders setValue:value forKey:key];
}
-(NSUInteger) requestQueueSize {
return [SWGApiClient requestQueueSize];
}
#pragma mark - Api Methods
///
@@ -76,7 +55,7 @@ NSInteger kSWGPetApiMissingParamErrorCode = 234513;
///
/// @returns void
///
-(NSNumber*) addPetWithBody: (SWGPet*) body
-(NSURLSessionTask*) addPetWithBody: (SWGPet*) body
completionHandler: (void (^)(NSError* error)) handler {
NSMutableString* resourcePath = [NSMutableString stringWithFormat:@"/pet"];
@@ -124,8 +103,7 @@ NSInteger kSWGPetApiMissingParamErrorCode = 234513;
if(handler) {
handler(error);
}
}
];
}];
}
///
@@ -137,7 +115,7 @@ NSInteger kSWGPetApiMissingParamErrorCode = 234513;
///
/// @returns void
///
-(NSNumber*) deletePetWithPetId: (NSNumber*) petId
-(NSURLSessionTask*) deletePetWithPetId: (NSNumber*) petId
apiKey: (NSString*) apiKey
completionHandler: (void (^)(NSError* error)) handler {
// verify the required parameter 'petId' is set
@@ -202,8 +180,7 @@ NSInteger kSWGPetApiMissingParamErrorCode = 234513;
if(handler) {
handler(error);
}
}
];
}];
}
///
@@ -213,7 +190,7 @@ NSInteger kSWGPetApiMissingParamErrorCode = 234513;
///
/// @returns NSArray<SWGPet>*
///
-(NSNumber*) findPetsByStatusWithStatus: (NSArray<NSString*>*) status
-(NSURLSessionTask*) findPetsByStatusWithStatus: (NSArray<NSString*>*) status
completionHandler: (void (^)(NSArray<SWGPet>* output, NSError* error)) handler {
NSMutableString* resourcePath = [NSMutableString stringWithFormat:@"/pet/findByStatus"];
@@ -264,8 +241,7 @@ NSInteger kSWGPetApiMissingParamErrorCode = 234513;
if(handler) {
handler((NSArray<SWGPet>*)data, error);
}
}
];
}];
}
///
@@ -275,7 +251,7 @@ NSInteger kSWGPetApiMissingParamErrorCode = 234513;
///
/// @returns NSArray<SWGPet>*
///
-(NSNumber*) findPetsByTagsWithTags: (NSArray<NSString*>*) tags
-(NSURLSessionTask*) findPetsByTagsWithTags: (NSArray<NSString*>*) tags
completionHandler: (void (^)(NSArray<SWGPet>* output, NSError* error)) handler {
NSMutableString* resourcePath = [NSMutableString stringWithFormat:@"/pet/findByTags"];
@@ -326,8 +302,7 @@ NSInteger kSWGPetApiMissingParamErrorCode = 234513;
if(handler) {
handler((NSArray<SWGPet>*)data, error);
}
}
];
}];
}
///
@@ -337,7 +312,7 @@ NSInteger kSWGPetApiMissingParamErrorCode = 234513;
///
/// @returns SWGPet*
///
-(NSNumber*) getPetByIdWithPetId: (NSNumber*) petId
-(NSURLSessionTask*) getPetByIdWithPetId: (NSNumber*) petId
completionHandler: (void (^)(SWGPet* output, NSError* error)) handler {
// verify the required parameter 'petId' is set
if (petId == nil) {
@@ -376,7 +351,7 @@ NSInteger kSWGPetApiMissingParamErrorCode = 234513;
NSString *requestContentType = [self.apiClient.sanitizer selectHeaderContentType:@[]];
// Authentication setting
NSArray *authSettings = @[@"api_key", @"petstore_auth"];
NSArray *authSettings = @[@"petstore_auth", @"api_key"];
id bodyParam = nil;
NSMutableDictionary *formParams = [[NSMutableDictionary alloc] init];
@@ -398,8 +373,7 @@ NSInteger kSWGPetApiMissingParamErrorCode = 234513;
if(handler) {
handler((SWGPet*)data, error);
}
}
];
}];
}
///
@@ -409,7 +383,7 @@ NSInteger kSWGPetApiMissingParamErrorCode = 234513;
///
/// @returns void
///
-(NSNumber*) updatePetWithBody: (SWGPet*) body
-(NSURLSessionTask*) updatePetWithBody: (SWGPet*) body
completionHandler: (void (^)(NSError* error)) handler {
NSMutableString* resourcePath = [NSMutableString stringWithFormat:@"/pet"];
@@ -457,8 +431,7 @@ NSInteger kSWGPetApiMissingParamErrorCode = 234513;
if(handler) {
handler(error);
}
}
];
}];
}
///
@@ -472,7 +445,7 @@ NSInteger kSWGPetApiMissingParamErrorCode = 234513;
///
/// @returns void
///
-(NSNumber*) updatePetWithFormWithPetId: (NSString*) petId
-(NSURLSessionTask*) updatePetWithFormWithPetId: (NSString*) petId
name: (NSString*) name
status: (NSString*) status
completionHandler: (void (^)(NSError* error)) handler {
@@ -541,8 +514,7 @@ NSInteger kSWGPetApiMissingParamErrorCode = 234513;
if(handler) {
handler(error);
}
}
];
}];
}
///
@@ -556,7 +528,7 @@ NSInteger kSWGPetApiMissingParamErrorCode = 234513;
///
/// @returns void
///
-(NSNumber*) uploadFileWithPetId: (NSNumber*) petId
-(NSURLSessionTask*) uploadFileWithPetId: (NSNumber*) petId
additionalMetadata: (NSString*) additionalMetadata
file: (NSURL*) file
completionHandler: (void (^)(NSError* error)) handler {
@@ -623,8 +595,7 @@ NSInteger kSWGPetApiMissingParamErrorCode = 234513;
if(handler) {
handler(error);
}
}
];
}];
}

View File

@@ -32,7 +32,7 @@
extern NSString* kSWGStoreApiErrorDomain;
extern NSInteger kSWGStoreApiMissingParamErrorCode;
+(instancetype) sharedAPI;
-(instancetype) initWithApiClient:(SWGApiClient *)apiClient NS_DESIGNATED_INITIALIZER;
/// Delete purchase order by ID
/// For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
@@ -43,7 +43,7 @@ extern NSInteger kSWGStoreApiMissingParamErrorCode;
/// code:404 message:"Order not found"
///
/// @return
-(NSNumber*) deleteOrderWithOrderId: (NSString*) orderId
-(NSURLSessionTask*) deleteOrderWithOrderId: (NSString*) orderId
completionHandler: (void (^)(NSError* error)) handler;
@@ -54,7 +54,7 @@ extern NSInteger kSWGStoreApiMissingParamErrorCode;
/// code:200 message:"successful operation"
///
/// @return NSDictionary<NSString*, NSNumber*>*
-(NSNumber*) getInventoryWithCompletionHandler:
-(NSURLSessionTask*) getInventoryWithCompletionHandler:
(void (^)(NSDictionary<NSString*, NSNumber*>* output, NSError* error)) handler;
@@ -68,7 +68,7 @@ extern NSInteger kSWGStoreApiMissingParamErrorCode;
/// code:404 message:"Order not found"
///
/// @return SWGOrder*
-(NSNumber*) getOrderByIdWithOrderId: (NSString*) orderId
-(NSURLSessionTask*) getOrderByIdWithOrderId: (NSString*) orderId
completionHandler: (void (^)(SWGOrder* output, NSError* error)) handler;
@@ -81,7 +81,7 @@ extern NSInteger kSWGStoreApiMissingParamErrorCode;
/// code:400 message:"Invalid Order"
///
/// @return SWGOrder*
-(NSNumber*) placeOrderWithBody: (SWGOrder*) body
-(NSURLSessionTask*) placeOrderWithBody: (SWGOrder*) body
completionHandler: (void (^)(SWGOrder* output, NSError* error)) handler;

View File

@@ -5,7 +5,7 @@
@interface SWGStoreApi ()
@property (nonatomic, strong) NSMutableDictionary *defaultHeaders;
@property (nonatomic, strong, readwrite) NSMutableDictionary *defaultHeaders;
@end
@@ -19,19 +19,11 @@ NSInteger kSWGStoreApiMissingParamErrorCode = 234513;
#pragma mark - Initialize methods
- (instancetype) init {
self = [super init];
if (self) {
SWGConfiguration *config = [SWGConfiguration sharedConfig];
if (config.apiClient == nil) {
config.apiClient = [[SWGApiClient alloc] init];
}
_apiClient = config.apiClient;
_defaultHeaders = [NSMutableDictionary dictionary];
}
return self;
return [self initWithApiClient:[SWGApiClient sharedClient]];
}
- (id) initWithApiClient:(SWGApiClient *)apiClient {
-(instancetype) initWithApiClient:(SWGApiClient *)apiClient {
self = [super init];
if (self) {
_apiClient = apiClient;
@@ -42,15 +34,6 @@ NSInteger kSWGStoreApiMissingParamErrorCode = 234513;
#pragma mark -
+ (instancetype)sharedAPI {
static SWGStoreApi *sharedAPI;
static dispatch_once_t once;
dispatch_once(&once, ^{
sharedAPI = [[self alloc] init];
});
return sharedAPI;
}
-(NSString*) defaultHeaderForKey:(NSString*)key {
return self.defaultHeaders[key];
}
@@ -63,10 +46,6 @@ NSInteger kSWGStoreApiMissingParamErrorCode = 234513;
[self.defaultHeaders setValue:value forKey:key];
}
-(NSUInteger) requestQueueSize {
return [SWGApiClient requestQueueSize];
}
#pragma mark - Api Methods
///
@@ -76,7 +55,7 @@ NSInteger kSWGStoreApiMissingParamErrorCode = 234513;
///
/// @returns void
///
-(NSNumber*) deleteOrderWithOrderId: (NSString*) orderId
-(NSURLSessionTask*) deleteOrderWithOrderId: (NSString*) orderId
completionHandler: (void (^)(NSError* error)) handler {
// verify the required parameter 'orderId' is set
if (orderId == nil) {
@@ -137,8 +116,7 @@ NSInteger kSWGStoreApiMissingParamErrorCode = 234513;
if(handler) {
handler(error);
}
}
];
}];
}
///
@@ -146,7 +124,7 @@ NSInteger kSWGStoreApiMissingParamErrorCode = 234513;
/// Returns a map of status codes to quantities
/// @returns NSDictionary<NSString*, NSNumber*>*
///
-(NSNumber*) getInventoryWithCompletionHandler:
-(NSURLSessionTask*) getInventoryWithCompletionHandler:
(void (^)(NSDictionary<NSString*, NSNumber*>* output, NSError* error)) handler {
NSMutableString* resourcePath = [NSMutableString stringWithFormat:@"/store/inventory"];
@@ -193,8 +171,7 @@ NSInteger kSWGStoreApiMissingParamErrorCode = 234513;
if(handler) {
handler((NSDictionary<NSString*, NSNumber*>*)data, error);
}
}
];
}];
}
///
@@ -204,7 +181,7 @@ NSInteger kSWGStoreApiMissingParamErrorCode = 234513;
///
/// @returns SWGOrder*
///
-(NSNumber*) getOrderByIdWithOrderId: (NSString*) orderId
-(NSURLSessionTask*) getOrderByIdWithOrderId: (NSString*) orderId
completionHandler: (void (^)(SWGOrder* output, NSError* error)) handler {
// verify the required parameter 'orderId' is set
if (orderId == nil) {
@@ -265,8 +242,7 @@ NSInteger kSWGStoreApiMissingParamErrorCode = 234513;
if(handler) {
handler((SWGOrder*)data, error);
}
}
];
}];
}
///
@@ -276,7 +252,7 @@ NSInteger kSWGStoreApiMissingParamErrorCode = 234513;
///
/// @returns SWGOrder*
///
-(NSNumber*) placeOrderWithBody: (SWGOrder*) body
-(NSURLSessionTask*) placeOrderWithBody: (SWGOrder*) body
completionHandler: (void (^)(SWGOrder* output, NSError* error)) handler {
NSMutableString* resourcePath = [NSMutableString stringWithFormat:@"/store/order"];
@@ -324,8 +300,7 @@ NSInteger kSWGStoreApiMissingParamErrorCode = 234513;
if(handler) {
handler((SWGOrder*)data, error);
}
}
];
}];
}

View File

@@ -32,7 +32,7 @@
extern NSString* kSWGUserApiErrorDomain;
extern NSInteger kSWGUserApiMissingParamErrorCode;
+(instancetype) sharedAPI;
-(instancetype) initWithApiClient:(SWGApiClient *)apiClient NS_DESIGNATED_INITIALIZER;
/// Create user
/// This can only be done by the logged in user.
@@ -42,7 +42,7 @@ extern NSInteger kSWGUserApiMissingParamErrorCode;
/// code:0 message:"successful operation"
///
/// @return
-(NSNumber*) createUserWithBody: (SWGUser*) body
-(NSURLSessionTask*) createUserWithBody: (SWGUser*) body
completionHandler: (void (^)(NSError* error)) handler;
@@ -54,7 +54,7 @@ extern NSInteger kSWGUserApiMissingParamErrorCode;
/// code:0 message:"successful operation"
///
/// @return
-(NSNumber*) createUsersWithArrayInputWithBody: (NSArray<SWGUser>*) body
-(NSURLSessionTask*) createUsersWithArrayInputWithBody: (NSArray<SWGUser>*) body
completionHandler: (void (^)(NSError* error)) handler;
@@ -66,7 +66,7 @@ extern NSInteger kSWGUserApiMissingParamErrorCode;
/// code:0 message:"successful operation"
///
/// @return
-(NSNumber*) createUsersWithListInputWithBody: (NSArray<SWGUser>*) body
-(NSURLSessionTask*) createUsersWithListInputWithBody: (NSArray<SWGUser>*) body
completionHandler: (void (^)(NSError* error)) handler;
@@ -79,7 +79,7 @@ extern NSInteger kSWGUserApiMissingParamErrorCode;
/// code:404 message:"User not found"
///
/// @return
-(NSNumber*) deleteUserWithUsername: (NSString*) username
-(NSURLSessionTask*) deleteUserWithUsername: (NSString*) username
completionHandler: (void (^)(NSError* error)) handler;
@@ -93,7 +93,7 @@ extern NSInteger kSWGUserApiMissingParamErrorCode;
/// code:404 message:"User not found"
///
/// @return SWGUser*
-(NSNumber*) getUserByNameWithUsername: (NSString*) username
-(NSURLSessionTask*) getUserByNameWithUsername: (NSString*) username
completionHandler: (void (^)(SWGUser* output, NSError* error)) handler;
@@ -107,7 +107,7 @@ extern NSInteger kSWGUserApiMissingParamErrorCode;
/// code:400 message:"Invalid username/password supplied"
///
/// @return NSString*
-(NSNumber*) loginUserWithUsername: (NSString*) username
-(NSURLSessionTask*) loginUserWithUsername: (NSString*) username
password: (NSString*) password
completionHandler: (void (^)(NSString* output, NSError* error)) handler;
@@ -119,7 +119,7 @@ extern NSInteger kSWGUserApiMissingParamErrorCode;
/// code:0 message:"successful operation"
///
/// @return
-(NSNumber*) logoutUserWithCompletionHandler:
-(NSURLSessionTask*) logoutUserWithCompletionHandler:
(void (^)(NSError* error)) handler;
@@ -133,7 +133,7 @@ extern NSInteger kSWGUserApiMissingParamErrorCode;
/// code:404 message:"User not found"
///
/// @return
-(NSNumber*) updateUserWithUsername: (NSString*) username
-(NSURLSessionTask*) updateUserWithUsername: (NSString*) username
body: (SWGUser*) body
completionHandler: (void (^)(NSError* error)) handler;

View File

@@ -5,7 +5,7 @@
@interface SWGUserApi ()
@property (nonatomic, strong) NSMutableDictionary *defaultHeaders;
@property (nonatomic, strong, readwrite) NSMutableDictionary *defaultHeaders;
@end
@@ -19,19 +19,11 @@ NSInteger kSWGUserApiMissingParamErrorCode = 234513;
#pragma mark - Initialize methods
- (instancetype) init {
self = [super init];
if (self) {
SWGConfiguration *config = [SWGConfiguration sharedConfig];
if (config.apiClient == nil) {
config.apiClient = [[SWGApiClient alloc] init];
}
_apiClient = config.apiClient;
_defaultHeaders = [NSMutableDictionary dictionary];
}
return self;
return [self initWithApiClient:[SWGApiClient sharedClient]];
}
- (id) initWithApiClient:(SWGApiClient *)apiClient {
-(instancetype) initWithApiClient:(SWGApiClient *)apiClient {
self = [super init];
if (self) {
_apiClient = apiClient;
@@ -42,15 +34,6 @@ NSInteger kSWGUserApiMissingParamErrorCode = 234513;
#pragma mark -
+ (instancetype)sharedAPI {
static SWGUserApi *sharedAPI;
static dispatch_once_t once;
dispatch_once(&once, ^{
sharedAPI = [[self alloc] init];
});
return sharedAPI;
}
-(NSString*) defaultHeaderForKey:(NSString*)key {
return self.defaultHeaders[key];
}
@@ -63,10 +46,6 @@ NSInteger kSWGUserApiMissingParamErrorCode = 234513;
[self.defaultHeaders setValue:value forKey:key];
}
-(NSUInteger) requestQueueSize {
return [SWGApiClient requestQueueSize];
}
#pragma mark - Api Methods
///
@@ -76,7 +55,7 @@ NSInteger kSWGUserApiMissingParamErrorCode = 234513;
///
/// @returns void
///
-(NSNumber*) createUserWithBody: (SWGUser*) body
-(NSURLSessionTask*) createUserWithBody: (SWGUser*) body
completionHandler: (void (^)(NSError* error)) handler {
NSMutableString* resourcePath = [NSMutableString stringWithFormat:@"/user"];
@@ -124,8 +103,7 @@ NSInteger kSWGUserApiMissingParamErrorCode = 234513;
if(handler) {
handler(error);
}
}
];
}];
}
///
@@ -135,7 +113,7 @@ NSInteger kSWGUserApiMissingParamErrorCode = 234513;
///
/// @returns void
///
-(NSNumber*) createUsersWithArrayInputWithBody: (NSArray<SWGUser>*) body
-(NSURLSessionTask*) createUsersWithArrayInputWithBody: (NSArray<SWGUser>*) body
completionHandler: (void (^)(NSError* error)) handler {
NSMutableString* resourcePath = [NSMutableString stringWithFormat:@"/user/createWithArray"];
@@ -183,8 +161,7 @@ NSInteger kSWGUserApiMissingParamErrorCode = 234513;
if(handler) {
handler(error);
}
}
];
}];
}
///
@@ -194,7 +171,7 @@ NSInteger kSWGUserApiMissingParamErrorCode = 234513;
///
/// @returns void
///
-(NSNumber*) createUsersWithListInputWithBody: (NSArray<SWGUser>*) body
-(NSURLSessionTask*) createUsersWithListInputWithBody: (NSArray<SWGUser>*) body
completionHandler: (void (^)(NSError* error)) handler {
NSMutableString* resourcePath = [NSMutableString stringWithFormat:@"/user/createWithList"];
@@ -242,8 +219,7 @@ NSInteger kSWGUserApiMissingParamErrorCode = 234513;
if(handler) {
handler(error);
}
}
];
}];
}
///
@@ -253,7 +229,7 @@ NSInteger kSWGUserApiMissingParamErrorCode = 234513;
///
/// @returns void
///
-(NSNumber*) deleteUserWithUsername: (NSString*) username
-(NSURLSessionTask*) deleteUserWithUsername: (NSString*) username
completionHandler: (void (^)(NSError* error)) handler {
// verify the required parameter 'username' is set
if (username == nil) {
@@ -314,8 +290,7 @@ NSInteger kSWGUserApiMissingParamErrorCode = 234513;
if(handler) {
handler(error);
}
}
];
}];
}
///
@@ -325,7 +300,7 @@ NSInteger kSWGUserApiMissingParamErrorCode = 234513;
///
/// @returns SWGUser*
///
-(NSNumber*) getUserByNameWithUsername: (NSString*) username
-(NSURLSessionTask*) getUserByNameWithUsername: (NSString*) username
completionHandler: (void (^)(SWGUser* output, NSError* error)) handler {
// verify the required parameter 'username' is set
if (username == nil) {
@@ -386,8 +361,7 @@ NSInteger kSWGUserApiMissingParamErrorCode = 234513;
if(handler) {
handler((SWGUser*)data, error);
}
}
];
}];
}
///
@@ -399,7 +373,7 @@ NSInteger kSWGUserApiMissingParamErrorCode = 234513;
///
/// @returns NSString*
///
-(NSNumber*) loginUserWithUsername: (NSString*) username
-(NSURLSessionTask*) loginUserWithUsername: (NSString*) username
password: (NSString*) password
completionHandler: (void (^)(NSString* output, NSError* error)) handler {
NSMutableString* resourcePath = [NSMutableString stringWithFormat:@"/user/login"];
@@ -453,8 +427,7 @@ NSInteger kSWGUserApiMissingParamErrorCode = 234513;
if(handler) {
handler((NSString*)data, error);
}
}
];
}];
}
///
@@ -462,7 +435,7 @@ NSInteger kSWGUserApiMissingParamErrorCode = 234513;
///
/// @returns void
///
-(NSNumber*) logoutUserWithCompletionHandler:
-(NSURLSessionTask*) logoutUserWithCompletionHandler:
(void (^)(NSError* error)) handler {
NSMutableString* resourcePath = [NSMutableString stringWithFormat:@"/user/logout"];
@@ -509,8 +482,7 @@ NSInteger kSWGUserApiMissingParamErrorCode = 234513;
if(handler) {
handler(error);
}
}
];
}];
}
///
@@ -522,7 +494,7 @@ NSInteger kSWGUserApiMissingParamErrorCode = 234513;
///
/// @returns void
///
-(NSNumber*) updateUserWithUsername: (NSString*) username
-(NSURLSessionTask*) updateUserWithUsername: (NSString*) username
body: (SWGUser*) body
completionHandler: (void (^)(NSError* error)) handler {
// verify the required parameter 'username' is set
@@ -585,8 +557,7 @@ NSInteger kSWGUserApiMissingParamErrorCode = 234513;
if(handler) {
handler(error);
}
}
];
}];
}

View File

@@ -1,5 +1,4 @@
#import <Foundation/Foundation.h>
#import <ISO8601/ISO8601.h>
#import <JSONModel/JSONValueTransformer.h>
/**

View File

@@ -1,3 +1,4 @@
#import <ISO8601/NSDate+ISO8601.h>
#import "JSONValueTransformer+ISO8601.h"
@implementation JSONValueTransformer (ISO8601)

View File

@@ -28,15 +28,13 @@
@protocol SWGApi <NSObject>
@property(nonatomic, assign) SWGApiClient *apiClient;
@property(readonly, nonatomic, strong) SWGApiClient *apiClient;
-(id) initWithApiClient:(SWGApiClient *)apiClient;
-(instancetype) initWithApiClient:(SWGApiClient *)apiClient;
-(void) addHeader:(NSString*)value forKey:(NSString*)key DEPRECATED_MSG_ATTRIBUTE("setDefaultHeaderValue:forKey:");
-(void) setDefaultHeaderValue:(NSString*) value forKey:(NSString*)key;
-(NSString*) defaultHeaderForKey:(NSString*)key;
-(NSUInteger) requestQueueSize;
@end

View File

@@ -1,13 +1,7 @@
#import <Foundation/Foundation.h>
#import <ISO8601/ISO8601.h>
#import <AFNetworking/AFNetworking.h>
#import "SWGJSONResponseSerializer.h"
#import "SWGJSONRequestSerializer.h"
#import "SWGQueryParamCollection.h"
#import "SWGConfiguration.h"
#import "SWGResponseDeserializer.h"
#import "SWGSanitizer.h"
#import "SWGLogger.h"
/**
* Swagger Petstore
@@ -33,16 +27,6 @@
* limitations under the License.
*/
#import "SWGCategory.h"
#import "SWGOrder.h"
#import "SWGPet.h"
#import "SWGTag.h"
#import "SWGUser.h"
@class SWGConfiguration;
/**
* A key for `NSError` user info dictionaries.
*
@@ -50,15 +34,15 @@
*/
extern NSString *const SWGResponseObjectErrorKey;
@interface SWGApiClient : AFHTTPSessionManager
@property (nonatomic, strong, readonly) id<SWGConfiguration> configuration;
@property(nonatomic, assign) NSURLRequestCachePolicy cachePolicy;
@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;
@property(nonatomic, strong) id<SWGResponseDeserializer> responseDeserializer;
@property(nonatomic, strong) id<SWGSanitizer> sanitizer;
@@ -74,13 +58,6 @@ extern NSString *const SWGResponseObjectErrorKey;
*/
+(void)setCacheEnabled:(BOOL) enabled;
/**
* Gets the request queue size
*
* @return The size of `queuedRequests` static variable.
*/
+(NSUInteger)requestQueueSize;
/**
* Sets the client unreachable
*
@@ -109,27 +86,6 @@ extern NSString *const SWGResponseObjectErrorKey;
*/
+(AFNetworkReachabilityStatus) getReachabilityStatus;
/**
* Gets the next request id
*
* @return The next executed request id.
*/
+(NSNumber*) nextRequestId;
/**
* Generates request id and add it to the queue
*
* @return The next executed request id.
*/
+(NSNumber*) queueRequest;
/**
* Removes request id from the queue
*
* @param requestId The request which will be removed.
*/
+(void) cancelRequest:(NSNumber*)requestId;
/**
* Customizes the behavior when the reachability changed
*
@@ -137,6 +93,11 @@ extern NSString *const SWGResponseObjectErrorKey;
*/
+(void) setReachabilityChangeBlock:(void(^)(int))changeBlock;
/**
* Gets client singleton instance
*/
+ (instancetype) sharedClient;
/**
* Sets the api client reachability strategy
*/
@@ -162,6 +123,14 @@ extern NSString *const SWGResponseObjectErrorKey;
queryParams:(NSDictionary **)querys
WithAuthSettings:(NSArray *)authSettings;
/**
* Initializes the session manager with a configuration.
*
* @param configuration The configuration implementation
*/
- (instancetype)initWithConfiguration:(id<SWGConfiguration>)configuration;
/**
* Performs request
*
@@ -176,21 +145,21 @@ extern NSString *const SWGResponseObjectErrorKey;
* @param responseContentType Response content-type.
* @param completionBlock The block will be executed when the request completed.
*
* @return The request id.
* @return The created session task.
*/
-(NSNumber*) requestWithPath:(NSString*) path
method:(NSString*) method
pathParams:(NSDictionary *) pathParams
queryParams:(NSDictionary*) queryParams
formParams:(NSDictionary *) formParams
files:(NSDictionary *) files
body:(id) body
headerParams:(NSDictionary*) headerParams
authSettings:(NSArray *) authSettings
requestContentType:(NSString*) requestContentType
responseContentType:(NSString*) responseContentType
responseType:(NSString *) responseType
completionBlock:(void (^)(id, NSError *))completionBlock;
- (NSURLSessionTask*) requestWithPath: (NSString*) path
method: (NSString*) method
pathParams: (NSDictionary *) pathParams
queryParams: (NSDictionary*) queryParams
formParams: (NSDictionary *) formParams
files: (NSDictionary *) files
body: (id) body
headerParams: (NSDictionary*) headerParams
authSettings: (NSArray *) authSettings
requestContentType: (NSString*) requestContentType
responseContentType: (NSString*) responseContentType
responseType: (NSString *) responseType
completionBlock: (void (^)(id, NSError *))completionBlock;
/**
* Custom security policy
@@ -199,12 +168,4 @@ extern NSString *const SWGResponseObjectErrorKey;
*/
- (AFSecurityPolicy *) customSecurityPolicy;
/**
* SWGConfiguration return sharedConfig
*
* @return SWGConfiguration
*/
- (SWGConfiguration*) configuration;
@end

View File

@@ -1,10 +1,16 @@
#import <ISO8601/NSDate+ISO8601.h>
#import "SWGApiClient.h"
#import "SWGJSONRequestSerializer.h"
#import "SWGJSONResponseSerializer.h"
#import "SWGQueryParamCollection.h"
#import "SWGDefaultConfiguration.h"
NSString *const SWGResponseObjectErrorKey = @"SWGResponseObject";
static NSUInteger requestId = 0;
static bool offlineState = false;
static NSMutableSet * queuedRequests = nil;
static bool cacheEnabled = false;
static AFNetworkReachabilityStatus reachabilityStatus = AFNetworkReachabilityStatusNotReachable;
static void (^reachabilityChangeBlock)(int);
@@ -36,38 +42,61 @@ static NSString * SWG__fileNameForResponse(NSURLResponse *response) {
@interface SWGApiClient ()
@property (nonatomic, strong) NSDictionary* HTTPResponseHeaders;
@property (nonatomic, strong, readwrite) id<SWGConfiguration> configuration;
@end
@implementation SWGApiClient
#pragma mark - Singleton Methods
+ (instancetype) sharedClient {
static SWGApiClient *sharedClient = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedClient = [[self alloc] init];
});
return sharedClient;
}
#pragma mark - Initialize Methods
- (instancetype)init {
NSString *baseUrl = [[SWGConfiguration sharedConfig] host];
return [self initWithBaseURL:[NSURL URLWithString:baseUrl]];
return [self initWithConfiguration:[SWGDefaultConfiguration sharedConfig]];
}
- (instancetype)initWithBaseURL:(NSURL *)url {
return [self initWithBaseURL:url
configuration:[SWGDefaultConfiguration sharedConfig]];
}
- (instancetype)initWithConfiguration:(id<SWGConfiguration>)configuration {
return [self initWithBaseURL:[NSURL URLWithString:configuration.host] configuration:configuration];
}
- (instancetype)initWithBaseURL:(NSURL *)url
configuration:(id<SWGConfiguration>)configuration {
self = [super initWithBaseURL:url];
if (self) {
self.timeoutInterval = 60;
_configuration = configuration;
_timeoutInterval = 60;
_responseDeserializer = [[SWGResponseDeserializer alloc] init];
_sanitizer = [[SWGSanitizer alloc] init];
self.requestSerializer = [AFJSONRequestSerializer serializer];
self.responseSerializer = [AFJSONResponseSerializer serializer];
self.securityPolicy = [self customSecurityPolicy];
self.responseDeserializer = [[SWGResponseDeserializer alloc] init];
self.sanitizer = [[SWGSanitizer alloc] init];
// configure reachability
[self configureCacheReachibility];
}
return self;
}
+ (void)initialize {
if (self == [SWGApiClient class]) {
queuedRequests = [[NSMutableSet alloc] init];
// initialize URL cache
[self configureCacheWithMemoryAndDiskCapacity:4*1024*1024 diskSize:32*1024*1024];
}
return self;
}
#pragma mark - Setter Methods
@@ -113,43 +142,6 @@ static NSString * SWG__fileNameForResponse(NSURLResponse *response) {
[NSURLCache setSharedURLCache:cache];
}
#pragma mark - Request Methods
+(NSUInteger)requestQueueSize {
return [queuedRequests count];
}
+(NSNumber*) nextRequestId {
@synchronized(self) {
return @(++requestId);
}
}
+(NSNumber*) queueRequest {
NSNumber* requestId = [[self class] nextRequestId];
SWGDebugLog(@"added %@ to request queue", requestId);
[queuedRequests addObject:requestId];
return requestId;
}
+(void) cancelRequest:(NSNumber*)requestId {
[queuedRequests removeObject:requestId];
}
-(Boolean) executeRequestWithId:(NSNumber*) requestId {
NSSet* matchingItems = [queuedRequests objectsPassingTest:^BOOL(id obj, BOOL *stop) {
return [obj intValue] == [requestId intValue];
}];
if (matchingItems.count == 1) {
SWGDebugLog(@"removed request id %@", requestId);
[queuedRequests removeObject:requestId];
return YES;
} else {
return NO;
}
}
#pragma mark - Reachability Methods
+(AFNetworkReachabilityStatus) getReachabilityStatus {
@@ -179,23 +171,19 @@ static NSString * SWG__fileNameForResponse(NSURLResponse *response) {
[self.reachabilityManager startMonitoring];
}
#pragma mark - Operation Methods
#pragma mark - Task Methods
- (void) operationWithCompletionBlock: (NSURLRequest *)request
requestId: (NSNumber *) requestId
completionBlock: (void (^)(id, NSError *))completionBlock {
__weak __typeof(self)weakSelf = self;
NSURLSessionDataTask* op = [self dataTaskWithRequest:request completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
__strong __typeof(weakSelf)strongSelf = weakSelf;
if (![strongSelf executeRequestWithId:requestId]) {
return;
}
- (NSURLSessionDataTask*) taskWithCompletionBlock: (NSURLRequest *)request
completionBlock: (void (^)(id, NSError *))completionBlock {
NSURLSessionDataTask *task = [self dataTaskWithRequest:request completionHandler:^(NSURLResponse * _Nonnull response, id _Nullable responseObject, NSError * _Nullable error) {
SWGDebugLogResponse(response, responseObject,request,error);
strongSelf.HTTPResponseHeaders = SWG__headerFieldsForResponse(response);
if(!error) {
completionBlock(responseObject, nil);
return;
}
NSMutableDictionary *userInfo = [error.userInfo mutableCopy];
if (responseObject) {
// Add in the (parsed) response body.
@@ -204,20 +192,18 @@ static NSString * SWG__fileNameForResponse(NSURLResponse *response) {
NSError *augmentedError = [error initWithDomain:error.domain code:error.code userInfo:userInfo];
completionBlock(nil, augmentedError);
}];
[op resume];
return task;
}
- (void) downloadOperationWithCompletionBlock: (NSURLRequest *)request
requestId: (NSNumber *) requestId
completionBlock: (void (^)(id, NSError *))completionBlock {
__weak __typeof(self)weakSelf = self;
NSURLSessionDataTask* op = [self dataTaskWithRequest:request completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
__strong __typeof(weakSelf)strongSelf = weakSelf;
if (![strongSelf executeRequestWithId:requestId]) {
return;
}
strongSelf.HTTPResponseHeaders = SWG__headerFieldsForResponse(response);
- (NSURLSessionDataTask*) downloadTaskWithCompletionBlock: (NSURLRequest *)request
completionBlock: (void (^)(id, NSError *))completionBlock {
id<SWGConfiguration> config = self.configuration;
NSURLSessionDataTask* task = [self dataTaskWithRequest:request completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
SWGDebugLogResponse(response, responseObject,request,error);
if(error) {
NSMutableDictionary *userInfo = [error.userInfo mutableCopy];
if (responseObject) {
@@ -226,8 +212,9 @@ static NSString * SWG__fileNameForResponse(NSURLResponse *response) {
NSError *augmentedError = [error initWithDomain:error.domain code:error.code userInfo:userInfo];
completionBlock(nil, augmentedError);
}
NSString *directory = [self configuration].tempFolderPath ?: NSTemporaryDirectory();
NSString * filename = SWG__fileNameForResponse(response);
NSString *directory = config.tempFolderPath ?: NSTemporaryDirectory();
NSString *filename = SWG__fileNameForResponse(response);
NSString *filepath = [directory stringByAppendingPathComponent:filename];
NSURL *file = [NSURL fileURLWithPath:filepath];
@@ -236,24 +223,26 @@ static NSString * SWG__fileNameForResponse(NSURLResponse *response) {
completionBlock(file, nil);
}];
[op resume];
return task;
}
#pragma mark - Perform Request Methods
#pragma mark - Perform Request Methods
- (NSURLSessionTask*) requestWithPath: (NSString*) path
method: (NSString*) method
pathParams: (NSDictionary *) pathParams
queryParams: (NSDictionary*) queryParams
formParams: (NSDictionary *) formParams
files: (NSDictionary *) files
body: (id) body
headerParams: (NSDictionary*) headerParams
authSettings: (NSArray *) authSettings
requestContentType: (NSString*) requestContentType
responseContentType: (NSString*) responseContentType
responseType: (NSString *) responseType
completionBlock: (void (^)(id, NSError *))completionBlock {
-(NSNumber*) requestWithPath: (NSString*) path
method: (NSString*) method
pathParams: (NSDictionary *) pathParams
queryParams: (NSDictionary*) queryParams
formParams: (NSDictionary *) formParams
files: (NSDictionary *) files
body: (id) body
headerParams: (NSDictionary*) headerParams
authSettings: (NSArray *) authSettings
requestContentType: (NSString*) requestContentType
responseContentType: (NSString*) responseContentType
responseType: (NSString *) responseType
completionBlock: (void (^)(id, NSError *))completionBlock {
// setting request serializer
if ([requestContentType isEqualToString:@"application/json"]) {
self.requestSerializer = [SWGJSONRequestSerializer serializer];
@@ -359,14 +348,16 @@ static NSString * SWG__fileNameForResponse(NSURLResponse *response) {
[self postProcessRequest:request];
NSNumber* requestId = [SWGApiClient queueRequest];
NSURLSessionTask *task = nil;
if ([responseType isEqualToString:@"NSURL*"] || [responseType isEqualToString:@"NSURL"]) {
[self downloadOperationWithCompletionBlock:request requestId:requestId completionBlock:^(id data, NSError *error) {
task = [self downloadTaskWithCompletionBlock:request completionBlock:^(id data, NSError *error) {
completionBlock(data, error);
}];
}
else {
[self operationWithCompletionBlock:request requestId:requestId completionBlock:^(id data, NSError *error) {
task = [self taskWithCompletionBlock:request completionBlock:^(id data, NSError *error) {
NSError * serializationError;
id response = [self.responseDeserializer deserialize:data class:responseType error:&serializationError];
if(!response && !error){
@@ -375,7 +366,10 @@ static NSString * SWG__fileNameForResponse(NSURLResponse *response) {
completionBlock(response, error);
}];
}
return requestId;
[task resume];
return task;
}
//Added for easier override to modify request
@@ -455,10 +449,11 @@ static NSString * SWG__fileNameForResponse(NSURLResponse *response) {
NSMutableDictionary *headersWithAuth = [NSMutableDictionary dictionaryWithDictionary:*headers];
NSMutableDictionary *querysWithAuth = [NSMutableDictionary dictionaryWithDictionary:*querys];
NSDictionary* configurationAuthSettings = [[self configuration] authSettings];
id<SWGConfiguration> config = self.configuration;
for (NSString *auth in authSettings) {
NSDictionary *authSetting = configurationAuthSettings[auth];
NSDictionary *authSetting = config.authSettings[auth];
if(!authSetting) { // auth setting is set only if the key is non-empty
continue;
}
@@ -479,11 +474,11 @@ static NSString * SWG__fileNameForResponse(NSURLResponse *response) {
- (AFSecurityPolicy *) customSecurityPolicy {
AFSecurityPolicy *securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeNone];
SWGConfiguration *config = [self configuration];
id<SWGConfiguration> config = self.configuration;
if (config.sslCaCert) {
NSData *certData = [NSData dataWithContentsOfFile:config.sslCaCert];
[securityPolicy setPinnedCertificates:@[certData]];
[securityPolicy setPinnedCertificates:[NSSet setWithObject:certData]];
}
if (config.verifySSL) {
@@ -497,8 +492,4 @@ static NSString * SWG__fileNameForResponse(NSURLResponse *response) {
return securityPolicy;
}
- (SWGConfiguration*) configuration {
return [SWGConfiguration sharedConfig];
}
@end

View File

@@ -0,0 +1,14 @@
/** The `SWGBasicAuthTokenProvider` class creates a basic auth token from username and password.
*
* 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.
*/
#import <Foundation/Foundation.h>
@interface SWGBasicAuthTokenProvider : NSObject
+ (NSString *)createBasicAuthTokenWithUsername:(NSString *)username password:(NSString *)password;
@end

View File

@@ -0,0 +1,19 @@
#import "SWGBasicAuthTokenProvider.h"
@implementation SWGBasicAuthTokenProvider
+ (NSString *)createBasicAuthTokenWithUsername:(NSString *)username password:(NSString *)password {
// return empty string if username and password are empty
if (username.length == 0 && password.length == 0){
return @"";
}
NSString *basicAuthCredentials = [NSString stringWithFormat:@"%@:%@", username, password];
NSData *data = [basicAuthCredentials dataUsingEncoding:NSUTF8StringEncoding];
basicAuthCredentials = [NSString stringWithFormat:@"Basic %@", [data base64EncodedStringWithOptions:0]];
return basicAuthCredentials;
}
@end

View File

@@ -1,5 +1,4 @@
#import <Foundation/Foundation.h>
#import "SWGApiClient.h"
#import "SWGLogger.h"
/**
@@ -26,157 +25,73 @@
* limitations under the License.
*/
@class SWGApiClient;
@interface SWGConfiguration : NSObject
@protocol SWGConfiguration <NSObject>
/**
* Default api logger
* Api logger
*/
@property (nonatomic, strong) SWGLogger * logger;
@property (readonly, nonatomic) SWGLogger *logger;
/**
* Default api client
* Base url
*/
@property (nonatomic) SWGApiClient *apiClient;
/**
* Default base url
*/
@property (nonatomic) NSString *host;
@property (readonly, nonatomic) NSString *host;
/**
* Api key values for Api Key type Authentication
*
* To add or remove api key, use `setApiKey:forApiKeyIdentifier:`.
*/
@property (readonly, nonatomic, strong) NSDictionary *apiKey;
@property (readonly, nonatomic) NSDictionary *apiKey;
/**
* Api key prefix values to be prepend to the respective api key
*
* To add or remove prefix, use `setApiKeyPrefix:forApiKeyPrefixIdentifier:`.
*/
@property (readonly, nonatomic, strong) NSDictionary *apiKeyPrefix;
@property (readonly, nonatomic) NSDictionary *apiKeyPrefix;
/**
* Username for HTTP Basic Authentication
*/
@property (nonatomic) NSString *username;
@property (readonly, nonatomic) NSString *username;
/**
* Password for HTTP Basic Authentication
*/
@property (nonatomic) NSString *password;
@property (readonly, nonatomic) NSString *password;
/**
* Access token for OAuth
*/
@property (nonatomic) NSString *accessToken;
@property (readonly, nonatomic) NSString *accessToken;
/**
* Temp folder for file download
*/
@property (nonatomic) NSString *tempFolderPath;
@property (readonly, nonatomic) NSString *tempFolderPath;
/**
* Debug switch, default false
*/
@property (nonatomic) BOOL debug;
/**
* Gets configuration singleton instance
*/
+ (instancetype) sharedConfig;
@property (readonly, nonatomic) BOOL debug;
/**
* SSL/TLS verification
* Set this to NO to skip verifying SSL certificate when calling API from https server
*/
@property (nonatomic) BOOL verifySSL;
@property (readonly, nonatomic) BOOL verifySSL;
/**
* SSL/TLS verification
* Set this to customize the certificate file to verify the peer
*/
@property (nonatomic) NSString *sslCaCert;
@property (readonly, nonatomic) NSString *sslCaCert;
/**
* Sets API key
*
* To remove a apiKey for an identifier, just set the apiKey to nil.
*
* @param apiKey API key or token.
* @param identifier API key identifier (authentication schema).
*
* Authentication Settings
*/
- (void) setApiKey:(NSString *)apiKey forApiKeyIdentifier:(NSString*)identifier;
/**
* Removes api key
*
* @param identifier API key identifier.
*/
- (void) removeApiKey:(NSString *)identifier;
/**
* Sets the prefix for API key
*
* @param apiKeyPrefix API key prefix.
* @param identifier API key identifier.
*/
- (void) setApiKeyPrefix:(NSString *)prefix forApiKeyPrefixIdentifier:(NSString *)identifier;
/**
* Removes api key prefix
*
* @param identifier API key identifier.
*/
- (void) removeApiKeyPrefix:(NSString *)identifier;
/**
* Gets API key (with prefix if set)
*/
- (NSString *) getApiKeyWithPrefix:(NSString *) key;
/**
* Gets Basic Auth token
*/
- (NSString *) getBasicAuthToken;
/**
* Gets OAuth access token
*/
- (NSString *) getAccessToken;
/**
* Gets Authentication Settings
*/
- (NSDictionary *) authSettings;
@property (readonly, nonatomic) NSDictionary *authSettings;
/**
* Default headers for all services
*/
@property (readonly, nonatomic, strong) NSDictionary *defaultHeaders;
/**
* Removes header from defaultHeaders
*
* @param Header name.
*/
-(void) removeDefaultHeaderForKey:(NSString*)key;
/**
* Sets the header for key
*
* @param value Value for header name
* @param key Header name
*/
-(void) setDefaultHeaderValue:(NSString*) value forKey:(NSString*)key;
/**
* @param Header key name.
*/
-(NSString*) defaultHeaderForKey:(NSString*)key;
@end
@end

View File

@@ -0,0 +1,175 @@
#import <Foundation/Foundation.h>
#import "SWGConfiguration.h"
/**
* Swagger Petstore
* This is a sample server Petstore server. You can find out more about Swagger at <a href=\"http://swagger.io\">http://swagger.io</a> or on irc.freenode.net, #swagger. For this sample, you can use the api key \"special-key\" to test the authorization filters
*
* OpenAPI spec version: 1.0.0
* Contact: apiteam@wordnik.com
*
* NOTE: This class is auto generated by the swagger code generator program.
* https://github.com/swagger-api/swagger-codegen.git
* Do not edit the class manually.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@interface SWGDefaultConfiguration : NSObject <SWGConfiguration>
/**
* Default api logger
*/
@property (nonatomic, strong) SWGLogger * logger;
/**
* Default base url
*/
@property (nonatomic) NSString *host;
/**
* Api key values for Api Key type Authentication
*
* To add or remove api key, use `setApiKey:forApiKeyIdentifier:`.
*/
@property (readonly, nonatomic, strong) NSDictionary *apiKey;
/**
* Api key prefix values to be prepend to the respective api key
*
* To add or remove prefix, use `setApiKeyPrefix:forApiKeyPrefixIdentifier:`.
*/
@property (readonly, nonatomic, strong) NSDictionary *apiKeyPrefix;
/**
* Username for HTTP Basic Authentication
*/
@property (nonatomic) NSString *username;
/**
* Password for HTTP Basic Authentication
*/
@property (nonatomic) NSString *password;
/**
* Access token for OAuth
*/
@property (nonatomic) NSString *accessToken;
/**
* Temp folder for file download
*/
@property (nonatomic) NSString *tempFolderPath;
/**
* Debug switch, default false
*/
@property (nonatomic) BOOL debug;
/**
* Gets configuration singleton instance
*/
+ (instancetype) sharedConfig;
/**
* SSL/TLS verification
* Set this to NO to skip verifying SSL certificate when calling API from https server
*/
@property (nonatomic) BOOL verifySSL;
/**
* SSL/TLS verification
* Set this to customize the certificate file to verify the peer
*/
@property (nonatomic) NSString *sslCaCert;
/**
* Sets API key
*
* To remove a apiKey for an identifier, just set the apiKey to nil.
*
* @param apiKey API key or token.
* @param identifier API key identifier (authentication schema).
*
*/
- (void) setApiKey:(NSString *)apiKey forApiKeyIdentifier:(NSString*)identifier;
/**
* Removes api key
*
* @param identifier API key identifier.
*/
- (void) removeApiKey:(NSString *)identifier;
/**
* Sets the prefix for API key
*
* @param apiKeyPrefix API key prefix.
* @param identifier API key identifier.
*/
- (void) setApiKeyPrefix:(NSString *)prefix forApiKeyPrefixIdentifier:(NSString *)identifier;
/**
* Removes api key prefix
*
* @param identifier API key identifier.
*/
- (void) removeApiKeyPrefix:(NSString *)identifier;
/**
* Gets API key (with prefix if set)
*/
- (NSString *) getApiKeyWithPrefix:(NSString *) key;
/**
* Gets Basic Auth token
*/
- (NSString *) getBasicAuthToken;
/**
* Gets OAuth access token
*/
- (NSString *) getAccessToken;
/**
* Gets Authentication Settings
*/
- (NSDictionary *) authSettings;
/**
* Default headers for all services
*/
@property (readonly, nonatomic, strong) NSDictionary *defaultHeaders;
/**
* Removes header from defaultHeaders
*
* @param Header name.
*/
-(void) removeDefaultHeaderForKey:(NSString*)key;
/**
* Sets the header for key
*
* @param value Value for header name
* @param key Header name
*/
-(void) setDefaultHeaderValue:(NSString*) value forKey:(NSString*)key;
/**
* @param Header key name.
*/
-(NSString*) defaultHeaderForKey:(NSString*)key;
@end

View File

@@ -1,6 +1,7 @@
#import "SWGConfiguration.h"
#import "SWGDefaultConfiguration.h"
#import "SWGBasicAuthTokenProvider.h"
@interface SWGConfiguration ()
@interface SWGDefaultConfiguration ()
@property (nonatomic, strong) NSMutableDictionary *mutableDefaultHeaders;
@property (nonatomic, strong) NSMutableDictionary *mutableApiKey;
@@ -8,12 +9,12 @@
@end
@implementation SWGConfiguration
@implementation SWGDefaultConfiguration
#pragma mark - Singleton Methods
+ (instancetype) sharedConfig {
static SWGConfiguration *shardConfig = nil;
static SWGDefaultConfiguration *shardConfig = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
shardConfig = [[self alloc] init];
@@ -26,17 +27,16 @@
- (instancetype) init {
self = [super init];
if (self) {
self.apiClient = nil;
self.host = @"http://petstore.swagger.io/v2";
self.username = @"";
self.password = @"";
self.accessToken= @"";
self.verifySSL = YES;
self.mutableApiKey = [NSMutableDictionary dictionary];
self.mutableApiKeyPrefix = [NSMutableDictionary dictionary];
self.mutableDefaultHeaders = [NSMutableDictionary dictionary];
self.mutableDefaultHeaders[@"User-Agent"] = [NSString stringWithFormat:@"Swagger-Codegen/1.0.0/objc (%@; iOS %@; Scale/%0.2f)",[[UIDevice currentDevice] model], [[UIDevice currentDevice] systemVersion], [[UIScreen mainScreen] scale]];
self.logger = [SWGLogger sharedLogger];
_host = @"http://petstore.swagger.io/v2";
_username = @"";
_password = @"";
_accessToken= @"";
_verifySSL = YES;
_mutableApiKey = [NSMutableDictionary dictionary];
_mutableApiKeyPrefix = [NSMutableDictionary dictionary];
_mutableDefaultHeaders = [NSMutableDictionary dictionary];
;
_logger = [SWGLogger sharedLogger];
}
return self;
}
@@ -58,16 +58,9 @@
}
- (NSString *) getBasicAuthToken {
// return empty string if username and password are empty
if (self.username.length == 0 && self.password.length == 0){
return @"";
}
NSString *basicAuthCredentials = [NSString stringWithFormat:@"%@:%@", self.username, self.password];
NSData *data = [basicAuthCredentials dataUsingEncoding:NSUTF8StringEncoding];
basicAuthCredentials = [NSString stringWithFormat:@"Basic %@", [data base64EncodedStringWithOptions:0]];
return basicAuthCredentials;
NSString *basicAuthToken = [SWGBasicAuthTokenProvider createBasicAuthTokenWithUsername:self.username password:self.password];
return basicAuthToken;
}
- (NSString *) getAccessToken {
@@ -110,13 +103,6 @@
- (NSDictionary *) authSettings {
return @{
@"api_key":
@{
@"type": @"api_key",
@"in": @"header",
@"key": @"api_key",
@"value": [self getApiKeyWithPrefix:@"api_key"]
},
@"petstore_auth":
@{
@"type": @"oauth",
@@ -124,6 +110,13 @@
@"key": @"Authorization",
@"value": [self getAccessToken]
},
@"api_key":
@{
@"type": @"api_key",
@"in": @"header",
@"key": @"api_key",
@"value": [self getApiKeyWithPrefix:@"api_key"]
},
};
}

View File

@@ -2,6 +2,35 @@
@implementation SWGObject
/**
* Workaround for JSONModel multithreading issues
* https://github.com/icanzilb/JSONModel/issues/441
*/
- (instancetype)initWithDictionary:(NSDictionary *)dict error:(NSError **)err {
static NSMutableSet *classNames;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
classNames = [NSMutableSet new];
});
BOOL initSync;
@synchronized([self class])
{
NSString *className = NSStringFromClass([self class]);
initSync = ![classNames containsObject:className];
if(initSync)
{
[classNames addObject:className];
self = [super initWithDictionary:dict error:err];
}
}
if(!initSync)
{
self = [super initWithDictionary:dict error:err];
}
return self;
}
/**
* Gets the string presentation of the object.
* This method will be called when logging model object using `NSLog`.

View File

@@ -5,11 +5,15 @@
@synthesize values = _values;
@synthesize format = _format;
- (id) initWithValuesAndFormat: (NSArray*) values
format: (NSString*) format {
_values = values;
_format = format;
- (id)initWithValuesAndFormat:(NSArray *)values
format:(NSString *)format {
self = [super init];
if (self) {
_values = values;
_format = format;
}
return self;
}

View File

@@ -10,7 +10,7 @@
#import <SwaggerClient/SWGApiClient.h>
#import <SwaggerClient/SWGPet.h>
#import <SwaggerClient/SWGPetApi.h>
#import <SwaggerClient/SWGConfiguration.h>
#import <SwaggerClient/SWGDefaultConfiguration.h>
@interface SWGViewController ()
@@ -22,7 +22,7 @@
{
[super viewDidLoad];
SWGConfiguration *config = [SWGConfiguration sharedConfig];
SWGDefaultConfiguration *config = [SWGDefaultConfiguration sharedConfig];
config.debug = YES;
SWGPetApi *api = [[SWGPetApi alloc] init];

View File

@@ -6,7 +6,7 @@ This ObjC package is automatically generated by the [Swagger Codegen](https://gi
- API version: 1.0.0
- Package version:
- Build date: 2016-07-19T16:53:24.981+08:00
- Build date: 2016-08-04T12:24:22.869+02:00
- Build package: class io.swagger.codegen.languages.ObjcClientCodegen
## Requirements
@@ -40,7 +40,7 @@ Import the following:
```objc
#import <SwaggerClient/SWGApiClient.h>
#import <SwaggerClient/SWGConfiguration.h>
#import <SwaggerClient/SWGDefaultConfiguration.h>
// load models
#import <SwaggerClient/SWGCategory.h>
#import <SwaggerClient/SWGOrder.h>
@@ -64,7 +64,7 @@ Please follow the [installation procedure](#installation--usage) and then run th
```objc
SWGConfiguration *apiConfig = [SWGConfiguration sharedConfig];
SWGDefaultConfiguration *apiConfig = [SWGDefaultConfiguration sharedConfig];
// Configure OAuth2 access token for authorization: (authentication scheme: petstore_auth)
[apiConfig setAccessToken:@"YOUR_ACCESS_TOKEN"];
@@ -124,12 +124,6 @@ Class | Method | HTTP request | Description
## Documentation For Authorization
## api_key
- **Type**: API key
- **API key parameter name**: api_key
- **Location**: HTTP header
## petstore_auth
- **Type**: OAuth
@@ -139,6 +133,12 @@ Class | Method | HTTP request | Description
- **write:pets**: modify pets in your account
- **read:pets**: read your pets
## api_key
- **Type**: API key
- **API key parameter name**: api_key
- **Location**: HTTP header
## Author

View File

@@ -32,6 +32,6 @@ Pod::Spec.new do |s|
s.dependency 'AFNetworking', '~> 3'
s.dependency 'JSONModel', '~> 1.2'
s.dependency 'ISO8601', '~> 0.5'
s.dependency 'ISO8601', '~> 0.6'
end

View File

@@ -32,7 +32,7 @@
extern NSString* kSWGPetApiErrorDomain;
extern NSInteger kSWGPetApiMissingParamErrorCode;
+(instancetype) sharedAPI;
-(instancetype) initWithApiClient:(SWGApiClient *)apiClient NS_DESIGNATED_INITIALIZER;
/// Add a new pet to the store
///
@@ -42,7 +42,7 @@ extern NSInteger kSWGPetApiMissingParamErrorCode;
/// code:405 message:"Invalid input"
///
/// @return
-(NSNumber*) addPetWithBody: (SWGPet*) body
-(NSURLSessionTask*) addPetWithBody: (SWGPet*) body
completionHandler: (void (^)(NSError* error)) handler;
@@ -55,7 +55,7 @@ extern NSInteger kSWGPetApiMissingParamErrorCode;
/// code:400 message:"Invalid pet value"
///
/// @return
-(NSNumber*) deletePetWithPetId: (NSNumber*) petId
-(NSURLSessionTask*) deletePetWithPetId: (NSNumber*) petId
apiKey: (NSString*) apiKey
completionHandler: (void (^)(NSError* error)) handler;
@@ -69,7 +69,7 @@ extern NSInteger kSWGPetApiMissingParamErrorCode;
/// code:400 message:"Invalid status value"
///
/// @return NSArray<SWGPet>*
-(NSNumber*) findPetsByStatusWithStatus: (NSArray<NSString*>*) status
-(NSURLSessionTask*) findPetsByStatusWithStatus: (NSArray<NSString*>*) status
completionHandler: (void (^)(NSArray<SWGPet>* output, NSError* error)) handler;
@@ -82,7 +82,7 @@ extern NSInteger kSWGPetApiMissingParamErrorCode;
/// code:400 message:"Invalid tag value"
///
/// @return NSArray<SWGPet>*
-(NSNumber*) findPetsByTagsWithTags: (NSArray<NSString*>*) tags
-(NSURLSessionTask*) findPetsByTagsWithTags: (NSArray<NSString*>*) tags
completionHandler: (void (^)(NSArray<SWGPet>* output, NSError* error)) handler;
@@ -96,7 +96,7 @@ extern NSInteger kSWGPetApiMissingParamErrorCode;
/// code:404 message:"Pet not found"
///
/// @return SWGPet*
-(NSNumber*) getPetByIdWithPetId: (NSNumber*) petId
-(NSURLSessionTask*) getPetByIdWithPetId: (NSNumber*) petId
completionHandler: (void (^)(SWGPet* output, NSError* error)) handler;
@@ -110,7 +110,7 @@ extern NSInteger kSWGPetApiMissingParamErrorCode;
/// code:405 message:"Validation exception"
///
/// @return
-(NSNumber*) updatePetWithBody: (SWGPet*) body
-(NSURLSessionTask*) updatePetWithBody: (SWGPet*) body
completionHandler: (void (^)(NSError* error)) handler;
@@ -124,7 +124,7 @@ extern NSInteger kSWGPetApiMissingParamErrorCode;
/// code:405 message:"Invalid input"
///
/// @return
-(NSNumber*) updatePetWithFormWithPetId: (NSString*) petId
-(NSURLSessionTask*) updatePetWithFormWithPetId: (NSString*) petId
name: (NSString*) name
status: (NSString*) status
completionHandler: (void (^)(NSError* error)) handler;
@@ -140,7 +140,7 @@ extern NSInteger kSWGPetApiMissingParamErrorCode;
/// code:0 message:"successful operation"
///
/// @return
-(NSNumber*) uploadFileWithPetId: (NSNumber*) petId
-(NSURLSessionTask*) uploadFileWithPetId: (NSNumber*) petId
additionalMetadata: (NSString*) additionalMetadata
file: (NSURL*) file
completionHandler: (void (^)(NSError* error)) handler;

View File

@@ -5,7 +5,7 @@
@interface SWGPetApi ()
@property (nonatomic, strong) NSMutableDictionary *defaultHeaders;
@property (nonatomic, strong, readwrite) NSMutableDictionary *defaultHeaders;
@end
@@ -19,19 +19,11 @@ NSInteger kSWGPetApiMissingParamErrorCode = 234513;
#pragma mark - Initialize methods
- (instancetype) init {
self = [super init];
if (self) {
SWGConfiguration *config = [SWGConfiguration sharedConfig];
if (config.apiClient == nil) {
config.apiClient = [[SWGApiClient alloc] init];
}
_apiClient = config.apiClient;
_defaultHeaders = [NSMutableDictionary dictionary];
}
return self;
return [self initWithApiClient:[SWGApiClient sharedClient]];
}
- (id) initWithApiClient:(SWGApiClient *)apiClient {
-(instancetype) initWithApiClient:(SWGApiClient *)apiClient {
self = [super init];
if (self) {
_apiClient = apiClient;
@@ -42,15 +34,6 @@ NSInteger kSWGPetApiMissingParamErrorCode = 234513;
#pragma mark -
+ (instancetype)sharedAPI {
static SWGPetApi *sharedAPI;
static dispatch_once_t once;
dispatch_once(&once, ^{
sharedAPI = [[self alloc] init];
});
return sharedAPI;
}
-(NSString*) defaultHeaderForKey:(NSString*)key {
return self.defaultHeaders[key];
}
@@ -63,10 +46,6 @@ NSInteger kSWGPetApiMissingParamErrorCode = 234513;
[self.defaultHeaders setValue:value forKey:key];
}
-(NSUInteger) requestQueueSize {
return [SWGApiClient requestQueueSize];
}
#pragma mark - Api Methods
///
@@ -76,7 +55,7 @@ NSInteger kSWGPetApiMissingParamErrorCode = 234513;
///
/// @returns void
///
-(NSNumber*) addPetWithBody: (SWGPet*) body
-(NSURLSessionTask*) addPetWithBody: (SWGPet*) body
completionHandler: (void (^)(NSError* error)) handler {
NSMutableString* resourcePath = [NSMutableString stringWithFormat:@"/pet"];
@@ -124,8 +103,7 @@ NSInteger kSWGPetApiMissingParamErrorCode = 234513;
if(handler) {
handler(error);
}
}
];
}];
}
///
@@ -137,7 +115,7 @@ NSInteger kSWGPetApiMissingParamErrorCode = 234513;
///
/// @returns void
///
-(NSNumber*) deletePetWithPetId: (NSNumber*) petId
-(NSURLSessionTask*) deletePetWithPetId: (NSNumber*) petId
apiKey: (NSString*) apiKey
completionHandler: (void (^)(NSError* error)) handler {
// verify the required parameter 'petId' is set
@@ -202,8 +180,7 @@ NSInteger kSWGPetApiMissingParamErrorCode = 234513;
if(handler) {
handler(error);
}
}
];
}];
}
///
@@ -213,7 +190,7 @@ NSInteger kSWGPetApiMissingParamErrorCode = 234513;
///
/// @returns NSArray<SWGPet>*
///
-(NSNumber*) findPetsByStatusWithStatus: (NSArray<NSString*>*) status
-(NSURLSessionTask*) findPetsByStatusWithStatus: (NSArray<NSString*>*) status
completionHandler: (void (^)(NSArray<SWGPet>* output, NSError* error)) handler {
NSMutableString* resourcePath = [NSMutableString stringWithFormat:@"/pet/findByStatus"];
@@ -264,8 +241,7 @@ NSInteger kSWGPetApiMissingParamErrorCode = 234513;
if(handler) {
handler((NSArray<SWGPet>*)data, error);
}
}
];
}];
}
///
@@ -275,7 +251,7 @@ NSInteger kSWGPetApiMissingParamErrorCode = 234513;
///
/// @returns NSArray<SWGPet>*
///
-(NSNumber*) findPetsByTagsWithTags: (NSArray<NSString*>*) tags
-(NSURLSessionTask*) findPetsByTagsWithTags: (NSArray<NSString*>*) tags
completionHandler: (void (^)(NSArray<SWGPet>* output, NSError* error)) handler {
NSMutableString* resourcePath = [NSMutableString stringWithFormat:@"/pet/findByTags"];
@@ -326,8 +302,7 @@ NSInteger kSWGPetApiMissingParamErrorCode = 234513;
if(handler) {
handler((NSArray<SWGPet>*)data, error);
}
}
];
}];
}
///
@@ -337,7 +312,7 @@ NSInteger kSWGPetApiMissingParamErrorCode = 234513;
///
/// @returns SWGPet*
///
-(NSNumber*) getPetByIdWithPetId: (NSNumber*) petId
-(NSURLSessionTask*) getPetByIdWithPetId: (NSNumber*) petId
completionHandler: (void (^)(SWGPet* output, NSError* error)) handler {
// verify the required parameter 'petId' is set
if (petId == nil) {
@@ -376,7 +351,7 @@ NSInteger kSWGPetApiMissingParamErrorCode = 234513;
NSString *requestContentType = [self.apiClient.sanitizer selectHeaderContentType:@[]];
// Authentication setting
NSArray *authSettings = @[@"api_key", @"petstore_auth"];
NSArray *authSettings = @[@"petstore_auth", @"api_key"];
id bodyParam = nil;
NSMutableDictionary *formParams = [[NSMutableDictionary alloc] init];
@@ -398,8 +373,7 @@ NSInteger kSWGPetApiMissingParamErrorCode = 234513;
if(handler) {
handler((SWGPet*)data, error);
}
}
];
}];
}
///
@@ -409,7 +383,7 @@ NSInteger kSWGPetApiMissingParamErrorCode = 234513;
///
/// @returns void
///
-(NSNumber*) updatePetWithBody: (SWGPet*) body
-(NSURLSessionTask*) updatePetWithBody: (SWGPet*) body
completionHandler: (void (^)(NSError* error)) handler {
NSMutableString* resourcePath = [NSMutableString stringWithFormat:@"/pet"];
@@ -457,8 +431,7 @@ NSInteger kSWGPetApiMissingParamErrorCode = 234513;
if(handler) {
handler(error);
}
}
];
}];
}
///
@@ -472,7 +445,7 @@ NSInteger kSWGPetApiMissingParamErrorCode = 234513;
///
/// @returns void
///
-(NSNumber*) updatePetWithFormWithPetId: (NSString*) petId
-(NSURLSessionTask*) updatePetWithFormWithPetId: (NSString*) petId
name: (NSString*) name
status: (NSString*) status
completionHandler: (void (^)(NSError* error)) handler {
@@ -541,8 +514,7 @@ NSInteger kSWGPetApiMissingParamErrorCode = 234513;
if(handler) {
handler(error);
}
}
];
}];
}
///
@@ -556,7 +528,7 @@ NSInteger kSWGPetApiMissingParamErrorCode = 234513;
///
/// @returns void
///
-(NSNumber*) uploadFileWithPetId: (NSNumber*) petId
-(NSURLSessionTask*) uploadFileWithPetId: (NSNumber*) petId
additionalMetadata: (NSString*) additionalMetadata
file: (NSURL*) file
completionHandler: (void (^)(NSError* error)) handler {
@@ -623,8 +595,7 @@ NSInteger kSWGPetApiMissingParamErrorCode = 234513;
if(handler) {
handler(error);
}
}
];
}];
}

View File

@@ -32,7 +32,7 @@
extern NSString* kSWGStoreApiErrorDomain;
extern NSInteger kSWGStoreApiMissingParamErrorCode;
+(instancetype) sharedAPI;
-(instancetype) initWithApiClient:(SWGApiClient *)apiClient NS_DESIGNATED_INITIALIZER;
/// Delete purchase order by ID
/// For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
@@ -43,7 +43,7 @@ extern NSInteger kSWGStoreApiMissingParamErrorCode;
/// code:404 message:"Order not found"
///
/// @return
-(NSNumber*) deleteOrderWithOrderId: (NSString*) orderId
-(NSURLSessionTask*) deleteOrderWithOrderId: (NSString*) orderId
completionHandler: (void (^)(NSError* error)) handler;
@@ -54,7 +54,7 @@ extern NSInteger kSWGStoreApiMissingParamErrorCode;
/// code:200 message:"successful operation"
///
/// @return NSDictionary<NSString*, NSNumber*>*
-(NSNumber*) getInventoryWithCompletionHandler:
-(NSURLSessionTask*) getInventoryWithCompletionHandler:
(void (^)(NSDictionary<NSString*, NSNumber*>* output, NSError* error)) handler;
@@ -68,7 +68,7 @@ extern NSInteger kSWGStoreApiMissingParamErrorCode;
/// code:404 message:"Order not found"
///
/// @return SWGOrder*
-(NSNumber*) getOrderByIdWithOrderId: (NSString*) orderId
-(NSURLSessionTask*) getOrderByIdWithOrderId: (NSString*) orderId
completionHandler: (void (^)(SWGOrder* output, NSError* error)) handler;
@@ -81,7 +81,7 @@ extern NSInteger kSWGStoreApiMissingParamErrorCode;
/// code:400 message:"Invalid Order"
///
/// @return SWGOrder*
-(NSNumber*) placeOrderWithBody: (SWGOrder*) body
-(NSURLSessionTask*) placeOrderWithBody: (SWGOrder*) body
completionHandler: (void (^)(SWGOrder* output, NSError* error)) handler;

View File

@@ -5,7 +5,7 @@
@interface SWGStoreApi ()
@property (nonatomic, strong) NSMutableDictionary *defaultHeaders;
@property (nonatomic, strong, readwrite) NSMutableDictionary *defaultHeaders;
@end
@@ -19,19 +19,11 @@ NSInteger kSWGStoreApiMissingParamErrorCode = 234513;
#pragma mark - Initialize methods
- (instancetype) init {
self = [super init];
if (self) {
SWGConfiguration *config = [SWGConfiguration sharedConfig];
if (config.apiClient == nil) {
config.apiClient = [[SWGApiClient alloc] init];
}
_apiClient = config.apiClient;
_defaultHeaders = [NSMutableDictionary dictionary];
}
return self;
return [self initWithApiClient:[SWGApiClient sharedClient]];
}
- (id) initWithApiClient:(SWGApiClient *)apiClient {
-(instancetype) initWithApiClient:(SWGApiClient *)apiClient {
self = [super init];
if (self) {
_apiClient = apiClient;
@@ -42,15 +34,6 @@ NSInteger kSWGStoreApiMissingParamErrorCode = 234513;
#pragma mark -
+ (instancetype)sharedAPI {
static SWGStoreApi *sharedAPI;
static dispatch_once_t once;
dispatch_once(&once, ^{
sharedAPI = [[self alloc] init];
});
return sharedAPI;
}
-(NSString*) defaultHeaderForKey:(NSString*)key {
return self.defaultHeaders[key];
}
@@ -63,10 +46,6 @@ NSInteger kSWGStoreApiMissingParamErrorCode = 234513;
[self.defaultHeaders setValue:value forKey:key];
}
-(NSUInteger) requestQueueSize {
return [SWGApiClient requestQueueSize];
}
#pragma mark - Api Methods
///
@@ -76,7 +55,7 @@ NSInteger kSWGStoreApiMissingParamErrorCode = 234513;
///
/// @returns void
///
-(NSNumber*) deleteOrderWithOrderId: (NSString*) orderId
-(NSURLSessionTask*) deleteOrderWithOrderId: (NSString*) orderId
completionHandler: (void (^)(NSError* error)) handler {
// verify the required parameter 'orderId' is set
if (orderId == nil) {
@@ -137,8 +116,7 @@ NSInteger kSWGStoreApiMissingParamErrorCode = 234513;
if(handler) {
handler(error);
}
}
];
}];
}
///
@@ -146,7 +124,7 @@ NSInteger kSWGStoreApiMissingParamErrorCode = 234513;
/// Returns a map of status codes to quantities
/// @returns NSDictionary<NSString*, NSNumber*>*
///
-(NSNumber*) getInventoryWithCompletionHandler:
-(NSURLSessionTask*) getInventoryWithCompletionHandler:
(void (^)(NSDictionary<NSString*, NSNumber*>* output, NSError* error)) handler {
NSMutableString* resourcePath = [NSMutableString stringWithFormat:@"/store/inventory"];
@@ -193,8 +171,7 @@ NSInteger kSWGStoreApiMissingParamErrorCode = 234513;
if(handler) {
handler((NSDictionary<NSString*, NSNumber*>*)data, error);
}
}
];
}];
}
///
@@ -204,7 +181,7 @@ NSInteger kSWGStoreApiMissingParamErrorCode = 234513;
///
/// @returns SWGOrder*
///
-(NSNumber*) getOrderByIdWithOrderId: (NSString*) orderId
-(NSURLSessionTask*) getOrderByIdWithOrderId: (NSString*) orderId
completionHandler: (void (^)(SWGOrder* output, NSError* error)) handler {
// verify the required parameter 'orderId' is set
if (orderId == nil) {
@@ -265,8 +242,7 @@ NSInteger kSWGStoreApiMissingParamErrorCode = 234513;
if(handler) {
handler((SWGOrder*)data, error);
}
}
];
}];
}
///
@@ -276,7 +252,7 @@ NSInteger kSWGStoreApiMissingParamErrorCode = 234513;
///
/// @returns SWGOrder*
///
-(NSNumber*) placeOrderWithBody: (SWGOrder*) body
-(NSURLSessionTask*) placeOrderWithBody: (SWGOrder*) body
completionHandler: (void (^)(SWGOrder* output, NSError* error)) handler {
NSMutableString* resourcePath = [NSMutableString stringWithFormat:@"/store/order"];
@@ -324,8 +300,7 @@ NSInteger kSWGStoreApiMissingParamErrorCode = 234513;
if(handler) {
handler((SWGOrder*)data, error);
}
}
];
}];
}

View File

@@ -32,7 +32,7 @@
extern NSString* kSWGUserApiErrorDomain;
extern NSInteger kSWGUserApiMissingParamErrorCode;
+(instancetype) sharedAPI;
-(instancetype) initWithApiClient:(SWGApiClient *)apiClient NS_DESIGNATED_INITIALIZER;
/// Create user
/// This can only be done by the logged in user.
@@ -42,7 +42,7 @@ extern NSInteger kSWGUserApiMissingParamErrorCode;
/// code:0 message:"successful operation"
///
/// @return
-(NSNumber*) createUserWithBody: (SWGUser*) body
-(NSURLSessionTask*) createUserWithBody: (SWGUser*) body
completionHandler: (void (^)(NSError* error)) handler;
@@ -54,7 +54,7 @@ extern NSInteger kSWGUserApiMissingParamErrorCode;
/// code:0 message:"successful operation"
///
/// @return
-(NSNumber*) createUsersWithArrayInputWithBody: (NSArray<SWGUser>*) body
-(NSURLSessionTask*) createUsersWithArrayInputWithBody: (NSArray<SWGUser>*) body
completionHandler: (void (^)(NSError* error)) handler;
@@ -66,7 +66,7 @@ extern NSInteger kSWGUserApiMissingParamErrorCode;
/// code:0 message:"successful operation"
///
/// @return
-(NSNumber*) createUsersWithListInputWithBody: (NSArray<SWGUser>*) body
-(NSURLSessionTask*) createUsersWithListInputWithBody: (NSArray<SWGUser>*) body
completionHandler: (void (^)(NSError* error)) handler;
@@ -79,7 +79,7 @@ extern NSInteger kSWGUserApiMissingParamErrorCode;
/// code:404 message:"User not found"
///
/// @return
-(NSNumber*) deleteUserWithUsername: (NSString*) username
-(NSURLSessionTask*) deleteUserWithUsername: (NSString*) username
completionHandler: (void (^)(NSError* error)) handler;
@@ -93,7 +93,7 @@ extern NSInteger kSWGUserApiMissingParamErrorCode;
/// code:404 message:"User not found"
///
/// @return SWGUser*
-(NSNumber*) getUserByNameWithUsername: (NSString*) username
-(NSURLSessionTask*) getUserByNameWithUsername: (NSString*) username
completionHandler: (void (^)(SWGUser* output, NSError* error)) handler;
@@ -107,7 +107,7 @@ extern NSInteger kSWGUserApiMissingParamErrorCode;
/// code:400 message:"Invalid username/password supplied"
///
/// @return NSString*
-(NSNumber*) loginUserWithUsername: (NSString*) username
-(NSURLSessionTask*) loginUserWithUsername: (NSString*) username
password: (NSString*) password
completionHandler: (void (^)(NSString* output, NSError* error)) handler;
@@ -119,7 +119,7 @@ extern NSInteger kSWGUserApiMissingParamErrorCode;
/// code:0 message:"successful operation"
///
/// @return
-(NSNumber*) logoutUserWithCompletionHandler:
-(NSURLSessionTask*) logoutUserWithCompletionHandler:
(void (^)(NSError* error)) handler;
@@ -133,7 +133,7 @@ extern NSInteger kSWGUserApiMissingParamErrorCode;
/// code:404 message:"User not found"
///
/// @return
-(NSNumber*) updateUserWithUsername: (NSString*) username
-(NSURLSessionTask*) updateUserWithUsername: (NSString*) username
body: (SWGUser*) body
completionHandler: (void (^)(NSError* error)) handler;

View File

@@ -5,7 +5,7 @@
@interface SWGUserApi ()
@property (nonatomic, strong) NSMutableDictionary *defaultHeaders;
@property (nonatomic, strong, readwrite) NSMutableDictionary *defaultHeaders;
@end
@@ -19,19 +19,11 @@ NSInteger kSWGUserApiMissingParamErrorCode = 234513;
#pragma mark - Initialize methods
- (instancetype) init {
self = [super init];
if (self) {
SWGConfiguration *config = [SWGConfiguration sharedConfig];
if (config.apiClient == nil) {
config.apiClient = [[SWGApiClient alloc] init];
}
_apiClient = config.apiClient;
_defaultHeaders = [NSMutableDictionary dictionary];
}
return self;
return [self initWithApiClient:[SWGApiClient sharedClient]];
}
- (id) initWithApiClient:(SWGApiClient *)apiClient {
-(instancetype) initWithApiClient:(SWGApiClient *)apiClient {
self = [super init];
if (self) {
_apiClient = apiClient;
@@ -42,15 +34,6 @@ NSInteger kSWGUserApiMissingParamErrorCode = 234513;
#pragma mark -
+ (instancetype)sharedAPI {
static SWGUserApi *sharedAPI;
static dispatch_once_t once;
dispatch_once(&once, ^{
sharedAPI = [[self alloc] init];
});
return sharedAPI;
}
-(NSString*) defaultHeaderForKey:(NSString*)key {
return self.defaultHeaders[key];
}
@@ -63,10 +46,6 @@ NSInteger kSWGUserApiMissingParamErrorCode = 234513;
[self.defaultHeaders setValue:value forKey:key];
}
-(NSUInteger) requestQueueSize {
return [SWGApiClient requestQueueSize];
}
#pragma mark - Api Methods
///
@@ -76,7 +55,7 @@ NSInteger kSWGUserApiMissingParamErrorCode = 234513;
///
/// @returns void
///
-(NSNumber*) createUserWithBody: (SWGUser*) body
-(NSURLSessionTask*) createUserWithBody: (SWGUser*) body
completionHandler: (void (^)(NSError* error)) handler {
NSMutableString* resourcePath = [NSMutableString stringWithFormat:@"/user"];
@@ -124,8 +103,7 @@ NSInteger kSWGUserApiMissingParamErrorCode = 234513;
if(handler) {
handler(error);
}
}
];
}];
}
///
@@ -135,7 +113,7 @@ NSInteger kSWGUserApiMissingParamErrorCode = 234513;
///
/// @returns void
///
-(NSNumber*) createUsersWithArrayInputWithBody: (NSArray<SWGUser>*) body
-(NSURLSessionTask*) createUsersWithArrayInputWithBody: (NSArray<SWGUser>*) body
completionHandler: (void (^)(NSError* error)) handler {
NSMutableString* resourcePath = [NSMutableString stringWithFormat:@"/user/createWithArray"];
@@ -183,8 +161,7 @@ NSInteger kSWGUserApiMissingParamErrorCode = 234513;
if(handler) {
handler(error);
}
}
];
}];
}
///
@@ -194,7 +171,7 @@ NSInteger kSWGUserApiMissingParamErrorCode = 234513;
///
/// @returns void
///
-(NSNumber*) createUsersWithListInputWithBody: (NSArray<SWGUser>*) body
-(NSURLSessionTask*) createUsersWithListInputWithBody: (NSArray<SWGUser>*) body
completionHandler: (void (^)(NSError* error)) handler {
NSMutableString* resourcePath = [NSMutableString stringWithFormat:@"/user/createWithList"];
@@ -242,8 +219,7 @@ NSInteger kSWGUserApiMissingParamErrorCode = 234513;
if(handler) {
handler(error);
}
}
];
}];
}
///
@@ -253,7 +229,7 @@ NSInteger kSWGUserApiMissingParamErrorCode = 234513;
///
/// @returns void
///
-(NSNumber*) deleteUserWithUsername: (NSString*) username
-(NSURLSessionTask*) deleteUserWithUsername: (NSString*) username
completionHandler: (void (^)(NSError* error)) handler {
// verify the required parameter 'username' is set
if (username == nil) {
@@ -314,8 +290,7 @@ NSInteger kSWGUserApiMissingParamErrorCode = 234513;
if(handler) {
handler(error);
}
}
];
}];
}
///
@@ -325,7 +300,7 @@ NSInteger kSWGUserApiMissingParamErrorCode = 234513;
///
/// @returns SWGUser*
///
-(NSNumber*) getUserByNameWithUsername: (NSString*) username
-(NSURLSessionTask*) getUserByNameWithUsername: (NSString*) username
completionHandler: (void (^)(SWGUser* output, NSError* error)) handler {
// verify the required parameter 'username' is set
if (username == nil) {
@@ -386,8 +361,7 @@ NSInteger kSWGUserApiMissingParamErrorCode = 234513;
if(handler) {
handler((SWGUser*)data, error);
}
}
];
}];
}
///
@@ -399,7 +373,7 @@ NSInteger kSWGUserApiMissingParamErrorCode = 234513;
///
/// @returns NSString*
///
-(NSNumber*) loginUserWithUsername: (NSString*) username
-(NSURLSessionTask*) loginUserWithUsername: (NSString*) username
password: (NSString*) password
completionHandler: (void (^)(NSString* output, NSError* error)) handler {
NSMutableString* resourcePath = [NSMutableString stringWithFormat:@"/user/login"];
@@ -453,8 +427,7 @@ NSInteger kSWGUserApiMissingParamErrorCode = 234513;
if(handler) {
handler((NSString*)data, error);
}
}
];
}];
}
///
@@ -462,7 +435,7 @@ NSInteger kSWGUserApiMissingParamErrorCode = 234513;
///
/// @returns void
///
-(NSNumber*) logoutUserWithCompletionHandler:
-(NSURLSessionTask*) logoutUserWithCompletionHandler:
(void (^)(NSError* error)) handler {
NSMutableString* resourcePath = [NSMutableString stringWithFormat:@"/user/logout"];
@@ -509,8 +482,7 @@ NSInteger kSWGUserApiMissingParamErrorCode = 234513;
if(handler) {
handler(error);
}
}
];
}];
}
///
@@ -522,7 +494,7 @@ NSInteger kSWGUserApiMissingParamErrorCode = 234513;
///
/// @returns void
///
-(NSNumber*) updateUserWithUsername: (NSString*) username
-(NSURLSessionTask*) updateUserWithUsername: (NSString*) username
body: (SWGUser*) body
completionHandler: (void (^)(NSError* error)) handler {
// verify the required parameter 'username' is set
@@ -585,8 +557,7 @@ NSInteger kSWGUserApiMissingParamErrorCode = 234513;
if(handler) {
handler(error);
}
}
];
}];
}

View File

@@ -1,5 +1,4 @@
#import <Foundation/Foundation.h>
#import <ISO8601/ISO8601.h>
#import <JSONModel/JSONValueTransformer.h>
/**

View File

@@ -1,3 +1,4 @@
#import <ISO8601/NSDate+ISO8601.h>
#import "JSONValueTransformer+ISO8601.h"
@implementation JSONValueTransformer (ISO8601)

View File

@@ -28,15 +28,13 @@
@protocol SWGApi <NSObject>
@property(nonatomic, assign) SWGApiClient *apiClient;
@property(readonly, nonatomic, strong) SWGApiClient *apiClient;
-(id) initWithApiClient:(SWGApiClient *)apiClient;
-(instancetype) initWithApiClient:(SWGApiClient *)apiClient;
-(void) addHeader:(NSString*)value forKey:(NSString*)key DEPRECATED_MSG_ATTRIBUTE("setDefaultHeaderValue:forKey:");
-(void) setDefaultHeaderValue:(NSString*) value forKey:(NSString*)key;
-(NSString*) defaultHeaderForKey:(NSString*)key;
-(NSUInteger) requestQueueSize;
@end

View File

@@ -1,13 +1,7 @@
#import <Foundation/Foundation.h>
#import <ISO8601/ISO8601.h>
#import <AFNetworking/AFNetworking.h>
#import "SWGJSONResponseSerializer.h"
#import "SWGJSONRequestSerializer.h"
#import "SWGQueryParamCollection.h"
#import "SWGConfiguration.h"
#import "SWGResponseDeserializer.h"
#import "SWGSanitizer.h"
#import "SWGLogger.h"
/**
* Swagger Petstore
@@ -33,16 +27,6 @@
* limitations under the License.
*/
#import "SWGCategory.h"
#import "SWGOrder.h"
#import "SWGPet.h"
#import "SWGTag.h"
#import "SWGUser.h"
@class SWGConfiguration;
/**
* A key for `NSError` user info dictionaries.
*
@@ -50,15 +34,15 @@
*/
extern NSString *const SWGResponseObjectErrorKey;
@interface SWGApiClient : AFHTTPSessionManager
@property (nonatomic, strong, readonly) id<SWGConfiguration> configuration;
@property(nonatomic, assign) NSURLRequestCachePolicy cachePolicy;
@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;
@property(nonatomic, strong) id<SWGResponseDeserializer> responseDeserializer;
@property(nonatomic, strong) id<SWGSanitizer> sanitizer;
@@ -74,13 +58,6 @@ extern NSString *const SWGResponseObjectErrorKey;
*/
+(void)setCacheEnabled:(BOOL) enabled;
/**
* Gets the request queue size
*
* @return The size of `queuedRequests` static variable.
*/
+(NSUInteger)requestQueueSize;
/**
* Sets the client unreachable
*
@@ -109,27 +86,6 @@ extern NSString *const SWGResponseObjectErrorKey;
*/
+(AFNetworkReachabilityStatus) getReachabilityStatus;
/**
* Gets the next request id
*
* @return The next executed request id.
*/
+(NSNumber*) nextRequestId;
/**
* Generates request id and add it to the queue
*
* @return The next executed request id.
*/
+(NSNumber*) queueRequest;
/**
* Removes request id from the queue
*
* @param requestId The request which will be removed.
*/
+(void) cancelRequest:(NSNumber*)requestId;
/**
* Customizes the behavior when the reachability changed
*
@@ -137,6 +93,11 @@ extern NSString *const SWGResponseObjectErrorKey;
*/
+(void) setReachabilityChangeBlock:(void(^)(int))changeBlock;
/**
* Gets client singleton instance
*/
+ (instancetype) sharedClient;
/**
* Sets the api client reachability strategy
*/
@@ -162,6 +123,14 @@ extern NSString *const SWGResponseObjectErrorKey;
queryParams:(NSDictionary **)querys
WithAuthSettings:(NSArray *)authSettings;
/**
* Initializes the session manager with a configuration.
*
* @param configuration The configuration implementation
*/
- (instancetype)initWithConfiguration:(id<SWGConfiguration>)configuration;
/**
* Performs request
*
@@ -176,21 +145,21 @@ extern NSString *const SWGResponseObjectErrorKey;
* @param responseContentType Response content-type.
* @param completionBlock The block will be executed when the request completed.
*
* @return The request id.
* @return The created session task.
*/
-(NSNumber*) requestWithPath:(NSString*) path
method:(NSString*) method
pathParams:(NSDictionary *) pathParams
queryParams:(NSDictionary*) queryParams
formParams:(NSDictionary *) formParams
files:(NSDictionary *) files
body:(id) body
headerParams:(NSDictionary*) headerParams
authSettings:(NSArray *) authSettings
requestContentType:(NSString*) requestContentType
responseContentType:(NSString*) responseContentType
responseType:(NSString *) responseType
completionBlock:(void (^)(id, NSError *))completionBlock;
- (NSURLSessionTask*) requestWithPath: (NSString*) path
method: (NSString*) method
pathParams: (NSDictionary *) pathParams
queryParams: (NSDictionary*) queryParams
formParams: (NSDictionary *) formParams
files: (NSDictionary *) files
body: (id) body
headerParams: (NSDictionary*) headerParams
authSettings: (NSArray *) authSettings
requestContentType: (NSString*) requestContentType
responseContentType: (NSString*) responseContentType
responseType: (NSString *) responseType
completionBlock: (void (^)(id, NSError *))completionBlock;
/**
* Custom security policy
@@ -199,12 +168,4 @@ extern NSString *const SWGResponseObjectErrorKey;
*/
- (AFSecurityPolicy *) customSecurityPolicy;
/**
* SWGConfiguration return sharedConfig
*
* @return SWGConfiguration
*/
- (SWGConfiguration*) configuration;
@end

View File

@@ -1,10 +1,16 @@
#import <ISO8601/NSDate+ISO8601.h>
#import "SWGApiClient.h"
#import "SWGJSONRequestSerializer.h"
#import "SWGJSONResponseSerializer.h"
#import "SWGQueryParamCollection.h"
#import "SWGDefaultConfiguration.h"
NSString *const SWGResponseObjectErrorKey = @"SWGResponseObject";
static NSUInteger requestId = 0;
static bool offlineState = false;
static NSMutableSet * queuedRequests = nil;
static bool cacheEnabled = false;
static AFNetworkReachabilityStatus reachabilityStatus = AFNetworkReachabilityStatusNotReachable;
static void (^reachabilityChangeBlock)(int);
@@ -36,38 +42,61 @@ static NSString * SWG__fileNameForResponse(NSURLResponse *response) {
@interface SWGApiClient ()
@property (nonatomic, strong) NSDictionary* HTTPResponseHeaders;
@property (nonatomic, strong, readwrite) id<SWGConfiguration> configuration;
@end
@implementation SWGApiClient
#pragma mark - Singleton Methods
+ (instancetype) sharedClient {
static SWGApiClient *sharedClient = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedClient = [[self alloc] init];
});
return sharedClient;
}
#pragma mark - Initialize Methods
- (instancetype)init {
NSString *baseUrl = [[SWGConfiguration sharedConfig] host];
return [self initWithBaseURL:[NSURL URLWithString:baseUrl]];
return [self initWithConfiguration:[SWGDefaultConfiguration sharedConfig]];
}
- (instancetype)initWithBaseURL:(NSURL *)url {
return [self initWithBaseURL:url
configuration:[SWGDefaultConfiguration sharedConfig]];
}
- (instancetype)initWithConfiguration:(id<SWGConfiguration>)configuration {
return [self initWithBaseURL:[NSURL URLWithString:configuration.host] configuration:configuration];
}
- (instancetype)initWithBaseURL:(NSURL *)url
configuration:(id<SWGConfiguration>)configuration {
self = [super initWithBaseURL:url];
if (self) {
self.timeoutInterval = 60;
_configuration = configuration;
_timeoutInterval = 60;
_responseDeserializer = [[SWGResponseDeserializer alloc] init];
_sanitizer = [[SWGSanitizer alloc] init];
self.requestSerializer = [AFJSONRequestSerializer serializer];
self.responseSerializer = [AFJSONResponseSerializer serializer];
self.securityPolicy = [self customSecurityPolicy];
self.responseDeserializer = [[SWGResponseDeserializer alloc] init];
self.sanitizer = [[SWGSanitizer alloc] init];
// configure reachability
[self configureCacheReachibility];
}
return self;
}
+ (void)initialize {
if (self == [SWGApiClient class]) {
queuedRequests = [[NSMutableSet alloc] init];
// initialize URL cache
[self configureCacheWithMemoryAndDiskCapacity:4*1024*1024 diskSize:32*1024*1024];
}
return self;
}
#pragma mark - Setter Methods
@@ -113,43 +142,6 @@ static NSString * SWG__fileNameForResponse(NSURLResponse *response) {
[NSURLCache setSharedURLCache:cache];
}
#pragma mark - Request Methods
+(NSUInteger)requestQueueSize {
return [queuedRequests count];
}
+(NSNumber*) nextRequestId {
@synchronized(self) {
return @(++requestId);
}
}
+(NSNumber*) queueRequest {
NSNumber* requestId = [[self class] nextRequestId];
SWGDebugLog(@"added %@ to request queue", requestId);
[queuedRequests addObject:requestId];
return requestId;
}
+(void) cancelRequest:(NSNumber*)requestId {
[queuedRequests removeObject:requestId];
}
-(Boolean) executeRequestWithId:(NSNumber*) requestId {
NSSet* matchingItems = [queuedRequests objectsPassingTest:^BOOL(id obj, BOOL *stop) {
return [obj intValue] == [requestId intValue];
}];
if (matchingItems.count == 1) {
SWGDebugLog(@"removed request id %@", requestId);
[queuedRequests removeObject:requestId];
return YES;
} else {
return NO;
}
}
#pragma mark - Reachability Methods
+(AFNetworkReachabilityStatus) getReachabilityStatus {
@@ -179,23 +171,19 @@ static NSString * SWG__fileNameForResponse(NSURLResponse *response) {
[self.reachabilityManager startMonitoring];
}
#pragma mark - Operation Methods
#pragma mark - Task Methods
- (void) operationWithCompletionBlock: (NSURLRequest *)request
requestId: (NSNumber *) requestId
completionBlock: (void (^)(id, NSError *))completionBlock {
__weak __typeof(self)weakSelf = self;
NSURLSessionDataTask* op = [self dataTaskWithRequest:request completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
__strong __typeof(weakSelf)strongSelf = weakSelf;
if (![strongSelf executeRequestWithId:requestId]) {
return;
}
- (NSURLSessionDataTask*) taskWithCompletionBlock: (NSURLRequest *)request
completionBlock: (void (^)(id, NSError *))completionBlock {
NSURLSessionDataTask *task = [self dataTaskWithRequest:request completionHandler:^(NSURLResponse * _Nonnull response, id _Nullable responseObject, NSError * _Nullable error) {
SWGDebugLogResponse(response, responseObject,request,error);
strongSelf.HTTPResponseHeaders = SWG__headerFieldsForResponse(response);
if(!error) {
completionBlock(responseObject, nil);
return;
}
NSMutableDictionary *userInfo = [error.userInfo mutableCopy];
if (responseObject) {
// Add in the (parsed) response body.
@@ -204,20 +192,18 @@ static NSString * SWG__fileNameForResponse(NSURLResponse *response) {
NSError *augmentedError = [error initWithDomain:error.domain code:error.code userInfo:userInfo];
completionBlock(nil, augmentedError);
}];
[op resume];
return task;
}
- (void) downloadOperationWithCompletionBlock: (NSURLRequest *)request
requestId: (NSNumber *) requestId
completionBlock: (void (^)(id, NSError *))completionBlock {
__weak __typeof(self)weakSelf = self;
NSURLSessionDataTask* op = [self dataTaskWithRequest:request completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
__strong __typeof(weakSelf)strongSelf = weakSelf;
if (![strongSelf executeRequestWithId:requestId]) {
return;
}
strongSelf.HTTPResponseHeaders = SWG__headerFieldsForResponse(response);
- (NSURLSessionDataTask*) downloadTaskWithCompletionBlock: (NSURLRequest *)request
completionBlock: (void (^)(id, NSError *))completionBlock {
id<SWGConfiguration> config = self.configuration;
NSURLSessionDataTask* task = [self dataTaskWithRequest:request completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
SWGDebugLogResponse(response, responseObject,request,error);
if(error) {
NSMutableDictionary *userInfo = [error.userInfo mutableCopy];
if (responseObject) {
@@ -226,8 +212,9 @@ static NSString * SWG__fileNameForResponse(NSURLResponse *response) {
NSError *augmentedError = [error initWithDomain:error.domain code:error.code userInfo:userInfo];
completionBlock(nil, augmentedError);
}
NSString *directory = [self configuration].tempFolderPath ?: NSTemporaryDirectory();
NSString * filename = SWG__fileNameForResponse(response);
NSString *directory = config.tempFolderPath ?: NSTemporaryDirectory();
NSString *filename = SWG__fileNameForResponse(response);
NSString *filepath = [directory stringByAppendingPathComponent:filename];
NSURL *file = [NSURL fileURLWithPath:filepath];
@@ -236,24 +223,26 @@ static NSString * SWG__fileNameForResponse(NSURLResponse *response) {
completionBlock(file, nil);
}];
[op resume];
return task;
}
#pragma mark - Perform Request Methods
#pragma mark - Perform Request Methods
- (NSURLSessionTask*) requestWithPath: (NSString*) path
method: (NSString*) method
pathParams: (NSDictionary *) pathParams
queryParams: (NSDictionary*) queryParams
formParams: (NSDictionary *) formParams
files: (NSDictionary *) files
body: (id) body
headerParams: (NSDictionary*) headerParams
authSettings: (NSArray *) authSettings
requestContentType: (NSString*) requestContentType
responseContentType: (NSString*) responseContentType
responseType: (NSString *) responseType
completionBlock: (void (^)(id, NSError *))completionBlock {
-(NSNumber*) requestWithPath: (NSString*) path
method: (NSString*) method
pathParams: (NSDictionary *) pathParams
queryParams: (NSDictionary*) queryParams
formParams: (NSDictionary *) formParams
files: (NSDictionary *) files
body: (id) body
headerParams: (NSDictionary*) headerParams
authSettings: (NSArray *) authSettings
requestContentType: (NSString*) requestContentType
responseContentType: (NSString*) responseContentType
responseType: (NSString *) responseType
completionBlock: (void (^)(id, NSError *))completionBlock {
// setting request serializer
if ([requestContentType isEqualToString:@"application/json"]) {
self.requestSerializer = [SWGJSONRequestSerializer serializer];
@@ -359,14 +348,16 @@ static NSString * SWG__fileNameForResponse(NSURLResponse *response) {
[self postProcessRequest:request];
NSNumber* requestId = [SWGApiClient queueRequest];
NSURLSessionTask *task = nil;
if ([responseType isEqualToString:@"NSURL*"] || [responseType isEqualToString:@"NSURL"]) {
[self downloadOperationWithCompletionBlock:request requestId:requestId completionBlock:^(id data, NSError *error) {
task = [self downloadTaskWithCompletionBlock:request completionBlock:^(id data, NSError *error) {
completionBlock(data, error);
}];
}
else {
[self operationWithCompletionBlock:request requestId:requestId completionBlock:^(id data, NSError *error) {
task = [self taskWithCompletionBlock:request completionBlock:^(id data, NSError *error) {
NSError * serializationError;
id response = [self.responseDeserializer deserialize:data class:responseType error:&serializationError];
if(!response && !error){
@@ -375,7 +366,10 @@ static NSString * SWG__fileNameForResponse(NSURLResponse *response) {
completionBlock(response, error);
}];
}
return requestId;
[task resume];
return task;
}
//Added for easier override to modify request
@@ -455,10 +449,11 @@ static NSString * SWG__fileNameForResponse(NSURLResponse *response) {
NSMutableDictionary *headersWithAuth = [NSMutableDictionary dictionaryWithDictionary:*headers];
NSMutableDictionary *querysWithAuth = [NSMutableDictionary dictionaryWithDictionary:*querys];
NSDictionary* configurationAuthSettings = [[self configuration] authSettings];
id<SWGConfiguration> config = self.configuration;
for (NSString *auth in authSettings) {
NSDictionary *authSetting = configurationAuthSettings[auth];
NSDictionary *authSetting = config.authSettings[auth];
if(!authSetting) { // auth setting is set only if the key is non-empty
continue;
}
@@ -479,11 +474,11 @@ static NSString * SWG__fileNameForResponse(NSURLResponse *response) {
- (AFSecurityPolicy *) customSecurityPolicy {
AFSecurityPolicy *securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeNone];
SWGConfiguration *config = [self configuration];
id<SWGConfiguration> config = self.configuration;
if (config.sslCaCert) {
NSData *certData = [NSData dataWithContentsOfFile:config.sslCaCert];
[securityPolicy setPinnedCertificates:@[certData]];
[securityPolicy setPinnedCertificates:[NSSet setWithObject:certData]];
}
if (config.verifySSL) {
@@ -497,8 +492,4 @@ static NSString * SWG__fileNameForResponse(NSURLResponse *response) {
return securityPolicy;
}
- (SWGConfiguration*) configuration {
return [SWGConfiguration sharedConfig];
}
@end

View File

@@ -0,0 +1,14 @@
/** The `SWGBasicAuthTokenProvider` class creates a basic auth token from username and password.
*
* 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.
*/
#import <Foundation/Foundation.h>
@interface SWGBasicAuthTokenProvider : NSObject
+ (NSString *)createBasicAuthTokenWithUsername:(NSString *)username password:(NSString *)password;
@end

View File

@@ -0,0 +1,19 @@
#import "SWGBasicAuthTokenProvider.h"
@implementation SWGBasicAuthTokenProvider
+ (NSString *)createBasicAuthTokenWithUsername:(NSString *)username password:(NSString *)password {
// return empty string if username and password are empty
if (username.length == 0 && password.length == 0){
return @"";
}
NSString *basicAuthCredentials = [NSString stringWithFormat:@"%@:%@", username, password];
NSData *data = [basicAuthCredentials dataUsingEncoding:NSUTF8StringEncoding];
basicAuthCredentials = [NSString stringWithFormat:@"Basic %@", [data base64EncodedStringWithOptions:0]];
return basicAuthCredentials;
}
@end

View File

@@ -1,5 +1,4 @@
#import <Foundation/Foundation.h>
#import "SWGApiClient.h"
#import "SWGLogger.h"
/**
@@ -26,157 +25,73 @@
* limitations under the License.
*/
@class SWGApiClient;
@interface SWGConfiguration : NSObject
@protocol SWGConfiguration <NSObject>
/**
* Default api logger
* Api logger
*/
@property (nonatomic, strong) SWGLogger * logger;
@property (readonly, nonatomic) SWGLogger *logger;
/**
* Default api client
* Base url
*/
@property (nonatomic) SWGApiClient *apiClient;
/**
* Default base url
*/
@property (nonatomic) NSString *host;
@property (readonly, nonatomic) NSString *host;
/**
* Api key values for Api Key type Authentication
*
* To add or remove api key, use `setApiKey:forApiKeyIdentifier:`.
*/
@property (readonly, nonatomic, strong) NSDictionary *apiKey;
@property (readonly, nonatomic) NSDictionary *apiKey;
/**
* Api key prefix values to be prepend to the respective api key
*
* To add or remove prefix, use `setApiKeyPrefix:forApiKeyPrefixIdentifier:`.
*/
@property (readonly, nonatomic, strong) NSDictionary *apiKeyPrefix;
@property (readonly, nonatomic) NSDictionary *apiKeyPrefix;
/**
* Username for HTTP Basic Authentication
*/
@property (nonatomic) NSString *username;
@property (readonly, nonatomic) NSString *username;
/**
* Password for HTTP Basic Authentication
*/
@property (nonatomic) NSString *password;
@property (readonly, nonatomic) NSString *password;
/**
* Access token for OAuth
*/
@property (nonatomic) NSString *accessToken;
@property (readonly, nonatomic) NSString *accessToken;
/**
* Temp folder for file download
*/
@property (nonatomic) NSString *tempFolderPath;
@property (readonly, nonatomic) NSString *tempFolderPath;
/**
* Debug switch, default false
*/
@property (nonatomic) BOOL debug;
/**
* Gets configuration singleton instance
*/
+ (instancetype) sharedConfig;
@property (readonly, nonatomic) BOOL debug;
/**
* SSL/TLS verification
* Set this to NO to skip verifying SSL certificate when calling API from https server
*/
@property (nonatomic) BOOL verifySSL;
@property (readonly, nonatomic) BOOL verifySSL;
/**
* SSL/TLS verification
* Set this to customize the certificate file to verify the peer
*/
@property (nonatomic) NSString *sslCaCert;
@property (readonly, nonatomic) NSString *sslCaCert;
/**
* Sets API key
*
* To remove a apiKey for an identifier, just set the apiKey to nil.
*
* @param apiKey API key or token.
* @param identifier API key identifier (authentication schema).
*
* Authentication Settings
*/
- (void) setApiKey:(NSString *)apiKey forApiKeyIdentifier:(NSString*)identifier;
/**
* Removes api key
*
* @param identifier API key identifier.
*/
- (void) removeApiKey:(NSString *)identifier;
/**
* Sets the prefix for API key
*
* @param apiKeyPrefix API key prefix.
* @param identifier API key identifier.
*/
- (void) setApiKeyPrefix:(NSString *)prefix forApiKeyPrefixIdentifier:(NSString *)identifier;
/**
* Removes api key prefix
*
* @param identifier API key identifier.
*/
- (void) removeApiKeyPrefix:(NSString *)identifier;
/**
* Gets API key (with prefix if set)
*/
- (NSString *) getApiKeyWithPrefix:(NSString *) key;
/**
* Gets Basic Auth token
*/
- (NSString *) getBasicAuthToken;
/**
* Gets OAuth access token
*/
- (NSString *) getAccessToken;
/**
* Gets Authentication Settings
*/
- (NSDictionary *) authSettings;
@property (readonly, nonatomic) NSDictionary *authSettings;
/**
* Default headers for all services
*/
@property (readonly, nonatomic, strong) NSDictionary *defaultHeaders;
/**
* Removes header from defaultHeaders
*
* @param Header name.
*/
-(void) removeDefaultHeaderForKey:(NSString*)key;
/**
* Sets the header for key
*
* @param value Value for header name
* @param key Header name
*/
-(void) setDefaultHeaderValue:(NSString*) value forKey:(NSString*)key;
/**
* @param Header key name.
*/
-(NSString*) defaultHeaderForKey:(NSString*)key;
@end
@end

View File

@@ -0,0 +1,175 @@
#import <Foundation/Foundation.h>
#import "SWGConfiguration.h"
/**
* Swagger Petstore
* This is a sample server Petstore server. You can find out more about Swagger at <a href=\"http://swagger.io\">http://swagger.io</a> or on irc.freenode.net, #swagger. For this sample, you can use the api key \"special-key\" to test the authorization filters
*
* OpenAPI spec version: 1.0.0
* Contact: apiteam@wordnik.com
*
* NOTE: This class is auto generated by the swagger code generator program.
* https://github.com/swagger-api/swagger-codegen.git
* Do not edit the class manually.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@interface SWGDefaultConfiguration : NSObject <SWGConfiguration>
/**
* Default api logger
*/
@property (nonatomic, strong) SWGLogger * logger;
/**
* Default base url
*/
@property (nonatomic) NSString *host;
/**
* Api key values for Api Key type Authentication
*
* To add or remove api key, use `setApiKey:forApiKeyIdentifier:`.
*/
@property (readonly, nonatomic, strong) NSDictionary *apiKey;
/**
* Api key prefix values to be prepend to the respective api key
*
* To add or remove prefix, use `setApiKeyPrefix:forApiKeyPrefixIdentifier:`.
*/
@property (readonly, nonatomic, strong) NSDictionary *apiKeyPrefix;
/**
* Username for HTTP Basic Authentication
*/
@property (nonatomic) NSString *username;
/**
* Password for HTTP Basic Authentication
*/
@property (nonatomic) NSString *password;
/**
* Access token for OAuth
*/
@property (nonatomic) NSString *accessToken;
/**
* Temp folder for file download
*/
@property (nonatomic) NSString *tempFolderPath;
/**
* Debug switch, default false
*/
@property (nonatomic) BOOL debug;
/**
* Gets configuration singleton instance
*/
+ (instancetype) sharedConfig;
/**
* SSL/TLS verification
* Set this to NO to skip verifying SSL certificate when calling API from https server
*/
@property (nonatomic) BOOL verifySSL;
/**
* SSL/TLS verification
* Set this to customize the certificate file to verify the peer
*/
@property (nonatomic) NSString *sslCaCert;
/**
* Sets API key
*
* To remove a apiKey for an identifier, just set the apiKey to nil.
*
* @param apiKey API key or token.
* @param identifier API key identifier (authentication schema).
*
*/
- (void) setApiKey:(NSString *)apiKey forApiKeyIdentifier:(NSString*)identifier;
/**
* Removes api key
*
* @param identifier API key identifier.
*/
- (void) removeApiKey:(NSString *)identifier;
/**
* Sets the prefix for API key
*
* @param apiKeyPrefix API key prefix.
* @param identifier API key identifier.
*/
- (void) setApiKeyPrefix:(NSString *)prefix forApiKeyPrefixIdentifier:(NSString *)identifier;
/**
* Removes api key prefix
*
* @param identifier API key identifier.
*/
- (void) removeApiKeyPrefix:(NSString *)identifier;
/**
* Gets API key (with prefix if set)
*/
- (NSString *) getApiKeyWithPrefix:(NSString *) key;
/**
* Gets Basic Auth token
*/
- (NSString *) getBasicAuthToken;
/**
* Gets OAuth access token
*/
- (NSString *) getAccessToken;
/**
* Gets Authentication Settings
*/
- (NSDictionary *) authSettings;
/**
* Default headers for all services
*/
@property (readonly, nonatomic, strong) NSDictionary *defaultHeaders;
/**
* Removes header from defaultHeaders
*
* @param Header name.
*/
-(void) removeDefaultHeaderForKey:(NSString*)key;
/**
* Sets the header for key
*
* @param value Value for header name
* @param key Header name
*/
-(void) setDefaultHeaderValue:(NSString*) value forKey:(NSString*)key;
/**
* @param Header key name.
*/
-(NSString*) defaultHeaderForKey:(NSString*)key;
@end

View File

@@ -1,6 +1,7 @@
#import "SWGConfiguration.h"
#import "SWGDefaultConfiguration.h"
#import "SWGBasicAuthTokenProvider.h"
@interface SWGConfiguration ()
@interface SWGDefaultConfiguration ()
@property (nonatomic, strong) NSMutableDictionary *mutableDefaultHeaders;
@property (nonatomic, strong) NSMutableDictionary *mutableApiKey;
@@ -8,12 +9,12 @@
@end
@implementation SWGConfiguration
@implementation SWGDefaultConfiguration
#pragma mark - Singleton Methods
+ (instancetype) sharedConfig {
static SWGConfiguration *shardConfig = nil;
static SWGDefaultConfiguration *shardConfig = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
shardConfig = [[self alloc] init];
@@ -26,17 +27,16 @@
- (instancetype) init {
self = [super init];
if (self) {
self.apiClient = nil;
self.host = @"http://petstore.swagger.io/v2";
self.username = @"";
self.password = @"";
self.accessToken= @"";
self.verifySSL = YES;
self.mutableApiKey = [NSMutableDictionary dictionary];
self.mutableApiKeyPrefix = [NSMutableDictionary dictionary];
self.mutableDefaultHeaders = [NSMutableDictionary dictionary];
self.mutableDefaultHeaders[@"User-Agent"] = [NSString stringWithFormat:@"Swagger-Codegen/1.0.0/objc (%@; iOS %@; Scale/%0.2f)",[[UIDevice currentDevice] model], [[UIDevice currentDevice] systemVersion], [[UIScreen mainScreen] scale]];
self.logger = [SWGLogger sharedLogger];
_host = @"http://petstore.swagger.io/v2";
_username = @"";
_password = @"";
_accessToken= @"";
_verifySSL = YES;
_mutableApiKey = [NSMutableDictionary dictionary];
_mutableApiKeyPrefix = [NSMutableDictionary dictionary];
_mutableDefaultHeaders = [NSMutableDictionary dictionary];
;
_logger = [SWGLogger sharedLogger];
}
return self;
}
@@ -58,16 +58,9 @@
}
- (NSString *) getBasicAuthToken {
// return empty string if username and password are empty
if (self.username.length == 0 && self.password.length == 0){
return @"";
}
NSString *basicAuthCredentials = [NSString stringWithFormat:@"%@:%@", self.username, self.password];
NSData *data = [basicAuthCredentials dataUsingEncoding:NSUTF8StringEncoding];
basicAuthCredentials = [NSString stringWithFormat:@"Basic %@", [data base64EncodedStringWithOptions:0]];
return basicAuthCredentials;
NSString *basicAuthToken = [SWGBasicAuthTokenProvider createBasicAuthTokenWithUsername:self.username password:self.password];
return basicAuthToken;
}
- (NSString *) getAccessToken {
@@ -110,13 +103,6 @@
- (NSDictionary *) authSettings {
return @{
@"api_key":
@{
@"type": @"api_key",
@"in": @"header",
@"key": @"api_key",
@"value": [self getApiKeyWithPrefix:@"api_key"]
},
@"petstore_auth":
@{
@"type": @"oauth",
@@ -124,6 +110,13 @@
@"key": @"Authorization",
@"value": [self getAccessToken]
},
@"api_key":
@{
@"type": @"api_key",
@"in": @"header",
@"key": @"api_key",
@"value": [self getApiKeyWithPrefix:@"api_key"]
},
};
}

View File

@@ -2,6 +2,35 @@
@implementation SWGObject
/**
* Workaround for JSONModel multithreading issues
* https://github.com/icanzilb/JSONModel/issues/441
*/
- (instancetype)initWithDictionary:(NSDictionary *)dict error:(NSError **)err {
static NSMutableSet *classNames;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
classNames = [NSMutableSet new];
});
BOOL initSync;
@synchronized([self class])
{
NSString *className = NSStringFromClass([self class]);
initSync = ![classNames containsObject:className];
if(initSync)
{
[classNames addObject:className];
self = [super initWithDictionary:dict error:err];
}
}
if(!initSync)
{
self = [super initWithDictionary:dict error:err];
}
return self;
}
/**
* Gets the string presentation of the object.
* This method will be called when logging model object using `NSLog`.

View File

@@ -5,11 +5,15 @@
@synthesize values = _values;
@synthesize format = _format;
- (id) initWithValuesAndFormat: (NSArray*) values
format: (NSString*) format {
_values = values;
_format = format;
- (id)initWithValuesAndFormat:(NSArray *)values
format:(NSString *)format {
self = [super init];
if (self) {
_values = values;
_format = format;
}
return self;
}

View File

@@ -10,7 +10,7 @@
#import <SwaggerClient/SWGApiClient.h>
#import <SwaggerClient/SWGPet.h>
#import <SwaggerClient/SWGPetApi.h>
#import <SwaggerClient/SWGConfiguration.h>
#import <SwaggerClient/SWGDefaultConfiguration.h>
@interface SWGViewController ()
@@ -22,7 +22,7 @@
{
[super viewDidLoad];
SWGConfiguration *config = [SWGConfiguration sharedConfig];
SWGDefaultConfiguration *config = [SWGDefaultConfiguration sharedConfig];
config.debug = YES;
SWGPetApi *api = [[SWGPetApi alloc] init];

View File

@@ -2,6 +2,9 @@
#import <XCTest/XCTest.h>
#import <ISO8601/ISO8601.h>
#import <SwaggerClient/SWGApiClient.h>
#import <SwaggerClient/SWGDefaultConfiguration.h>
#import <SwaggerClient/SWGQueryParamCollection.h>
#import <SwaggerClient/SWGPet.h>
@interface SWGApiClientTest : XCTestCase
@@ -86,7 +89,7 @@
}
- (void)testConfiguration {
SWGConfiguration *config = [SWGConfiguration sharedConfig];
SWGDefaultConfiguration *config = [SWGDefaultConfiguration sharedConfig];
[config setApiKey:@"123456" forApiKeyIdentifier:@"api_key"];
[config setApiKeyPrefix:@"PREFIX" forApiKeyPrefixIdentifier:@"api_key"];
config.username = @"test_username";
@@ -113,7 +116,7 @@
}
- (void)testGetBasicAuthToken {
SWGConfiguration *config = [SWGConfiguration sharedConfig];
SWGDefaultConfiguration *config = [SWGDefaultConfiguration sharedConfig];
config.username = @"test_username";
config.password = @"test_password";

View File

@@ -16,7 +16,7 @@ Method | HTTP request | Description
# **addPet**
```objc
-(NSNumber*) addPetWithBody: (SWGPet*) body
-(NSURLSessionTask*) addPetWithBody: (SWGPet*) body
completionHandler: (void (^)(NSError* error)) handler;
```
@@ -26,7 +26,7 @@ Add a new pet to the store
### Example
```objc
SWGConfiguration *apiConfig = [SWGConfiguration sharedConfig];
SWGDefaultConfiguration *apiConfig = [SWGDefaultConfiguration sharedConfig];
// Configure OAuth2 access token for authorization: (authentication scheme: petstore_auth)
[apiConfig setAccessToken:@"YOUR_ACCESS_TOKEN"];
@@ -68,7 +68,7 @@ void (empty response body)
# **deletePet**
```objc
-(NSNumber*) deletePetWithPetId: (NSNumber*) petId
-(NSURLSessionTask*) deletePetWithPetId: (NSNumber*) petId
apiKey: (NSString*) apiKey
completionHandler: (void (^)(NSError* error)) handler;
```
@@ -79,7 +79,7 @@ Deletes a pet
### Example
```objc
SWGConfiguration *apiConfig = [SWGConfiguration sharedConfig];
SWGDefaultConfiguration *apiConfig = [SWGDefaultConfiguration sharedConfig];
// Configure OAuth2 access token for authorization: (authentication scheme: petstore_auth)
[apiConfig setAccessToken:@"YOUR_ACCESS_TOKEN"];
@@ -124,7 +124,7 @@ void (empty response body)
# **findPetsByStatus**
```objc
-(NSNumber*) findPetsByStatusWithStatus: (NSArray<NSString*>*) status
-(NSURLSessionTask*) findPetsByStatusWithStatus: (NSArray<NSString*>*) status
completionHandler: (void (^)(NSArray<SWGPet>* output, NSError* error)) handler;
```
@@ -134,7 +134,7 @@ Multiple status values can be provided with comma seperated strings
### Example
```objc
SWGConfiguration *apiConfig = [SWGConfiguration sharedConfig];
SWGDefaultConfiguration *apiConfig = [SWGDefaultConfiguration sharedConfig];
// Configure OAuth2 access token for authorization: (authentication scheme: petstore_auth)
[apiConfig setAccessToken:@"YOUR_ACCESS_TOKEN"];
@@ -179,7 +179,7 @@ Name | Type | Description | Notes
# **findPetsByTags**
```objc
-(NSNumber*) findPetsByTagsWithTags: (NSArray<NSString*>*) tags
-(NSURLSessionTask*) findPetsByTagsWithTags: (NSArray<NSString*>*) tags
completionHandler: (void (^)(NSArray<SWGPet>* output, NSError* error)) handler;
```
@@ -189,7 +189,7 @@ Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3
### Example
```objc
SWGConfiguration *apiConfig = [SWGConfiguration sharedConfig];
SWGDefaultConfiguration *apiConfig = [SWGDefaultConfiguration sharedConfig];
// Configure OAuth2 access token for authorization: (authentication scheme: petstore_auth)
[apiConfig setAccessToken:@"YOUR_ACCESS_TOKEN"];
@@ -234,7 +234,7 @@ Name | Type | Description | Notes
# **getPetById**
```objc
-(NSNumber*) getPetByIdWithPetId: (NSNumber*) petId
-(NSURLSessionTask*) getPetByIdWithPetId: (NSNumber*) petId
completionHandler: (void (^)(SWGPet* output, NSError* error)) handler;
```
@@ -244,16 +244,16 @@ Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error cond
### Example
```objc
SWGConfiguration *apiConfig = [SWGConfiguration sharedConfig];
SWGDefaultConfiguration *apiConfig = [SWGDefaultConfiguration sharedConfig];
// Configure OAuth2 access token for authorization: (authentication scheme: petstore_auth)
[apiConfig setAccessToken:@"YOUR_ACCESS_TOKEN"];
// Configure API key authorization: (authentication scheme: api_key)
[apiConfig setApiKey:@"YOUR_API_KEY" forApiKeyIdentifier:@"api_key"];
// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
//[apiConfig setApiKeyPrefix:@"Bearer" forApiKeyIdentifier:@"api_key"];
// Configure OAuth2 access token for authorization: (authentication scheme: petstore_auth)
[apiConfig setAccessToken:@"YOUR_ACCESS_TOKEN"];
NSNumber* petId = @789; // ID of pet that needs to be fetched
@@ -283,7 +283,7 @@ Name | Type | Description | Notes
### Authorization
[api_key](../README.md#api_key), [petstore_auth](../README.md#petstore_auth)
[petstore_auth](../README.md#petstore_auth), [api_key](../README.md#api_key)
### HTTP request headers
@@ -294,7 +294,7 @@ Name | Type | Description | Notes
# **updatePet**
```objc
-(NSNumber*) updatePetWithBody: (SWGPet*) body
-(NSURLSessionTask*) updatePetWithBody: (SWGPet*) body
completionHandler: (void (^)(NSError* error)) handler;
```
@@ -304,7 +304,7 @@ Update an existing pet
### Example
```objc
SWGConfiguration *apiConfig = [SWGConfiguration sharedConfig];
SWGDefaultConfiguration *apiConfig = [SWGDefaultConfiguration sharedConfig];
// Configure OAuth2 access token for authorization: (authentication scheme: petstore_auth)
[apiConfig setAccessToken:@"YOUR_ACCESS_TOKEN"];
@@ -346,7 +346,7 @@ void (empty response body)
# **updatePetWithForm**
```objc
-(NSNumber*) updatePetWithFormWithPetId: (NSString*) petId
-(NSURLSessionTask*) updatePetWithFormWithPetId: (NSString*) petId
name: (NSString*) name
status: (NSString*) status
completionHandler: (void (^)(NSError* error)) handler;
@@ -358,7 +358,7 @@ Updates a pet in the store with form data
### Example
```objc
SWGConfiguration *apiConfig = [SWGConfiguration sharedConfig];
SWGDefaultConfiguration *apiConfig = [SWGDefaultConfiguration sharedConfig];
// Configure OAuth2 access token for authorization: (authentication scheme: petstore_auth)
[apiConfig setAccessToken:@"YOUR_ACCESS_TOKEN"];
@@ -406,7 +406,7 @@ void (empty response body)
# **uploadFile**
```objc
-(NSNumber*) uploadFileWithPetId: (NSNumber*) petId
-(NSURLSessionTask*) uploadFileWithPetId: (NSNumber*) petId
additionalMetadata: (NSString*) additionalMetadata
file: (NSURL*) file
completionHandler: (void (^)(NSError* error)) handler;
@@ -418,7 +418,7 @@ uploads an image
### Example
```objc
SWGConfiguration *apiConfig = [SWGConfiguration sharedConfig];
SWGDefaultConfiguration *apiConfig = [SWGDefaultConfiguration sharedConfig];
// Configure OAuth2 access token for authorization: (authentication scheme: petstore_auth)
[apiConfig setAccessToken:@"YOUR_ACCESS_TOKEN"];

View File

@@ -12,7 +12,7 @@ Method | HTTP request | Description
# **deleteOrder**
```objc
-(NSNumber*) deleteOrderWithOrderId: (NSString*) orderId
-(NSURLSessionTask*) deleteOrderWithOrderId: (NSString*) orderId
completionHandler: (void (^)(NSError* error)) handler;
```
@@ -59,7 +59,7 @@ No authorization required
# **getInventory**
```objc
-(NSNumber*) getInventoryWithCompletionHandler:
-(NSURLSessionTask*) getInventoryWithCompletionHandler:
(void (^)(NSDictionary<NSString*, NSNumber*>* output, NSError* error)) handler;
```
@@ -69,7 +69,7 @@ Returns a map of status codes to quantities
### Example
```objc
SWGConfiguration *apiConfig = [SWGConfiguration sharedConfig];
SWGDefaultConfiguration *apiConfig = [SWGDefaultConfiguration sharedConfig];
// Configure API key authorization: (authentication scheme: api_key)
[apiConfig setApiKey:@"YOUR_API_KEY" forApiKeyIdentifier:@"api_key"];
@@ -112,7 +112,7 @@ This endpoint does not need any parameter.
# **getOrderById**
```objc
-(NSNumber*) getOrderByIdWithOrderId: (NSString*) orderId
-(NSURLSessionTask*) getOrderByIdWithOrderId: (NSString*) orderId
completionHandler: (void (^)(SWGOrder* output, NSError* error)) handler;
```
@@ -162,7 +162,7 @@ No authorization required
# **placeOrder**
```objc
-(NSNumber*) placeOrderWithBody: (SWGOrder*) body
-(NSURLSessionTask*) placeOrderWithBody: (SWGOrder*) body
completionHandler: (void (^)(SWGOrder* output, NSError* error)) handler;
```

View File

@@ -16,7 +16,7 @@ Method | HTTP request | Description
# **createUser**
```objc
-(NSNumber*) createUserWithBody: (SWGUser*) body
-(NSURLSessionTask*) createUserWithBody: (SWGUser*) body
completionHandler: (void (^)(NSError* error)) handler;
```
@@ -63,7 +63,7 @@ No authorization required
# **createUsersWithArrayInput**
```objc
-(NSNumber*) createUsersWithArrayInputWithBody: (NSArray<SWGUser>*) body
-(NSURLSessionTask*) createUsersWithArrayInputWithBody: (NSArray<SWGUser>*) body
completionHandler: (void (^)(NSError* error)) handler;
```
@@ -110,7 +110,7 @@ No authorization required
# **createUsersWithListInput**
```objc
-(NSNumber*) createUsersWithListInputWithBody: (NSArray<SWGUser>*) body
-(NSURLSessionTask*) createUsersWithListInputWithBody: (NSArray<SWGUser>*) body
completionHandler: (void (^)(NSError* error)) handler;
```
@@ -157,7 +157,7 @@ No authorization required
# **deleteUser**
```objc
-(NSNumber*) deleteUserWithUsername: (NSString*) username
-(NSURLSessionTask*) deleteUserWithUsername: (NSString*) username
completionHandler: (void (^)(NSError* error)) handler;
```
@@ -204,7 +204,7 @@ No authorization required
# **getUserByName**
```objc
-(NSNumber*) getUserByNameWithUsername: (NSString*) username
-(NSURLSessionTask*) getUserByNameWithUsername: (NSString*) username
completionHandler: (void (^)(SWGUser* output, NSError* error)) handler;
```
@@ -254,7 +254,7 @@ No authorization required
# **loginUser**
```objc
-(NSNumber*) loginUserWithUsername: (NSString*) username
-(NSURLSessionTask*) loginUserWithUsername: (NSString*) username
password: (NSString*) password
completionHandler: (void (^)(NSString* output, NSError* error)) handler;
```
@@ -308,7 +308,7 @@ No authorization required
# **logoutUser**
```objc
-(NSNumber*) logoutUserWithCompletionHandler:
-(NSURLSessionTask*) logoutUserWithCompletionHandler:
(void (^)(NSError* error)) handler;
```
@@ -351,7 +351,7 @@ No authorization required
# **updateUser**
```objc
-(NSNumber*) updateUserWithUsername: (NSString*) username
-(NSURLSessionTask*) updateUserWithUsername: (NSString*) username
body: (SWGUser*) body
completionHandler: (void (^)(NSError* error)) handler;
```