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
|
||||
@ -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
|
||||
|
@ -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];
|
||||
|
@ -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
|
||||
*
|
||||
|
@ -21,6 +21,11 @@ Pod::Spec.new do |s|
|
||||
|
||||
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
|
||||
@ -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
|
||||
|
@ -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,8 +421,12 @@ static SWGPetApi* singletonAPI = nil;
|
||||
|
||||
NSMutableDictionary *pathParams = [[NSMutableDictionary alloc] init];
|
||||
if (petId != nil) {
|
||||
if([petId isKindOfClass:[NSNumber class]]){
|
||||
pathParams[@"petId"] = [((NSNumber *)petId) stringValue];
|
||||
}else{
|
||||
pathParams[@"petId"] = petId;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
||||
@ -513,8 +517,12 @@ static SWGPetApi* singletonAPI = nil;
|
||||
|
||||
NSMutableDictionary *pathParams = [[NSMutableDictionary alloc] init];
|
||||
if (petId != nil) {
|
||||
if([petId isKindOfClass:[NSNumber class]]){
|
||||
pathParams[@"petId"] = [((NSNumber *)petId) stringValue];
|
||||
}else{
|
||||
pathParams[@"petId"] = petId;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
||||
@ -551,14 +559,22 @@ static SWGPetApi* singletonAPI = nil;
|
||||
|
||||
|
||||
if (name) {
|
||||
if([name isKindOfClass:[NSNumber class]]){
|
||||
formParams[@"name"] = [((NSNumber *)name) stringValue];
|
||||
}else{
|
||||
formParams[@"name"] = name;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (status) {
|
||||
if([status isKindOfClass:[NSNumber class]]){
|
||||
formParams[@"status"] = [((NSNumber *)status) stringValue];
|
||||
}else{
|
||||
formParams[@"status"] = status;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -614,16 +630,25 @@ static SWGPetApi* singletonAPI = nil;
|
||||
|
||||
NSMutableDictionary *pathParams = [[NSMutableDictionary alloc] init];
|
||||
if (petId != nil) {
|
||||
if([petId isKindOfClass:[NSNumber class]]){
|
||||
pathParams[@"petId"] = [((NSNumber *)petId) stringValue];
|
||||
}else{
|
||||
pathParams[@"petId"] = petId;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// HTTP header `Accept`
|
||||
@ -708,8 +733,12 @@ static SWGPetApi* singletonAPI = nil;
|
||||
|
||||
NSMutableDictionary *pathParams = [[NSMutableDictionary alloc] init];
|
||||
if (petId != nil) {
|
||||
if([petId isKindOfClass:[NSNumber class]]){
|
||||
pathParams[@"petId"] = [((NSNumber *)petId) stringValue];
|
||||
}else{
|
||||
pathParams[@"petId"] = petId;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
||||
@ -746,8 +775,12 @@ static SWGPetApi* singletonAPI = nil;
|
||||
|
||||
|
||||
if (additionalMetadata) {
|
||||
if([additionalMetadata isKindOfClass:[NSNumber class]]){
|
||||
formParams[@"additionalMetadata"] = [((NSNumber *)additionalMetadata) stringValue];
|
||||
}else{
|
||||
formParams[@"additionalMetadata"] = additionalMetadata;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -250,8 +250,12 @@ static SWGStoreApi* singletonAPI = nil;
|
||||
|
||||
NSMutableDictionary *pathParams = [[NSMutableDictionary alloc] init];
|
||||
if (orderId != nil) {
|
||||
if([orderId isKindOfClass:[NSNumber class]]){
|
||||
pathParams[@"orderId"] = [((NSNumber *)orderId) stringValue];
|
||||
}else{
|
||||
pathParams[@"orderId"] = orderId;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
||||
@ -336,8 +340,12 @@ static SWGStoreApi* singletonAPI = nil;
|
||||
|
||||
NSMutableDictionary *pathParams = [[NSMutableDictionary alloc] init];
|
||||
if (orderId != nil) {
|
||||
if([orderId isKindOfClass:[NSNumber class]]){
|
||||
pathParams[@"orderId"] = [((NSNumber *)orderId) stringValue];
|
||||
}else{
|
||||
pathParams[@"orderId"] = orderId;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
||||
|
@ -495,8 +495,12 @@ static SWGUserApi* singletonAPI = nil;
|
||||
|
||||
NSMutableDictionary *pathParams = [[NSMutableDictionary alloc] init];
|
||||
if (username != nil) {
|
||||
if([username isKindOfClass:[NSNumber class]]){
|
||||
pathParams[@"username"] = [((NSNumber *)username) stringValue];
|
||||
}else{
|
||||
pathParams[@"username"] = username;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
||||
@ -584,8 +588,12 @@ static SWGUserApi* singletonAPI = nil;
|
||||
|
||||
NSMutableDictionary *pathParams = [[NSMutableDictionary alloc] init];
|
||||
if (username != nil) {
|
||||
if([username isKindOfClass:[NSNumber class]]){
|
||||
pathParams[@"username"] = [((NSNumber *)username) stringValue];
|
||||
}else{
|
||||
pathParams[@"username"] = username;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
||||
@ -670,8 +678,12 @@ static SWGUserApi* singletonAPI = nil;
|
||||
|
||||
NSMutableDictionary *pathParams = [[NSMutableDictionary alloc] init];
|
||||
if (username != nil) {
|
||||
if([username isKindOfClass:[NSNumber class]]){
|
||||
pathParams[@"username"] = [((NSNumber *)username) stringValue];
|
||||
}else{
|
||||
pathParams[@"username"] = username;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
||||
|
@ -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