forked from loafle/openapi-generator-original
Objc client ssl verification
This commit is contained in:
parent
48bd888483
commit
b0063d9e9f
@ -28,6 +28,7 @@ static void (^reachabilityChangeBlock)(int);
|
|||||||
if (self) {
|
if (self) {
|
||||||
self.requestSerializer = [AFJSONRequestSerializer serializer];
|
self.requestSerializer = [AFJSONRequestSerializer serializer];
|
||||||
self.responseSerializer = [AFJSONResponseSerializer serializer];
|
self.responseSerializer = [AFJSONResponseSerializer serializer];
|
||||||
|
self.securityPolicy = [self customSecurityPolicy];
|
||||||
// configure reachability
|
// configure reachability
|
||||||
[self configureCacheReachibility];
|
[self configureCacheReachibility];
|
||||||
}
|
}
|
||||||
@ -278,7 +279,7 @@ static void (^reachabilityChangeBlock)(int);
|
|||||||
|
|
||||||
// pure object
|
// pure object
|
||||||
if ([class isEqualToString:@"NSObject"]) {
|
if ([class isEqualToString:@"NSObject"]) {
|
||||||
return [[NSObject alloc] init];
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
// list of models
|
// list of models
|
||||||
@ -741,4 +742,25 @@ static void (^reachabilityChangeBlock)(int);
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (AFSecurityPolicy *) customSecurityPolicy {
|
||||||
|
AFSecurityPolicy *securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeNone];
|
||||||
|
|
||||||
|
{{classPrefix}}Configuration *config = [{{classPrefix}}Configuration sharedConfig];
|
||||||
|
|
||||||
|
if (config.sslCaCert) {
|
||||||
|
NSData *certData = [NSData dataWithContentsOfFile:config.sslCaCert];
|
||||||
|
[securityPolicy setPinnedCertificates:@[certData]];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (config.verifySSL) {
|
||||||
|
[securityPolicy setAllowInvalidCertificates:NO];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
[securityPolicy setAllowInvalidCertificates:YES];
|
||||||
|
[securityPolicy setValidatesDomainName:NO];
|
||||||
|
}
|
||||||
|
|
||||||
|
return securityPolicy;
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
@ -203,4 +203,11 @@ extern NSString *const {{classPrefix}}ResponseObjectErrorKey;
|
|||||||
*/
|
*/
|
||||||
- (id) sanitizeForSerialization:(id) object;
|
- (id) sanitizeForSerialization:(id) object;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Custom security policy
|
||||||
|
*
|
||||||
|
* @return AFSecurityPolicy
|
||||||
|
*/
|
||||||
|
- (AFSecurityPolicy *) customSecurityPolicy;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
@ -31,6 +31,7 @@
|
|||||||
self.password = @"";
|
self.password = @"";
|
||||||
self.tempFolderPath = nil;
|
self.tempFolderPath = nil;
|
||||||
self.debug = NO;
|
self.debug = NO;
|
||||||
|
self.verifySSL = YES;
|
||||||
self.loggingFile = nil;
|
self.loggingFile = nil;
|
||||||
self.mutableApiKey = [NSMutableDictionary dictionary];
|
self.mutableApiKey = [NSMutableDictionary dictionary];
|
||||||
self.mutableApiKeyPrefix = [NSMutableDictionary dictionary];
|
self.mutableApiKeyPrefix = [NSMutableDictionary dictionary];
|
||||||
|
@ -75,6 +75,18 @@
|
|||||||
*/
|
*/
|
||||||
+ (instancetype) sharedConfig;
|
+ (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
|
* Sets API key
|
||||||
*
|
*
|
||||||
|
@ -21,6 +21,11 @@ Pod::Spec.new do |s|
|
|||||||
|
|
||||||
s.framework = 'SystemConfiguration'
|
s.framework = 'SystemConfiguration'
|
||||||
|
|
||||||
|
s.homepage = "https://github.com/swagger-api/swagger-codegen"
|
||||||
|
s.license = "MIT"
|
||||||
|
s.source = { :git => "https://github.com/swagger-api/swagger-codegen.git", :tag => "#{s.version}" }
|
||||||
|
s.author = { "Swagger" => "apiteam@swagger.io" }
|
||||||
|
|
||||||
s.source_files = 'SwaggerClient/**/*'
|
s.source_files = 'SwaggerClient/**/*'
|
||||||
s.public_header_files = 'SwaggerClient/**/*.h'
|
s.public_header_files = 'SwaggerClient/**/*.h'
|
||||||
|
|
||||||
|
@ -207,4 +207,11 @@ extern NSString *const SWGResponseObjectErrorKey;
|
|||||||
*/
|
*/
|
||||||
- (id) sanitizeForSerialization:(id) object;
|
- (id) sanitizeForSerialization:(id) object;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Custom security policy
|
||||||
|
*
|
||||||
|
* @return AFSecurityPolicy
|
||||||
|
*/
|
||||||
|
- (AFSecurityPolicy *) customSecurityPolicy;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
@ -28,6 +28,7 @@ static void (^reachabilityChangeBlock)(int);
|
|||||||
if (self) {
|
if (self) {
|
||||||
self.requestSerializer = [AFJSONRequestSerializer serializer];
|
self.requestSerializer = [AFJSONRequestSerializer serializer];
|
||||||
self.responseSerializer = [AFJSONResponseSerializer serializer];
|
self.responseSerializer = [AFJSONResponseSerializer serializer];
|
||||||
|
self.securityPolicy = [self customSecurityPolicy];
|
||||||
// configure reachability
|
// configure reachability
|
||||||
[self configureCacheReachibility];
|
[self configureCacheReachibility];
|
||||||
}
|
}
|
||||||
@ -278,7 +279,7 @@ static void (^reachabilityChangeBlock)(int);
|
|||||||
|
|
||||||
// pure object
|
// pure object
|
||||||
if ([class isEqualToString:@"NSObject"]) {
|
if ([class isEqualToString:@"NSObject"]) {
|
||||||
return [[NSObject alloc] init];
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
// list of models
|
// list of models
|
||||||
@ -741,4 +742,25 @@ static void (^reachabilityChangeBlock)(int);
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (AFSecurityPolicy *) customSecurityPolicy {
|
||||||
|
AFSecurityPolicy *securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeNone];
|
||||||
|
|
||||||
|
SWGConfiguration *config = [SWGConfiguration sharedConfig];
|
||||||
|
|
||||||
|
if (config.sslCaCert) {
|
||||||
|
NSData *certData = [NSData dataWithContentsOfFile:config.sslCaCert];
|
||||||
|
[securityPolicy setPinnedCertificates:@[certData]];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (config.verifySSL) {
|
||||||
|
[securityPolicy setAllowInvalidCertificates:NO];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
[securityPolicy setAllowInvalidCertificates:YES];
|
||||||
|
[securityPolicy setValidatesDomainName:NO];
|
||||||
|
}
|
||||||
|
|
||||||
|
return securityPolicy;
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
@ -75,6 +75,18 @@
|
|||||||
*/
|
*/
|
||||||
+ (instancetype) sharedConfig;
|
+ (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
|
* Sets API key
|
||||||
*
|
*
|
||||||
|
@ -31,6 +31,7 @@
|
|||||||
self.password = @"";
|
self.password = @"";
|
||||||
self.tempFolderPath = nil;
|
self.tempFolderPath = nil;
|
||||||
self.debug = NO;
|
self.debug = NO;
|
||||||
|
self.verifySSL = YES;
|
||||||
self.loggingFile = nil;
|
self.loggingFile = nil;
|
||||||
self.mutableApiKey = [NSMutableDictionary dictionary];
|
self.mutableApiKey = [NSMutableDictionary dictionary];
|
||||||
self.mutableApiKeyPrefix = [NSMutableDictionary dictionary];
|
self.mutableApiKeyPrefix = [NSMutableDictionary dictionary];
|
||||||
|
@ -421,8 +421,12 @@ static SWGPetApi* singletonAPI = nil;
|
|||||||
|
|
||||||
NSMutableDictionary *pathParams = [[NSMutableDictionary alloc] init];
|
NSMutableDictionary *pathParams = [[NSMutableDictionary alloc] init];
|
||||||
if (petId != nil) {
|
if (petId != nil) {
|
||||||
|
if([petId isKindOfClass:[NSNumber class]]){
|
||||||
|
pathParams[@"petId"] = [((NSNumber *)petId) stringValue];
|
||||||
|
}else{
|
||||||
pathParams[@"petId"] = petId;
|
pathParams[@"petId"] = petId;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
||||||
@ -513,8 +517,12 @@ static SWGPetApi* singletonAPI = nil;
|
|||||||
|
|
||||||
NSMutableDictionary *pathParams = [[NSMutableDictionary alloc] init];
|
NSMutableDictionary *pathParams = [[NSMutableDictionary alloc] init];
|
||||||
if (petId != nil) {
|
if (petId != nil) {
|
||||||
|
if([petId isKindOfClass:[NSNumber class]]){
|
||||||
|
pathParams[@"petId"] = [((NSNumber *)petId) stringValue];
|
||||||
|
}else{
|
||||||
pathParams[@"petId"] = petId;
|
pathParams[@"petId"] = petId;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
||||||
@ -551,14 +559,22 @@ static SWGPetApi* singletonAPI = nil;
|
|||||||
|
|
||||||
|
|
||||||
if (name) {
|
if (name) {
|
||||||
|
if([name isKindOfClass:[NSNumber class]]){
|
||||||
|
formParams[@"name"] = [((NSNumber *)name) stringValue];
|
||||||
|
}else{
|
||||||
formParams[@"name"] = name;
|
formParams[@"name"] = name;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (status) {
|
if (status) {
|
||||||
|
if([status isKindOfClass:[NSNumber class]]){
|
||||||
|
formParams[@"status"] = [((NSNumber *)status) stringValue];
|
||||||
|
}else{
|
||||||
formParams[@"status"] = status;
|
formParams[@"status"] = status;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -614,16 +630,25 @@ static SWGPetApi* singletonAPI = nil;
|
|||||||
|
|
||||||
NSMutableDictionary *pathParams = [[NSMutableDictionary alloc] init];
|
NSMutableDictionary *pathParams = [[NSMutableDictionary alloc] init];
|
||||||
if (petId != nil) {
|
if (petId != nil) {
|
||||||
|
if([petId isKindOfClass:[NSNumber class]]){
|
||||||
|
pathParams[@"petId"] = [((NSNumber *)petId) stringValue];
|
||||||
|
}else{
|
||||||
pathParams[@"petId"] = petId;
|
pathParams[@"petId"] = petId;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
||||||
|
|
||||||
NSMutableDictionary* headerParams = [NSMutableDictionary dictionaryWithDictionary:self.defaultHeaders];
|
NSMutableDictionary* headerParams = [NSMutableDictionary dictionaryWithDictionary:self.defaultHeaders];
|
||||||
|
|
||||||
if(apiKey != nil)
|
if(apiKey != nil){
|
||||||
|
if([apiKey isKindOfClass:[NSNumber class]]){
|
||||||
|
headerParams[@"api_key"] = [((NSNumber *)apiKey) stringValue];
|
||||||
|
}else{
|
||||||
headerParams[@"api_key"] = apiKey;
|
headerParams[@"api_key"] = apiKey;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// HTTP header `Accept`
|
// HTTP header `Accept`
|
||||||
@ -708,8 +733,12 @@ static SWGPetApi* singletonAPI = nil;
|
|||||||
|
|
||||||
NSMutableDictionary *pathParams = [[NSMutableDictionary alloc] init];
|
NSMutableDictionary *pathParams = [[NSMutableDictionary alloc] init];
|
||||||
if (petId != nil) {
|
if (petId != nil) {
|
||||||
|
if([petId isKindOfClass:[NSNumber class]]){
|
||||||
|
pathParams[@"petId"] = [((NSNumber *)petId) stringValue];
|
||||||
|
}else{
|
||||||
pathParams[@"petId"] = petId;
|
pathParams[@"petId"] = petId;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
||||||
@ -746,8 +775,12 @@ static SWGPetApi* singletonAPI = nil;
|
|||||||
|
|
||||||
|
|
||||||
if (additionalMetadata) {
|
if (additionalMetadata) {
|
||||||
|
if([additionalMetadata isKindOfClass:[NSNumber class]]){
|
||||||
|
formParams[@"additionalMetadata"] = [((NSNumber *)additionalMetadata) stringValue];
|
||||||
|
}else{
|
||||||
formParams[@"additionalMetadata"] = additionalMetadata;
|
formParams[@"additionalMetadata"] = additionalMetadata;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -250,8 +250,12 @@ static SWGStoreApi* singletonAPI = nil;
|
|||||||
|
|
||||||
NSMutableDictionary *pathParams = [[NSMutableDictionary alloc] init];
|
NSMutableDictionary *pathParams = [[NSMutableDictionary alloc] init];
|
||||||
if (orderId != nil) {
|
if (orderId != nil) {
|
||||||
|
if([orderId isKindOfClass:[NSNumber class]]){
|
||||||
|
pathParams[@"orderId"] = [((NSNumber *)orderId) stringValue];
|
||||||
|
}else{
|
||||||
pathParams[@"orderId"] = orderId;
|
pathParams[@"orderId"] = orderId;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
||||||
@ -336,8 +340,12 @@ static SWGStoreApi* singletonAPI = nil;
|
|||||||
|
|
||||||
NSMutableDictionary *pathParams = [[NSMutableDictionary alloc] init];
|
NSMutableDictionary *pathParams = [[NSMutableDictionary alloc] init];
|
||||||
if (orderId != nil) {
|
if (orderId != nil) {
|
||||||
|
if([orderId isKindOfClass:[NSNumber class]]){
|
||||||
|
pathParams[@"orderId"] = [((NSNumber *)orderId) stringValue];
|
||||||
|
}else{
|
||||||
pathParams[@"orderId"] = orderId;
|
pathParams[@"orderId"] = orderId;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
||||||
|
@ -495,8 +495,12 @@ static SWGUserApi* singletonAPI = nil;
|
|||||||
|
|
||||||
NSMutableDictionary *pathParams = [[NSMutableDictionary alloc] init];
|
NSMutableDictionary *pathParams = [[NSMutableDictionary alloc] init];
|
||||||
if (username != nil) {
|
if (username != nil) {
|
||||||
|
if([username isKindOfClass:[NSNumber class]]){
|
||||||
|
pathParams[@"username"] = [((NSNumber *)username) stringValue];
|
||||||
|
}else{
|
||||||
pathParams[@"username"] = username;
|
pathParams[@"username"] = username;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
||||||
@ -584,8 +588,12 @@ static SWGUserApi* singletonAPI = nil;
|
|||||||
|
|
||||||
NSMutableDictionary *pathParams = [[NSMutableDictionary alloc] init];
|
NSMutableDictionary *pathParams = [[NSMutableDictionary alloc] init];
|
||||||
if (username != nil) {
|
if (username != nil) {
|
||||||
|
if([username isKindOfClass:[NSNumber class]]){
|
||||||
|
pathParams[@"username"] = [((NSNumber *)username) stringValue];
|
||||||
|
}else{
|
||||||
pathParams[@"username"] = username;
|
pathParams[@"username"] = username;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
||||||
@ -670,8 +678,12 @@ static SWGUserApi* singletonAPI = nil;
|
|||||||
|
|
||||||
NSMutableDictionary *pathParams = [[NSMutableDictionary alloc] init];
|
NSMutableDictionary *pathParams = [[NSMutableDictionary alloc] init];
|
||||||
if (username != nil) {
|
if (username != nil) {
|
||||||
|
if([username isKindOfClass:[NSNumber class]]){
|
||||||
|
pathParams[@"username"] = [((NSNumber *)username) stringValue];
|
||||||
|
}else{
|
||||||
pathParams[@"username"] = username;
|
pathParams[@"username"] = username;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
||||||
|
@ -21,6 +21,16 @@
|
|||||||
- (void)viewDidLoad
|
- (void)viewDidLoad
|
||||||
{
|
{
|
||||||
[super viewDidLoad];
|
[super viewDidLoad];
|
||||||
|
|
||||||
|
SWGConfiguration *config = [SWGConfiguration sharedConfig];
|
||||||
|
config.debug = YES;
|
||||||
|
config.verifySSL = NO;
|
||||||
|
|
||||||
|
SWGPetApi *api = [[SWGPetApi alloc] init];
|
||||||
|
SWGPet *pet = [self createPet];
|
||||||
|
[api addPetWithCompletionBlock:pet completionHandler:^(NSError *error) {
|
||||||
|
NSLog(@"*** error: %@", error);
|
||||||
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)didReceiveMemoryWarning
|
- (void)didReceiveMemoryWarning
|
||||||
|
@ -45,7 +45,10 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (void)testDeserializeObject {
|
- (void)testDeserializeObject {
|
||||||
XCTAssertTrue([[apiClient deserialize:@"" class:@"NSObject*"] isKindOfClass:[NSObject class]]);
|
NSNumber *data = @1;
|
||||||
|
NSNumber *result = [apiClient deserialize:data class:@"NSObject*"];
|
||||||
|
|
||||||
|
XCTAssertEqualObjects(data, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)testDeserializeString {
|
- (void)testDeserializeString {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user