replaced SWG by classPrefix and ran tests (#4871)

This commit is contained in:
patulacci
2017-03-03 10:29:16 +01:00
committed by wing328
parent 39a42d014b
commit e23a24c138
38 changed files with 432 additions and 918 deletions

View File

@@ -2,46 +2,35 @@
#import "SWGApi.h"
/**
* Swagger Petstore *_/ ' \" =end \\r\\n \\n \\r
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ *_/ ' \" =end
* Swagger Petstore *_/ ' \" =end -- \\r\\n \\n \\r
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ *_/ ' \" =end --
*
* OpenAPI spec version: 1.0.0 *_/ ' \" =end \\r\\n \\n \\r
* Contact: apiteam@swagger.io *_/ ' \" =end \\r\\n \\n \\r
* OpenAPI spec version: 1.0.0 *_/ ' \" =end -- \\r\\n \\n \\r
* Contact: apiteam@swagger.io *_/ ' \" =end -- \\r\\n \\n \\r
*
* 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 SWGFakeApi: NSObject <SWGApi>
extern NSString* kSWGFakeApiErrorDomain;
extern NSInteger kSWGFakeApiMissingParamErrorCode;
+(instancetype) sharedAPI;
-(instancetype) initWithApiClient:(SWGApiClient *)apiClient NS_DESIGNATED_INITIALIZER;
/// To test code injection *_/ ' \" =end \\r\\n \\n \\r
/// To test code injection *_/ ' \" =end -- \\r\\n \\n \\r
///
///
/// @param testCodeInjectEndRnNR To test code injection *_/ &#39; \&quot; &#x3D;end \\r\\n \\n \\r (optional)
/// @param testCodeInjectEndRnNR To test code injection *_/ &#39; \&quot; &#x3D;end -- \\r\\n \\n \\r (optional)
///
/// code:400 message:"To test code injection *_/ ' \" =end \\r\\n \\n \\r"
/// code:400 message:"To test code injection *_/ ' \" =end -- \\r\\n \\n \\r"
///
/// @return
-(NSNumber*) testCodeInjectEndRnNRWithTestCodeInjectEndRnNR: (NSString*) testCodeInjectEndRnNR
-(NSURLSessionTask*) testCodeInjectEndRnNRWithTestCodeInjectEndRnNR: (NSString*) testCodeInjectEndRnNR
completionHandler: (void (^)(NSError* error)) handler;

View File

@@ -1,10 +1,11 @@
#import "SWGFakeApi.h"
#import "SWGQueryParamCollection.h"
#import "SWGApiClient.h"
@interface SWGFakeApi ()
@property (nonatomic, strong) NSMutableDictionary *defaultHeaders;
@property (nonatomic, strong, readwrite) NSMutableDictionary *mutableDefaultHeaders;
@end
@@ -18,64 +19,43 @@ NSInteger kSWGFakeApiMissingParamErrorCode = 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;
_defaultHeaders = [NSMutableDictionary dictionary];
_mutableDefaultHeaders = [NSMutableDictionary dictionary];
}
return self;
}
#pragma mark -
+ (instancetype)sharedAPI {
static SWGFakeApi *sharedAPI;
static dispatch_once_t once;
dispatch_once(&once, ^{
sharedAPI = [[self alloc] init];
});
return sharedAPI;
}
-(NSString*) defaultHeaderForKey:(NSString*)key {
return self.defaultHeaders[key];
}
-(void) addHeader:(NSString*)value forKey:(NSString*)key {
[self setDefaultHeaderValue:value forKey:key];
return self.mutableDefaultHeaders[key];
}
-(void) setDefaultHeaderValue:(NSString*) value forKey:(NSString*)key {
[self.defaultHeaders setValue:value forKey:key];
[self.mutableDefaultHeaders setValue:value forKey:key];
}
-(NSUInteger) requestQueueSize {
return [SWGApiClient requestQueueSize];
-(NSDictionary *)defaultHeaders {
return self.mutableDefaultHeaders;
}
#pragma mark - Api Methods
///
/// To test code injection *_/ ' \" =end \\r\\n \\n \\r
/// To test code injection *_/ ' \" =end -- \\r\\n \\n \\r
///
/// @param testCodeInjectEndRnNR To test code injection *_/ ' \" =end \\r\\n \\n \\r (optional)
/// @param testCodeInjectEndRnNR To test code injection *_/ ' \" =end -- \\r\\n \\n \\r (optional)
///
/// @returns void
///
-(NSNumber*) testCodeInjectEndRnNRWithTestCodeInjectEndRnNR: (NSString*) testCodeInjectEndRnNR
-(NSURLSessionTask*) testCodeInjectEndRnNRWithTestCodeInjectEndRnNR: (NSString*) testCodeInjectEndRnNR
completionHandler: (void (^)(NSError* error)) handler {
NSMutableString* resourcePath = [NSMutableString stringWithFormat:@"/fake"];
@@ -88,9 +68,7 @@ NSInteger kSWGFakeApiMissingParamErrorCode = 234513;
NSMutableDictionary* headerParams = [NSMutableDictionary dictionaryWithDictionary:self.apiClient.configuration.defaultHeaders];
[headerParams addEntriesFromDictionary:self.defaultHeaders];
// HTTP header `Accept`
NSString *acceptHeader = [self.apiClient.sanitizer selectHeaderAccept:@[@"application/json", @"*/ ' =end
NSString *acceptHeader = [self.apiClient.sanitizer selectHeaderAccept:@[@"application/json", @"*_/ ' =end -- "]];
if(acceptHeader.length > 0) {
headerParams[@"Accept"] = acceptHeader;
}
@@ -99,9 +77,7 @@ NSInteger kSWGFakeApiMissingParamErrorCode = 234513;
NSString *responseContentType = [[acceptHeader componentsSeparatedByString:@", "] firstObject] ?: @"";
// request content type
// request content type
NSString *requestContentType = [self.apiClient.sanitizer selectHeaderContentType:@[@"application/json", @"*/ ' =end
NSString *requestContentType = [self.apiClient.sanitizer selectHeaderContentType:@[@"application/json", @"*_/ ' =end -- "]];
// Authentication setting
NSArray *authSettings = @[];
@@ -110,7 +86,7 @@ NSInteger kSWGFakeApiMissingParamErrorCode = 234513;
NSMutableDictionary *formParams = [[NSMutableDictionary alloc] init];
NSMutableDictionary *localVarFiles = [[NSMutableDictionary alloc] init];
if (testCodeInjectEndRnNR) {
NSMutableDictionary *localVarFiles = [[NSMutableDictionary alloc] init];
formParams[@"test code inject */ &#39; &quot; &#x3D;end -- \r\n \n \r"] = testCodeInjectEndRnNR;
}
return [self.apiClient requestWithPath: resourcePath
@@ -129,8 +105,7 @@ NSInteger kSWGFakeApiMissingParamErrorCode = 234513;
if(handler) {
handler(error);
}
handler(error);
}
}];
}

