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) {
|
||||
self.requestSerializer = [AFJSONRequestSerializer serializer];
|
||||
self.responseSerializer = [AFJSONResponseSerializer serializer];
|
||||
self.securityPolicy = [self customSecurityPolicy];
|
||||
// configure reachability
|
||||
[self configureCacheReachibility];
|
||||
}
|
||||
@ -278,7 +279,7 @@ static void (^reachabilityChangeBlock)(int);
|
||||
|
||||
// pure object
|
||||
if ([class isEqualToString:@"NSObject"]) {
|
||||
return [[NSObject alloc] init];
|
||||
return data;
|
||||
}
|
||||
|
||||
// list of models
|
||||
@ -407,7 +408,7 @@ static void (^reachabilityChangeBlock)(int);
|
||||
|
||||
if([[{{classPrefix}}Configuration sharedConfig] debug])
|
||||
[self logResponse:nil forRequest:request error:augmentedError];
|
||||
|
||||
|
||||
NSDictionary *responseHeaders = [[operation response] allHeaderFields];
|
||||
self.HTTPResponseHeaders = responseHeaders;
|
||||
|
||||
@ -740,5 +741,26 @@ static void (^reachabilityChangeBlock)(int);
|
||||
@throw e;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
- (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
|
||||
|
@ -203,4 +203,11 @@ extern NSString *const {{classPrefix}}ResponseObjectErrorKey;
|
||||
*/
|
||||
- (id) sanitizeForSerialization:(id) object;
|
||||
|
||||
/**
|
||||
* Custom security policy
|
||||
*
|
||||
* @return AFSecurityPolicy
|
||||
*/
|
||||
- (AFSecurityPolicy *) customSecurityPolicy;
|
||||
|
||||
@end
|
||||
|
@ -31,6 +31,7 @@
|
||||
self.password = @"";
|
||||
self.tempFolderPath = nil;
|
||||
self.debug = NO;
|
||||
self.verifySSL = YES;
|
||||
self.loggingFile = nil;
|
||||
self.mutableApiKey = [NSMutableDictionary dictionary];
|
||||
self.mutableApiKeyPrefix = [NSMutableDictionary dictionary];
|
||||
|
@ -1,6 +1,6 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "{{classPrefix}}ApiClient.h"
|
||||
|
||||
|
||||
/** The `{{classPrefix}}Configuration` class manages the configurations for the sdk.
|
||||
*
|
||||
* NOTE: This class is auto generated by the swagger code generator program.
|
||||
@ -9,14 +9,14 @@
|
||||
*/
|
||||
|
||||
@class {{classPrefix}}ApiClient;
|
||||
|
||||
|
||||
@interface {{classPrefix}}Configuration : NSObject
|
||||
|
||||
/**
|
||||
* Default api client
|
||||
*/
|
||||
@property (nonatomic) {{classPrefix}}ApiClient *apiClient;
|
||||
|
||||
|
||||
/**
|
||||
* Default base url
|
||||
*/
|
||||
@ -75,6 +75,18 @@
|
||||
*/
|
||||
+ (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
|
||||
*
|
||||
|
@ -20,6 +20,11 @@ Pod::Spec.new do |s|
|
||||
s.requires_arc = true
|
||||
|
||||
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.public_header_files = 'SwaggerClient/**/*.h'
|
||||
|
@ -207,4 +207,11 @@ extern NSString *const SWGResponseObjectErrorKey;
|
||||
*/
|
||||
- (id) sanitizeForSerialization:(id) object;
|
||||
|
||||
/**
|
||||
* Custom security policy
|
||||
*
|
||||
* @return AFSecurityPolicy
|
||||
*/
|
||||
- (AFSecurityPolicy *) customSecurityPolicy;
|
||||
|
||||
@end
|
||||
|
@ -28,6 +28,7 @@ static void (^reachabilityChangeBlock)(int);
|
||||
if (self) {
|
||||
self.requestSerializer = [AFJSONRequestSerializer serializer];
|
||||
self.responseSerializer = [AFJSONResponseSerializer serializer];
|
||||
self.securityPolicy = [self customSecurityPolicy];
|
||||
// configure reachability
|
||||
[self configureCacheReachibility];
|
||||
}
|
||||
@ -278,7 +279,7 @@ static void (^reachabilityChangeBlock)(int);
|
||||
|
||||
// pure object
|
||||
if ([class isEqualToString:@"NSObject"]) {
|
||||
return [[NSObject alloc] init];
|
||||
return data;
|
||||
}
|
||||
|
||||
// list of models
|
||||
@ -407,7 +408,7 @@ static void (^reachabilityChangeBlock)(int);
|
||||
|
||||
if([[SWGConfiguration sharedConfig] debug])
|
||||
[self logResponse:nil forRequest:request error:augmentedError];
|
||||
|
||||
|
||||
NSDictionary *responseHeaders = [[operation response] allHeaderFields];
|
||||
self.HTTPResponseHeaders = responseHeaders;
|
||||
|
||||
@ -740,5 +741,26 @@ static void (^reachabilityChangeBlock)(int);
|
||||
@throw e;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
- (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
|
||||
|
@ -1,6 +1,6 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "SWGApiClient.h"
|
||||
|
||||
|
||||
/** The `SWGConfiguration` class manages the configurations for the sdk.
|
||||
*
|
||||
* NOTE: This class is auto generated by the swagger code generator program.
|
||||
@ -9,14 +9,14 @@
|
||||
*/
|
||||
|
||||
@class SWGApiClient;
|
||||
|
||||
|
||||
@interface SWGConfiguration : NSObject
|
||||
|
||||
/**
|
||||
* Default api client
|
||||
*/
|
||||
@property (nonatomic) SWGApiClient *apiClient;
|
||||
|
||||
|
||||
/**
|
||||
* Default base url
|
||||
*/
|
||||
@ -75,6 +75,18 @@
|
||||
*/
|
||||
+ (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
|
||||
*
|
||||
|
@ -31,6 +31,7 @@
|
||||
self.password = @"";
|
||||
self.tempFolderPath = nil;
|
||||
self.debug = NO;
|
||||
self.verifySSL = YES;
|
||||
self.loggingFile = nil;
|
||||
self.mutableApiKey = [NSMutableDictionary dictionary];
|
||||
self.mutableApiKeyPrefix = [NSMutableDictionary dictionary];
|
||||
|
@ -421,7 +421,11 @@ static SWGPetApi* singletonAPI = nil;
|
||||
|
||||
NSMutableDictionary *pathParams = [[NSMutableDictionary alloc] init];
|
||||
if (petId != nil) {
|
||||
pathParams[@"petId"] = petId;
|
||||
if([petId isKindOfClass:[NSNumber class]]){
|
||||
pathParams[@"petId"] = [((NSNumber *)petId) stringValue];
|
||||
}else{
|
||||
pathParams[@"petId"] = petId;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -513,7 +517,11 @@ static SWGPetApi* singletonAPI = nil;
|
||||
|
||||
NSMutableDictionary *pathParams = [[NSMutableDictionary alloc] init];
|
||||
if (petId != nil) {
|
||||
pathParams[@"petId"] = petId;
|
||||
if([petId isKindOfClass:[NSNumber class]]){
|
||||
pathParams[@"petId"] = [((NSNumber *)petId) stringValue];
|
||||
}else{
|
||||
pathParams[@"petId"] = petId;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -551,13 +559,21 @@ static SWGPetApi* singletonAPI = nil;
|
||||
|
||||
|
||||
if (name) {
|
||||
formParams[@"name"] = name;
|
||||
if([name isKindOfClass:[NSNumber class]]){
|
||||
formParams[@"name"] = [((NSNumber *)name) stringValue];
|
||||
}else{
|
||||
formParams[@"name"] = name;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (status) {
|
||||
formParams[@"status"] = status;
|
||||
if([status isKindOfClass:[NSNumber class]]){
|
||||
formParams[@"status"] = [((NSNumber *)status) stringValue];
|
||||
}else{
|
||||
formParams[@"status"] = status;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -614,7 +630,11 @@ static SWGPetApi* singletonAPI = nil;
|
||||
|
||||
NSMutableDictionary *pathParams = [[NSMutableDictionary alloc] init];
|
||||
if (petId != nil) {
|
||||
pathParams[@"petId"] = petId;
|
||||
if([petId isKindOfClass:[NSNumber class]]){
|
||||
pathParams[@"petId"] = [((NSNumber *)petId) stringValue];
|
||||
}else{
|
||||
pathParams[@"petId"] = petId;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -622,8 +642,13 @@ static SWGPetApi* singletonAPI = nil;
|
||||
|
||||
NSMutableDictionary* headerParams = [NSMutableDictionary dictionaryWithDictionary:self.defaultHeaders];
|
||||
|
||||
if(apiKey != nil)
|
||||
headerParams[@"api_key"] = apiKey;
|
||||
if(apiKey != nil){
|
||||
if([apiKey isKindOfClass:[NSNumber class]]){
|
||||
headerParams[@"api_key"] = [((NSNumber *)apiKey) stringValue];
|
||||
}else{
|
||||
headerParams[@"api_key"] = apiKey;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// HTTP header `Accept`
|
||||
@ -708,7 +733,11 @@ static SWGPetApi* singletonAPI = nil;
|
||||
|
||||
NSMutableDictionary *pathParams = [[NSMutableDictionary alloc] init];
|
||||
if (petId != nil) {
|
||||
pathParams[@"petId"] = petId;
|
||||
if([petId isKindOfClass:[NSNumber class]]){
|
||||
pathParams[@"petId"] = [((NSNumber *)petId) stringValue];
|
||||
}else{
|
||||
pathParams[@"petId"] = petId;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -746,7 +775,11 @@ static SWGPetApi* singletonAPI = nil;
|
||||
|
||||
|
||||
if (additionalMetadata) {
|
||||
formParams[@"additionalMetadata"] = additionalMetadata;
|
||||
if([additionalMetadata isKindOfClass:[NSNumber class]]){
|
||||
formParams[@"additionalMetadata"] = [((NSNumber *)additionalMetadata) stringValue];
|
||||
}else{
|
||||
formParams[@"additionalMetadata"] = additionalMetadata;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -250,7 +250,11 @@ static SWGStoreApi* singletonAPI = nil;
|
||||
|
||||
NSMutableDictionary *pathParams = [[NSMutableDictionary alloc] init];
|
||||
if (orderId != nil) {
|
||||
pathParams[@"orderId"] = orderId;
|
||||
if([orderId isKindOfClass:[NSNumber class]]){
|
||||
pathParams[@"orderId"] = [((NSNumber *)orderId) stringValue];
|
||||
}else{
|
||||
pathParams[@"orderId"] = orderId;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -336,7 +340,11 @@ static SWGStoreApi* singletonAPI = nil;
|
||||
|
||||
NSMutableDictionary *pathParams = [[NSMutableDictionary alloc] init];
|
||||
if (orderId != nil) {
|
||||
pathParams[@"orderId"] = orderId;
|
||||
if([orderId isKindOfClass:[NSNumber class]]){
|
||||
pathParams[@"orderId"] = [((NSNumber *)orderId) stringValue];
|
||||
}else{
|
||||
pathParams[@"orderId"] = orderId;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -495,7 +495,11 @@ static SWGUserApi* singletonAPI = nil;
|
||||
|
||||
NSMutableDictionary *pathParams = [[NSMutableDictionary alloc] init];
|
||||
if (username != nil) {
|
||||
pathParams[@"username"] = username;
|
||||
if([username isKindOfClass:[NSNumber class]]){
|
||||
pathParams[@"username"] = [((NSNumber *)username) stringValue];
|
||||
}else{
|
||||
pathParams[@"username"] = username;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -584,7 +588,11 @@ static SWGUserApi* singletonAPI = nil;
|
||||
|
||||
NSMutableDictionary *pathParams = [[NSMutableDictionary alloc] init];
|
||||
if (username != nil) {
|
||||
pathParams[@"username"] = username;
|
||||
if([username isKindOfClass:[NSNumber class]]){
|
||||
pathParams[@"username"] = [((NSNumber *)username) stringValue];
|
||||
}else{
|
||||
pathParams[@"username"] = username;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -670,7 +678,11 @@ static SWGUserApi* singletonAPI = nil;
|
||||
|
||||
NSMutableDictionary *pathParams = [[NSMutableDictionary alloc] init];
|
||||
if (username != nil) {
|
||||
pathParams[@"username"] = username;
|
||||
if([username isKindOfClass:[NSNumber class]]){
|
||||
pathParams[@"username"] = [((NSNumber *)username) stringValue];
|
||||
}else{
|
||||
pathParams[@"username"] = username;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -21,6 +21,16 @@
|
||||
- (void)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
|
||||
|
@ -45,7 +45,10 @@
|
||||
}
|
||||
|
||||
- (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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user