View File

@@ -1,31 +1,19 @@
#import <Foundation/Foundation.h>
#import <ISO8601/ISO8601.h>
#import <JSONModel/JSONValueTransformer.h>
/**
* Swagger Petstore *_/ ' \" =end \\r\\n \\n \\r
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ *_/ ' \" =end
* Swagger Petstore *_/ ' \" =end -- \\r\\n \\n \\r
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ *_/ ' \" =end --
*
* OpenAPI spec version: 1.0.0 *_/ ' \" =end \\r\\n \\n \\r
* Contact: apiteam@swagger.io *_/ ' \" =end \\r\\n \\n \\r
* OpenAPI spec version: 1.0.0 *_/ ' \" =end -- \\r\\n \\n \\r
* Contact: apiteam@swagger.io *_/ ' \" =end -- \\r\\n \\n \\r
*
* 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 JSONValueTransformer (ISO8601)
@end

View File

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

View File

@@ -1,42 +1,29 @@
#import <Foundation/Foundation.h>
#import "SWGObject.h"
#import "SWGApiClient.h"
@class SWGApiClient;
/**
* Swagger Petstore *_/ ' \" =end \\r\\n \\n \\r
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ *_/ ' \" =end
* Swagger Petstore *_/ ' \" =end -- \\r\\n \\n \\r
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ *_/ ' \" =end --
*
* OpenAPI spec version: 1.0.0 *_/ ' \" =end \\r\\n \\n \\r
* Contact: apiteam@swagger.io *_/ ' \" =end \\r\\n \\n \\r
* OpenAPI spec version: 1.0.0 *_/ ' \" =end -- \\r\\n \\n \\r
* Contact: apiteam@swagger.io *_/ ' \" =end -- \\r\\n \\n \\r
*
* 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.
*/
@protocol SWGApi <NSObject>
@property(nonatomic, assign) SWGApiClient *apiClient;
@property(readonly, nonatomic, strong) SWGApiClient *apiClient;
-(id) initWithApiClient:(SWGApiClient *)apiClient;
-(void) addHeader:(NSString*)value forKey:(NSString*)key DEPRECATED_MSG_ATTRIBUTE("setDefaultHeaderValue:forKey:");
-(instancetype) initWithApiClient:(SWGApiClient *)apiClient;
-(void) setDefaultHeaderValue:(NSString*) value forKey:(NSString*)key;
-(NSString*) defaultHeaderForKey:(NSString*)key;
-(NSUInteger) requestQueueSize;
-(NSDictionary *)defaultHeaders;
@end

View File

@@ -1,43 +1,20 @@
#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 *_/ ' \" =end \\r\\n \\n \\r
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ *_/ ' \" =end
* Swagger Petstore *_/ ' \" =end -- \\r\\n \\n \\r
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ *_/ ' \" =end --
*
* OpenAPI spec version: 1.0.0 *_/ ' \" =end \\r\\n \\n \\r
* Contact: apiteam@swagger.io *_/ ' \" =end \\r\\n \\n \\r
* OpenAPI spec version: 1.0.0 *_/ ' \" =end -- \\r\\n \\n \\r
* Contact: apiteam@swagger.io *_/ ' \" =end -- \\r\\n \\n \\r
*
* 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.
*/
#import "SWGReturn.h"
@class SWGConfiguration;
/**
* A key for `NSError` user info dictionaries.
@@ -46,117 +23,49 @@
*/
extern NSString *const SWGResponseObjectErrorKey;
@interface SWGApiClient : AFHTTPSessionManager
@property(nonatomic, assign) NSURLRequestCachePolicy cachePolicy;
@property(nonatomic, assign) NSTimeInterval timeoutInterval;
@property(nonatomic, readonly) NSOperationQueue* queue;
@property (nonatomic, strong, readonly) id<SWGConfiguration> configuration;
/// 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, assign) NSTimeInterval timeoutInterval;
@property(nonatomic, strong) id<SWGResponseDeserializer> responseDeserializer;
@property(nonatomic, strong) id<SWGSanitizer> sanitizer;
/**
* Clears Cache
*/
+(void)clearCache;
@property (nonatomic, strong) NSDictionary< NSString *, AFHTTPRequestSerializer <AFURLRequestSerialization> *>* requestSerializerForContentType;
/**
* Turns on cache
*
* @param enabled If the cached is enable, must be `YES` or `NO`
* Gets client singleton instance
*/
+(void)setCacheEnabled:(BOOL) enabled;
+ (instancetype) sharedClient;
/**
* Gets the request queue size
*
* @return The size of `queuedRequests` static variable.
*/
+(NSUInteger)requestQueueSize;
/**
* Sets the client unreachable
*
* @param state off line state, must be `YES` or `NO`
*/
+(void) setOfflineState:(BOOL) state;
/**
* Gets if the client is unreachable
*
* @return The client offline state
*/
+(BOOL) getOfflineState;
/**
* Sets the client reachability, this may be overridden by the reachability manager if reachability changes
*
* @param The client reachability.
*/
+(void) setReachabilityStatus:(AFNetworkReachabilityStatus) status;
/**
* Gets the client reachability
*
* @return The client reachability.
*/
+(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
*
* @param changeBlock The block will be executed when the reachability changed.
*/
+(void) setReachabilityChangeBlock:(void(^)(int))changeBlock;
/**
* Sets the api client reachability strategy
*/
- (void)configureCacheReachibility;
/**
* Sets header for request
*
* @param value The header value
* @param forKey The header key
*/
-(void)setHeaderValue:(NSString*) value
forKey:(NSString*) forKey;
/**
* Updates header parameters and query parameters for authentication
*
* @param headers The header parameter will be updated, passed by pointer to pointer.
* @param headers The header parameter will be udpated, passed by pointer to pointer.
* @param querys The query parameters will be updated, passed by pointer to pointer.
* @param authSettings The authentication names NSArray.
*/
- (void) updateHeaderParams:(NSDictionary **)headers
queryParams:(NSDictionary **)querys
WithAuthSettings:(NSArray *)authSettings;
- (void) updateHeaderParams:(NSDictionary **)headers queryParams:(NSDictionary **)querys WithAuthSettings:(NSArray *)authSettings;
/**
* Initializes the session manager with a configuration.
*
* @param configuration The configuration implementation
*/
- (instancetype)initWithConfiguration:(id<SWGConfiguration>)configuration;
/**
* Initializes the session manager with a configuration and url
*
* @param url The base url
* @param configuration The configuration implementation
*/
- (instancetype)initWithBaseURL:(NSURL *)url configuration:(id<SWGConfiguration>)configuration;
/**
* Performs request
@@ -172,35 +81,20 @@ 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;
/**
* Custom security policy
*
* @return AFSecurityPolicy
*/
- (AFSecurityPolicy *) customSecurityPolicy;
/**
* SWGConfiguration return sharedConfig
*
* @return SWGConfiguration
*/
- (SWGConfiguration*) configuration;
- (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;
@end

View File

@@ -1,14 +1,13 @@
#import "SWGLogger.h"
#import "SWGApiClient.h"
#import "SWGJSONRequestSerializer.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);
static NSString * const kSWGContentDispositionKey = @"Content-Disposition";
static NSDictionary * SWG__headerFieldsForResponse(NSURLResponse *response) {
if(![response isKindOfClass:[NSHTTPURLResponse class]]) {
@@ -19,179 +18,80 @@ static NSDictionary * SWG__headerFieldsForResponse(NSURLResponse *response) {
static NSString * SWG__fileNameForResponse(NSURLResponse *response) {
NSDictionary * headers = SWG__headerFieldsForResponse(response);
if(!headers[@"Content-Disposition"]) {
if(!headers[kSWGContentDispositionKey]) {
return [NSString stringWithFormat:@"%@", [[NSProcessInfo processInfo] globallyUniqueString]];
}
NSString *pattern = @"filename=['\"]?([^'\"\\s]+)['\"]?";
NSRegularExpression *regexp = [NSRegularExpression regularExpressionWithPattern:pattern
options:NSRegularExpressionCaseInsensitive
error:nil];
NSString *contentDispositionHeader = headers[@"Content-Disposition"];
NSTextCheckingResult *match = [regexp firstMatchInString:contentDispositionHeader
options:0
range:NSMakeRange(0, [contentDispositionHeader length])];
NSRegularExpression *regexp = [NSRegularExpression regularExpressionWithPattern:pattern options:NSRegularExpressionCaseInsensitive error:nil];
NSString *contentDispositionHeader = headers[kSWGContentDispositionKey];
NSTextCheckingResult *match = [regexp firstMatchInString:contentDispositionHeader options:0 range:NSMakeRange(0, [contentDispositionHeader length])];
return [contentDispositionHeader substringWithRange:[match rangeAtIndex:1]];
}
@interface SWGApiClient ()
@property (nonatomic, strong) NSDictionary* HTTPResponseHeaders;
@property (nonatomic, strong, readwrite) id<SWGConfiguration> configuration;
@property (nonatomic, strong) NSArray<NSString*>* downloadTaskResponseTypes;
@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;
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];
_configuration = configuration;
_timeoutInterval = 60;
_responseDeserializer = [[SWGResponseDeserializer alloc] init];
_sanitizer = [[SWGSanitizer alloc] init];
_downloadTaskResponseTypes = @[@"NSURL*", @"NSURL"];
AFHTTPRequestSerializer* afhttpRequestSerializer = [AFHTTPRequestSerializer serializer];
SWGJSONRequestSerializer * swgjsonRequestSerializer = [SWGJSONRequestSerializer serializer];
_requestSerializerForContentType = @{kSWGApplicationJSONType : swgjsonRequestSerializer,
@"application/x-www-form-urlencoded": afhttpRequestSerializer,
@"multipart/form-data": afhttpRequestSerializer
};
self.securityPolicy = [self createSecurityPolicy];
self.responseSerializer = [AFHTTPResponseSerializer serializer];
}
return self;
}
+ (void)initialize {
if (self == [SWGApiClient class]) {
queuedRequests = [[NSMutableSet alloc] init];
// initialize URL cache
[self configureCacheWithMemoryAndDiskCapacity:4*1024*1024 diskSize:32*1024*1024];
}
}
#pragma mark - Task Methods
#pragma mark - Setter Methods
- (NSURLSessionDataTask*) taskWithCompletionBlock: (NSURLRequest *)request completionBlock: (void (^)(id, NSError *))completionBlock {
+ (void) setOfflineState:(BOOL) state {
offlineState = state;
}
+ (void) setCacheEnabled:(BOOL)enabled {
cacheEnabled = enabled;
}
+(void) setReachabilityStatus:(AFNetworkReachabilityStatus)status {
reachabilityStatus = status;
}
- (void)setHeaderValue:(NSString*) value forKey:(NSString*) forKey {
[self.requestSerializer setValue:value forHTTPHeaderField:forKey];
}
- (void)setRequestSerializer:(AFHTTPRequestSerializer<AFURLRequestSerialization> *)requestSerializer {
[super setRequestSerializer:requestSerializer];
requestSerializer.timeoutInterval = self.timeoutInterval;
}
#pragma mark - Cache Methods
+(void)clearCache {
[[NSURLCache sharedURLCache] removeAllCachedResponses];
}
+(void)configureCacheWithMemoryAndDiskCapacity: (unsigned long) memorySize
diskSize: (unsigned long) diskSize {
NSAssert(memorySize > 0, @"invalid in-memory cache size");
NSAssert(diskSize >= 0, @"invalid disk cache size");
NSURLCache *cache =
[[NSURLCache alloc]
initWithMemoryCapacity:memorySize
diskCapacity:diskSize
diskPath:@"swagger_url_cache"];
[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 {
return reachabilityStatus;
}
+(BOOL) getOfflineState {
return offlineState;
}
+(void) setReachabilityChangeBlock:(void(^)(int))changeBlock {
reachabilityChangeBlock = changeBlock;
}
- (void) configureCacheReachibility {
[self.reachabilityManager setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
reachabilityStatus = status;
SWGDebugLog(@"reachability changed to %@",AFStringFromNetworkReachabilityStatus(status));
[SWGApiClient setOfflineState:status == AFNetworkReachabilityStatusUnknown || status == AFNetworkReachabilityStatusNotReachable];
// call the reachability block, if configured
if (reachabilityChangeBlock != nil) {
reachabilityChangeBlock(status);
}
}];
[self.reachabilityManager startMonitoring];
}
#pragma mark - Operation 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 *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;
@@ -204,20 +104,17 @@ 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 {
__block NSString * tempFolderPath = [self.configuration.tempFolderPath copy];
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) {
@@ -225,9 +122,11 @@ static NSString * SWG__fileNameForResponse(NSURLResponse *response) {
}
NSError *augmentedError = [error initWithDomain:error.domain code:error.code userInfo:userInfo];
completionBlock(nil, augmentedError);
return;
}
NSString *directory = [self configuration].tempFolderPath ?: NSTemporaryDirectory();
NSString * filename = SWG__fileNameForResponse(response);
NSString *directory = tempFolderPath ?: NSTemporaryDirectory();
NSString *filename = SWG__fileNameForResponse(response);
NSString *filepath = [directory stringByAppendingPathComponent:filename];
NSURL *file = [NSURL fileURLWithPath:filepath];
@@ -236,53 +135,37 @@ static NSString * SWG__fileNameForResponse(NSURLResponse *response) {
completionBlock(file, nil);
}];
[op resume];
return task;
}
#pragma mark - Perform Request Methods
#pragma mark - Perform Request Methods
-(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];
}
else if ([requestContentType isEqualToString:@"application/x-www-form-urlencoded"]) {
self.requestSerializer = [AFHTTPRequestSerializer serializer];
}
else if ([requestContentType isEqualToString:@"multipart/form-data"]) {
self.requestSerializer = [AFHTTPRequestSerializer serializer];
}
else {
self.requestSerializer = [AFHTTPRequestSerializer serializer];
NSAssert(NO, @"Unsupported request type %@", requestContentType);
}
- (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 {
// setting response serializer
if ([responseContentType isEqualToString:@"application/json"]) {
self.responseSerializer = [SWGJSONResponseSerializer serializer];
} else {
self.responseSerializer = [AFHTTPResponseSerializer serializer];
}
AFHTTPRequestSerializer <AFURLRequestSerialization> * requestSerializer = [self requestSerializerForRequestContentType:requestContentType];
__weak id<SWGSanitizer> sanitizer = self.sanitizer;
// sanitize parameters
pathParams = [self.sanitizer sanitizeForSerialization:pathParams];
queryParams = [self.sanitizer sanitizeForSerialization:queryParams];
headerParams = [self.sanitizer sanitizeForSerialization:headerParams];
formParams = [self.sanitizer sanitizeForSerialization:formParams];
pathParams = [sanitizer sanitizeForSerialization:pathParams];
queryParams = [sanitizer sanitizeForSerialization:queryParams];
headerParams = [sanitizer sanitizeForSerialization:headerParams];
formParams = [sanitizer sanitizeForSerialization:formParams];
if(![body isKindOfClass:[NSData class]]) {
body = [self.sanitizer sanitizeForSerialization:body];
body = [sanitizer sanitizeForSerialization:body];
}
// auth setting
@@ -295,22 +178,19 @@ static NSString * SWG__fileNameForResponse(NSURLResponse *response) {
[resourcePath replaceCharactersInRange:[resourcePath rangeOfString:[NSString stringWithFormat:@"{%@}", key]] withString:safeString];
}];
NSMutableURLRequest * request = nil;
NSString* pathWithQueryParams = [self pathWithQueryParamsToString:resourcePath queryParams:queryParams];
if ([pathWithQueryParams hasPrefix:@"/"]) {
pathWithQueryParams = [pathWithQueryParams substringFromIndex:1];
}
NSString* urlString = [[NSURL URLWithString:pathWithQueryParams relativeToURL:self.baseURL] absoluteString];
NSError *requestCreateError = nil;
NSMutableURLRequest * request = nil;
if (files.count > 0) {
__weak __typeof(self)weakSelf = self;
request = [self.requestSerializer multipartFormRequestWithMethod:@"POST"
URLString:urlString
parameters:nil
constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
request = [requestSerializer multipartFormRequestWithMethod:@"POST" URLString:urlString parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
[formParams enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
NSString *objString = [weakSelf.sanitizer parameterToString:obj];
NSString *objString = [sanitizer parameterToString:obj];
NSData *data = [objString dataUsingEncoding:NSUTF8StringEncoding];
[formData appendPartWithFormData:data name:key];
}];
@@ -318,76 +198,73 @@ static NSString * SWG__fileNameForResponse(NSURLResponse *response) {
NSURL *filePath = (NSURL *)obj;
[formData appendPartWithFileURL:filePath name:key error:nil];
}];
} error:nil];
} error:&requestCreateError];
}
else {
if (formParams) {
request = [self.requestSerializer requestWithMethod:method
URLString:urlString
parameters:formParams
error:nil];
request = [requestSerializer requestWithMethod:method URLString:urlString parameters:formParams error:&requestCreateError];
}
if (body) {
request = [self.requestSerializer requestWithMethod:method
URLString:urlString
parameters:body
error:nil];
request = [requestSerializer requestWithMethod:method URLString:urlString parameters:body error:&requestCreateError];
}
}
// request cache
BOOL hasHeaderParams = [headerParams count] > 0;
if (offlineState) {
SWGDebugLog(@"%@ cache forced", resourcePath);
[request setCachePolicy:NSURLRequestReturnCacheDataDontLoad];
}
else if(!hasHeaderParams && [method isEqualToString:@"GET"] && cacheEnabled) {
SWGDebugLog(@"%@ cache enabled", resourcePath);
[request setCachePolicy:NSURLRequestUseProtocolCachePolicy];
}
else {
SWGDebugLog(@"%@ cache disabled", resourcePath);
[request setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData];
if(!request) {
completionBlock(nil, requestCreateError);
return nil;
}
if (hasHeaderParams){
if ([headerParams count] > 0){
for(NSString * key in [headerParams keyEnumerator]){
[request setValue:[headerParams valueForKey:key] forHTTPHeaderField:key];
}
}
[self.requestSerializer setValue:responseContentType forHTTPHeaderField:@"Accept"];
[requestSerializer setValue:responseContentType forHTTPHeaderField:@"Accept"];
[self postProcessRequest:request];
NSNumber* requestId = [SWGApiClient queueRequest];
if ([responseType isEqualToString:@"NSURL*"] || [responseType isEqualToString:@"NSURL"]) {
[self downloadOperationWithCompletionBlock:request requestId:requestId completionBlock:^(id data, NSError *error) {
NSURLSessionTask *task = nil;
if ([self.downloadTaskResponseTypes containsObject:responseType]) {
task = [self downloadTaskWithCompletionBlock:request completionBlock:^(id data, NSError *error) {
completionBlock(data, error);
}];
}
else {
[self operationWithCompletionBlock:request requestId:requestId completionBlock:^(id data, NSError *error) {
} else {
__weak typeof(self) weakSelf = self;
task = [self taskWithCompletionBlock:request completionBlock:^(id data, NSError *error) {
NSError * serializationError;
id response = [self.responseDeserializer deserialize:data class:responseType error:&serializationError];
id response = [weakSelf.responseDeserializer deserialize:data class:responseType error:&serializationError];
if(!response && !error){
error = serializationError;
}
completionBlock(response, error);
}];
}
return requestId;
[task resume];
return task;
}
-(AFHTTPRequestSerializer <AFURLRequestSerialization> *)requestSerializerForRequestContentType:(NSString *)requestContentType {
AFHTTPRequestSerializer <AFURLRequestSerialization> * serializer = self.requestSerializerForContentType[requestContentType];
if(!serializer) {
NSAssert(NO, @"Unsupported request content type %@", requestContentType);
serializer = [AFHTTPRequestSerializer serializer];
}
serializer.timeoutInterval = self.timeoutInterval;
return serializer;
}
//Added for easier override to modify request
-(void)postProcessRequest:(NSMutableURLRequest *)request {
// Always disable cookies!
[request setHTTPShouldHandleCookies:NO];
}
#pragma mark -
- (NSString*) pathWithQueryParamsToString:(NSString*) path
queryParams:(NSDictionary*) queryParams {
- (NSString*) pathWithQueryParamsToString:(NSString*) path queryParams:(NSDictionary*) queryParams {
if(queryParams.count == 0) {
return path;
}
@@ -445,9 +322,7 @@ static NSString * SWG__fileNameForResponse(NSURLResponse *response) {
/**
* Update header and query params based on authentication settings
*/
- (void) updateHeaderParams:(NSDictionary *__autoreleasing *)headers
queryParams:(NSDictionary *__autoreleasing *)querys
WithAuthSettings:(NSArray *)authSettings {
- (void) updateHeaderParams:(NSDictionary * *)headers queryParams:(NSDictionary * *)querys WithAuthSettings:(NSArray *)authSettings {
if ([authSettings count] == 0) {
return;
@@ -456,9 +331,10 @@ 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;
}
@@ -476,14 +352,14 @@ static NSString * SWG__fileNameForResponse(NSURLResponse *response) {
*querys = [NSDictionary dictionaryWithDictionary:querysWithAuth];
}
- (AFSecurityPolicy *) customSecurityPolicy {
- (AFSecurityPolicy *) createSecurityPolicy {
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 +373,4 @@ static NSString * SWG__fileNameForResponse(NSURLResponse *response) {
return securityPolicy;
}
- (SWGConfiguration*) configuration {
return [SWGConfiguration sharedConfig];
}
@end

View File

@@ -1,182 +1,89 @@
#import <Foundation/Foundation.h>
#import "SWGApiClient.h"
#import "SWGLogger.h"
@class SWGLogger;
/**
* Swagger Petstore *_/ ' \" =end \\r\\n \\n \\r
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ *_/ ' \" =end
* Swagger Petstore *_/ ' \" =end -- \\r\\n \\n \\r
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ *_/ ' \" =end --
*
* OpenAPI spec version: 1.0.0 *_/ ' \" =end \\r\\n \\n \\r
* Contact: apiteam@swagger.io *_/ ' \" =end \\r\\n \\n \\r
* OpenAPI spec version: 1.0.0 *_/ ' \" =end -- \\r\\n \\n \\r
* Contact: apiteam@swagger.io *_/ ' \" =end -- \\r\\n \\n \\r
*
* 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.
*/
@class SWGApiClient;
@interface SWGConfiguration : NSObject
static NSString * const kSWGAPIVersion = @"1.0.0";
@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

@@ -2,28 +2,17 @@
#import <AFNetworking/AFURLRequestSerialization.h>
/**
* Swagger Petstore *_/ ' \" =end \\r\\n \\n \\r
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ *_/ ' \" =end
* Swagger Petstore *_/ ' \" =end -- \\r\\n \\n \\r
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ *_/ ' \" =end --
*
* OpenAPI spec version: 1.0.0 *_/ ' \" =end \\r\\n \\n \\r
* Contact: apiteam@swagger.io *_/ ' \" =end \\r\\n \\n \\r
* OpenAPI spec version: 1.0.0 *_/ ' \" =end -- \\r\\n \\n \\r
* Contact: apiteam@swagger.io *_/ ' \" =end -- \\r\\n \\n \\r
*
* 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 SWGJSONRequestSerializer : AFJSONRequestSerializer
@end

View File

@@ -1,29 +1,18 @@
#import <Foundation/Foundation.h>
/**
* Swagger Petstore *_/ ' \" =end \\r\\n \\n \\r
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ *_/ ' \" =end
* Swagger Petstore *_/ ' \" =end -- \\r\\n \\n \\r
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ *_/ ' \" =end --
*
* OpenAPI spec version: 1.0.0 *_/ ' \" =end \\r\\n \\n \\r
* Contact: apiteam@swagger.io *_/ ' \" =end \\r\\n \\n \\r
* OpenAPI spec version: 1.0.0 *_/ ' \" =end -- \\r\\n \\n \\r
* Contact: apiteam@swagger.io *_/ ' \" =end -- \\r\\n \\n \\r
*
* 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.
*/
#ifndef SWGDebugLogResponse
#define SWGDebugLogResponse(response, responseObject,request, error) [[SWGLogger sharedLogger] logResponse:response responseObject:responseObject request:request error:error];
#endif

View File

@@ -17,8 +17,7 @@
#pragma mark - Log Methods
- (void)debugLog:(NSString *)method
message:(NSString *)format, ... {
- (void)debugLog:(NSString *)method message:(NSString *)format, ... {
if (!self.isEnabled) {
return;
}

View File

@@ -2,29 +2,18 @@
#import <JSONModel/JSONModel.h>
/**
* Swagger Petstore *_/ ' \" =end \\r\\n \\n \\r
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ *_/ ' \" =end
* Swagger Petstore *_/ ' \" =end -- \\r\\n \\n \\r
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ *_/ ' \" =end --
*
* OpenAPI spec version: 1.0.0 *_/ ' \" =end \\r\\n \\n \\r
* Contact: apiteam@swagger.io *_/ ' \" =end \\r\\n \\n \\r
* OpenAPI spec version: 1.0.0 *_/ ' \" =end -- \\r\\n \\n \\r
* Contact: apiteam@swagger.io *_/ ' \" =end -- \\r\\n \\n \\r
*
* 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 SWGObject : JSONModel
@end

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

@@ -1,29 +1,18 @@
#import <Foundation/Foundation.h>
/**
* Swagger Petstore *_/ ' \" =end \\r\\n \\n \\r
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ *_/ ' \" =end
* Swagger Petstore *_/ ' \" =end -- \\r\\n \\n \\r
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ *_/ ' \" =end --
*
* OpenAPI spec version: 1.0.0 *_/ ' \" =end \\r\\n \\n \\r
* Contact: apiteam@swagger.io *_/ ' \" =end \\r\\n \\n \\r
* OpenAPI spec version: 1.0.0 *_/ ' \" =end -- \\r\\n \\n \\r
* Contact: apiteam@swagger.io *_/ ' \" =end -- \\r\\n \\n \\r
*
* 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 SWGQueryParamCollection : NSObject
@property(nonatomic, readonly) NSArray* values;

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

@@ -1,29 +1,18 @@
#import <Foundation/Foundation.h>
/**
* Swagger Petstore *_/ ' \" =end \\r\\n \\n \\r
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ *_/ ' \" =end
* Swagger Petstore *_/ ' \" =end -- \\r\\n \\n \\r
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ *_/ ' \" =end --
*
* OpenAPI spec version: 1.0.0 *_/ ' \" =end \\r\\n \\n \\r
* Contact: apiteam@swagger.io *_/ ' \" =end \\r\\n \\n \\r
* OpenAPI spec version: 1.0.0 *_/ ' \" =end -- \\r\\n \\n \\r
* Contact: apiteam@swagger.io *_/ ' \" =end -- \\r\\n \\n \\r
*
* 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.
*/
/**
* A key for deserialization ErrorDomain
*/
@@ -50,7 +39,7 @@ extern NSInteger const SWGUnknownResponseObjectErrorCode;
* Deserializes the given data to Objective-C object.
*
* @param data The data will be deserialized.
* @param class The type of objective-c object.
* @param className The type of objective-c object.
* @param error The error
*/
- (id) deserialize:(id) data class:(NSString *) className error:(NSError**)error;

View File

@@ -16,6 +16,7 @@ NSInteger const SWGUnknownResponseObjectErrorCode = 143528;
@property (nonatomic, strong) NSNumberFormatter* numberFormatter;
@property (nonatomic, strong) NSArray *primitiveTypes;
@property (nonatomic, strong) NSArray *basicReturnTypes;
@property (nonatomic, strong) NSArray *dataReturnTypes;
@property (nonatomic, strong) NSRegularExpression* arrayOfModelsPatExpression;
@property (nonatomic, strong) NSRegularExpression* arrayOfPrimitivesPatExpression;
@@ -33,7 +34,9 @@ NSInteger const SWGUnknownResponseObjectErrorCode = 143528;
formatter.numberStyle = NSNumberFormatterDecimalStyle;
_numberFormatter = formatter;
_primitiveTypes = @[@"NSString", @"NSDate", @"NSNumber"];
_basicReturnTypes = @[@"NSObject", @"id", @"NSData"];
_basicReturnTypes = @[@"NSObject", @"id"];
_dataReturnTypes = @[@"NSData"];
_arrayOfModelsPatExpression = [NSRegularExpression regularExpressionWithPattern:@"NSArray<(.+)>"
options:NSRegularExpressionCaseInsensitive
error:nil];
@@ -53,23 +56,36 @@ NSInteger const SWGUnknownResponseObjectErrorCode = 143528;
#pragma mark - Deserialize methods
- (id) deserialize:(id) data class:(NSString *) className error:(NSError **) error {
// return nil if data is nil or className is nil
if (!data || !className || [data isKindOfClass:[NSNull class]]) {
if (!data || !className) {
return nil;
}
// remove "*" from className, if ends with "*"
if ([className hasSuffix:@"*"]) {
className = [className substringToIndex:[className length] - 1];
}
if([self.dataReturnTypes containsObject:className]) {
return data;
}
id jsonData = nil;
if([data isKindOfClass:[NSData class]]) {
jsonData = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:error];
} else {
jsonData = data;
}
if(!jsonData) {
jsonData = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
} else if([jsonData isKindOfClass:[NSNull class]]) {
return nil;
}
// pure object
if ([self.basicReturnTypes containsObject:className]) {
return data;
return jsonData;
}
// primitives
if ([self.primitiveTypes containsObject:className]) {
return [self deserializePrimitiveValue:data class:className error:error];
return [self deserializePrimitiveValue:jsonData class:className error:error];
}
NSTextCheckingResult *match = nil;
@@ -78,37 +94,37 @@ NSInteger const SWGUnknownResponseObjectErrorCode = 143528;
match = [self.arrayOfModelsPatExpression firstMatchInString:className options:0 range:range];
if (match) {
NSString *innerType = [className substringWithRange:[match rangeAtIndex:1]];
return [self deserializeArrayValue:data innerType:innerType error:error];
return [self deserializeArrayValue:jsonData innerType:innerType error:error];
}
// list of primitives
match = [self.arrayOfPrimitivesPatExpression firstMatchInString:className options:0 range:range];
if (match) {
NSString *innerType = [className substringWithRange:[match rangeAtIndex:1]];
return [self deserializeArrayValue:data innerType:innerType error:error];
return [self deserializeArrayValue:jsonData innerType:innerType error:error];
}
// map
match = [self.dictPatExpression firstMatchInString:className options:0 range:range];
if (match) {
NSString *valueType = [className substringWithRange:[match rangeAtIndex:2]];
return [self deserializeDictionaryValue:data valueType:valueType error:error];
return [self deserializeDictionaryValue:jsonData valueType:valueType error:error];
}
match = [self.dictModelsPatExpression firstMatchInString:className options:0 range:range];
if (match) {
NSString *valueType = [className substringWithRange:[match rangeAtIndex:2]];
return [self deserializeDictionaryValue:data valueType:valueType error:error];
return [self deserializeDictionaryValue:jsonData valueType:valueType error:error];
}
// model
Class ModelClass = NSClassFromString(className);
if ([ModelClass instancesRespondToSelector:@selector(initWithDictionary:error:)]) {
return [(JSONModel *) [ModelClass alloc] initWithDictionary:data error:error];
return [(JSONModel *) [ModelClass alloc] initWithDictionary:jsonData error:error];
}
if(error) {
*error = [self unknownResponseErrorWithExpectedType:className data:data];
*error = [self unknownResponseErrorWithExpectedType:className data:jsonData];
}
return nil;
}
@@ -172,7 +188,7 @@ NSInteger const SWGUnknownResponseObjectErrorCode = 143528;
- (id) deserializePrimitiveValue:(id) data class:(NSString *) className error:(NSError**)error {
if ([className isEqualToString:@"NSString"]) {
return [NSString stringWithString:data];
return [NSString stringWithFormat:@"%@",data];
}
else if ([className isEqualToString:@"NSDate"]) {
return [self deserializeDateValue:data error:error];

View File

@@ -1,31 +1,22 @@
#import <Foundation/Foundation.h>
/**
* Swagger Petstore *_/ ' \" =end \\r\\n \\n \\r
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ *_/ ' \" =end
* Swagger Petstore *_/ ' \" =end -- \\r\\n \\n \\r
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ *_/ ' \" =end --
*
* OpenAPI spec version: 1.0.0 *_/ ' \" =end \\r\\n \\n \\r
* Contact: apiteam@swagger.io *_/ ' \" =end \\r\\n \\n \\r
* OpenAPI spec version: 1.0.0 *_/ ' \" =end -- \\r\\n \\n \\r
* Contact: apiteam@swagger.io *_/ ' \" =end -- \\r\\n \\n \\r
*
* 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.
*/
extern NSString * SWGPercentEscapedStringFromString(NSString *string);
extern NSString * const kSWGApplicationJSONType;
@protocol SWGSanitizer <NSObject>
/**

View File

@@ -3,6 +3,8 @@
#import "SWGQueryParamCollection.h"
#import <ISO8601/ISO8601.h>
NSString * const kSWGApplicationJSONType = @"application/json";
NSString * SWGPercentEscapedStringFromString(NSString *string) {
static NSString * const kSWGCharactersGeneralDelimitersToEncode = @":#[]@";
static NSString * const kSWGCharactersSubDelimitersToEncode = @"!$&'()*+,;=";
@@ -43,8 +45,6 @@ NSString * SWGPercentEscapedStringFromString(NSString *string) {
@implementation SWGSanitizer
static NSString * kApplicationJSONType = @"application/json";
-(instancetype)init {
self = [super init];
if ( !self ) {
@@ -141,7 +141,7 @@ static NSString * kApplicationJSONType = @"application/json";
NSMutableArray *lowerAccepts = [[NSMutableArray alloc] initWithCapacity:[accepts count]];
for (NSString *string in accepts) {
if ([self.jsonHeaderTypeExpression matchesInString:string options:0 range:NSMakeRange(0, [string length])].count > 0) {
return kApplicationJSONType;
return kSWGApplicationJSONType;
}
[lowerAccepts addObject:[string lowercaseString]];
}
@@ -153,12 +153,12 @@ static NSString * kApplicationJSONType = @"application/json";
*/
- (NSString *) selectHeaderContentType:(NSArray *)contentTypes {
if (contentTypes.count == 0) {
return kApplicationJSONType;
return kSWGApplicationJSONType;
}
NSMutableArray *lowerContentTypes = [[NSMutableArray alloc] initWithCapacity:[contentTypes count]];
for (NSString *string in contentTypes) {
if([self.jsonHeaderTypeExpression matchesInString:string options:0 range:NSMakeRange(0, [string length])].count > 0){
return kApplicationJSONType;
return kSWGApplicationJSONType;
}
[lowerContentTypes addObject:[string lowercaseString]];
}

View File

@@ -2,37 +2,26 @@
#import "SWGObject.h"
/**
* Swagger Petstore *_/ ' \" =end \\r\\n \\n \\r
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ *_/ ' \" =end
* Swagger Petstore *_/ ' \" =end -- \\r\\n \\n \\r
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ *_/ ' \" =end --
*
* OpenAPI spec version: 1.0.0 *_/ ' \" =end \\r\\n \\n \\r
* Contact: apiteam@swagger.io *_/ ' \" =end \\r\\n \\n \\r
* OpenAPI spec version: 1.0.0 *_/ ' \" =end -- \\r\\n \\n \\r
* Contact: apiteam@swagger.io *_/ ' \" =end -- \\r\\n \\n \\r
*
* 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.
*/
@protocol SWGReturn
@end
@interface SWGReturn : SWGObject
/* property description *_/ ' \" =end \\r\\n \\n \\r [optional]
/* property description *_/ ' \" =end -- \\r\\n \\n \\r [optional]
*/
@property(nonatomic) NSNumber* _return;

View File

@@ -17,7 +17,7 @@
* This method is used by `JSONModel`.
*/
+ (JSONKeyMapper *)keyMapper {
return [[JSONKeyMapper alloc] initWithDictionary:@{ @"return": @"_return" }];
return [[JSONKeyMapper alloc] initWithModelToJSONDictionary:@{ @"_return": @"return" }];
}
/**