Skip to content

Commit

Permalink
[objc] Let the developer specify the timezone to be used for date ser…
Browse files Browse the repository at this point in the history
…ialisation (#6628)

* [objc] Update deployment target to 8.0

Updates the test project deployment target to 8.0, as that's the lowest
supported by the latest XCode.

* [objc] Update petstore tests based on current master

Makes sure the tests are based on the latest version of master.

* [objc] Allow specifying the serialization timezone

Now it's possible to specify the timezone used for serializing dates
  • Loading branch information
SirBif authored and wing328 committed Oct 7, 2017
1 parent 567ae3f commit 0db4b32
Show file tree
Hide file tree
Showing 23 changed files with 117 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@
*/
@property (nonatomic) NSString *sslCaCert;

/**
* The time zone to use for date serialization
*/
@property (nonatomic) NSTimeZone *serializationTimeZone;

/**
* Sets API key
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#import <ISO8601/NSDate+ISO8601.h>
#import "JSONValueTransformer+ISO8601.h"
#import "{{classPrefix}}Sanitizer.h"

@implementation JSONValueTransformer (ISO8601)

Expand All @@ -8,4 +9,9 @@
return [NSDate dateWithISO8601String:string];
}

- (NSString *)JSONObjectFromNSDate:(NSDate *)date
{
return [{{classPrefix}}Sanitizer dateToString:date];
}

@end
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#import "{{classPrefix}}Sanitizer.h"
#import "{{classPrefix}}Object.h"
#import "{{classPrefix}}QueryParamCollection.h"
#import "{{classPrefix}}DefaultConfiguration.h"
#import <ISO8601/ISO8601.h>

NSString * const k{{classPrefix}}ApplicationJSONType = @"application/json";
Expand Down Expand Up @@ -63,7 +64,7 @@ NSString * {{classPrefix}}PercentEscapedStringFromString(NSString *string) {
return object;
}
else if ([object isKindOfClass:[NSDate class]]) {
return [self dateParameterToString:object];
return [{{classPrefix}}Sanitizer dateToString:object];
}
else if ([object isKindOfClass:[NSArray class]]) {
NSArray *objectArray = object;
Expand Down Expand Up @@ -107,7 +108,7 @@ NSString * {{classPrefix}}PercentEscapedStringFromString(NSString *string) {
return [param stringValue];
}
else if ([param isKindOfClass:[NSDate class]]) {
return [self dateParameterToString:param];
return [{{classPrefix}}Sanitizer dateToString:param];
}
else if ([param isKindOfClass:[NSArray class]]) {
NSMutableArray *mutableParam = [NSMutableArray array];
Expand All @@ -125,8 +126,9 @@ NSString * {{classPrefix}}PercentEscapedStringFromString(NSString *string) {
}
}

- (NSString *)dateParameterToString:(id)param {
return [param ISO8601String];
+ (NSString *)dateToString:(id)date {
NSTimeZone* timeZone = [{{classPrefix}}DefaultConfiguration sharedConfig].serializationTimeZone;
return [date ISO8601StringWithTimeZone:timeZone usingCalendar:nil];
}

#pragma mark - Utility Methods
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ extern NSString * const k{{classPrefix}}ApplicationJSONType;
*/
- (NSString *) parameterToString: (id) param;

/**
* Convert date to NSString
*/
+ (NSString *)dateToString:(id)date;

/**
* Detects Accept header from accepts NSArray
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2.3.0-SNAPSHOT
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ extern NSInteger kSWGFakeApiMissingParamErrorCode;
///
/// code:400 message:"To test code injection *_/ ' \" =end -- \\r\\n \\n \\r"
///
/// @return
/// @return void
-(NSURLSessionTask*) testCodeInjectEndRnNRWithTestCodeInjectEndRnNR: (NSString*) testCodeInjectEndRnNR
completionHandler: (void (^)(NSError* error)) handler;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#import <ISO8601/NSDate+ISO8601.h>
#import "JSONValueTransformer+ISO8601.h"
#import "SWGSanitizer.h"

@implementation JSONValueTransformer (ISO8601)

Expand All @@ -8,4 +9,9 @@ - (NSDate *) NSDateFromNSString:(NSString *)string
return [NSDate dateWithISO8601String:string];
}

- (NSString *)JSONObjectFromNSDate:(NSDate *)date
{
return [SWGSanitizer dateToString:date];
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,27 @@ extern NSString *const SWGResponseObjectErrorKey;

@property(nonatomic, strong) id<SWGSanitizer> sanitizer;

/**
* 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 status The client reachability status.
*/
+(void) setReachabilityStatus:(AFNetworkReachabilityStatus) status;

/**
* Gets the client reachability
*
* @return The client reachability.
*/
+(AFNetworkReachabilityStatus) getReachabilityStatus;

@property (nonatomic, strong) NSDictionary< NSString *, AFHTTPRequestSerializer <AFURLRequestSerialization> *>* requestSerializerForContentType;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,4 @@ static NSString * const kSWGAPIVersion = @"1.0.0";
*/
@property (readonly, nonatomic, strong) NSDictionary *defaultHeaders;

@end
@end
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@
*/
@property (nonatomic) NSString *sslCaCert;

/**
* The time zone to use for date serialization
*/
@property (nonatomic) NSTimeZone *serializationTimeZone;

/**
* Sets API key
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ extern NSString * const kSWGApplicationJSONType;
*/
- (NSString *) parameterToString: (id) param;

/**
* Convert date to NSString
*/
+ (NSString *)dateToString:(id)date;

/**
* Detects Accept header from accepts NSArray
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#import "SWGSanitizer.h"
#import "SWGObject.h"
#import "SWGQueryParamCollection.h"
#import "SWGDefaultConfiguration.h"
#import <ISO8601/ISO8601.h>

NSString * const kSWGApplicationJSONType = @"application/json";
Expand Down Expand Up @@ -63,7 +64,7 @@ - (id) sanitizeForSerialization:(id) object {
return object;
}
else if ([object isKindOfClass:[NSDate class]]) {
return [self dateParameterToString:object];
return [SWGSanitizer dateToString:object];
}
else if ([object isKindOfClass:[NSArray class]]) {
NSArray *objectArray = object;
Expand Down Expand Up @@ -107,7 +108,7 @@ - (NSString *) parameterToString:(id)param {
return [param stringValue];
}
else if ([param isKindOfClass:[NSDate class]]) {
return [self dateParameterToString:param];
return [SWGSanitizer dateToString:param];
}
else if ([param isKindOfClass:[NSArray class]]) {
NSMutableArray *mutableParam = [NSMutableArray array];
Expand All @@ -125,8 +126,9 @@ - (NSString *) parameterToString:(id)param {
}
}

- (NSString *)dateParameterToString:(id)param {
return [param ISO8601String];
+ (NSString *)dateToString:(id)date {
NSTimeZone* timeZone = [SWGDefaultConfiguration sharedConfig].serializationTimeZone;
return [date ISO8601StringWithTimeZone:timeZone usingCalendar:nil];
}

#pragma mark - Utility Methods
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@




@protocol SWGReturn
@end

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#import <ISO8601/NSDate+ISO8601.h>
#import "JSONValueTransformer+ISO8601.h"
#import "SWGSanitizer.h"

@implementation JSONValueTransformer (ISO8601)

Expand All @@ -8,4 +9,9 @@ - (NSDate *) NSDateFromNSString:(NSString *)string
return [NSDate dateWithISO8601String:string];
}

- (NSString *)JSONObjectFromNSDate:(NSDate *)date
{
return [SWGSanitizer dateToString:date];
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@
*/
@property (nonatomic) NSString *sslCaCert;

/**
* The time zone to use for date serialization
*/
@property (nonatomic) NSTimeZone *serializationTimeZone;

/**
* Sets API key
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ extern NSString * const kSWGApplicationJSONType;
*/
- (NSString *) parameterToString: (id) param;

/**
* Convert date to NSString
*/
+ (NSString *)dateToString:(id)date;

/**
* Detects Accept header from accepts NSArray
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#import "SWGSanitizer.h"
#import "SWGObject.h"
#import "SWGQueryParamCollection.h"
#import "SWGDefaultConfiguration.h"
#import <ISO8601/ISO8601.h>

NSString * const kSWGApplicationJSONType = @"application/json";
Expand Down Expand Up @@ -63,7 +64,7 @@ - (id) sanitizeForSerialization:(id) object {
return object;
}
else if ([object isKindOfClass:[NSDate class]]) {
return [self dateParameterToString:object];
return [SWGSanitizer dateToString:object];
}
else if ([object isKindOfClass:[NSArray class]]) {
NSArray *objectArray = object;
Expand Down Expand Up @@ -107,7 +108,7 @@ - (NSString *) parameterToString:(id)param {
return [param stringValue];
}
else if ([param isKindOfClass:[NSDate class]]) {
return [self dateParameterToString:param];
return [SWGSanitizer dateToString:param];
}
else if ([param isKindOfClass:[NSArray class]]) {
NSMutableArray *mutableParam = [NSMutableArray array];
Expand All @@ -125,8 +126,9 @@ - (NSString *) parameterToString:(id)param {
}
}

- (NSString *)dateParameterToString:(id)param {
return [param ISO8601String];
+ (NSString *)dateToString:(id)date {
NSTimeZone* timeZone = [SWGDefaultConfiguration sharedConfig].serializationTimeZone;
return [date ISO8601StringWithTimeZone:timeZone usingCalendar:nil];
}

#pragma mark - Utility Methods
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#import <ISO8601/NSDate+ISO8601.h>
#import "JSONValueTransformer+ISO8601.h"
#import "SWGSanitizer.h"

@implementation JSONValueTransformer (ISO8601)

Expand All @@ -8,4 +9,9 @@ - (NSDate *) NSDateFromNSString:(NSString *)string
return [NSDate dateWithISO8601String:string];
}

- (NSString *)JSONObjectFromNSDate:(NSDate *)date
{
return [SWGSanitizer dateToString:date];
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@
*/
@property (nonatomic) NSString *sslCaCert;

/**
* The time zone to use for date serialization
*/
@property (nonatomic) NSTimeZone *serializationTimeZone;

/**
* Sets API key
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ extern NSString * const kSWGApplicationJSONType;
*/
- (NSString *) parameterToString: (id) param;

/**
* Convert date to NSString
*/
+ (NSString *)dateToString:(id)date;

/**
* Detects Accept header from accepts NSArray
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#import "SWGSanitizer.h"
#import "SWGObject.h"
#import "SWGQueryParamCollection.h"
#import "SWGDefaultConfiguration.h"
#import <ISO8601/ISO8601.h>

NSString * const kSWGApplicationJSONType = @"application/json";
Expand Down Expand Up @@ -63,7 +64,7 @@ - (id) sanitizeForSerialization:(id) object {
return object;
}
else if ([object isKindOfClass:[NSDate class]]) {
return [self dateParameterToString:object];
return [SWGSanitizer dateToString:object];
}
else if ([object isKindOfClass:[NSArray class]]) {
NSArray *objectArray = object;
Expand Down Expand Up @@ -107,7 +108,7 @@ - (NSString *) parameterToString:(id)param {
return [param stringValue];
}
else if ([param isKindOfClass:[NSDate class]]) {
return [self dateParameterToString:param];
return [SWGSanitizer dateToString:param];
}
else if ([param isKindOfClass:[NSArray class]]) {
NSMutableArray *mutableParam = [NSMutableArray array];
Expand All @@ -125,8 +126,9 @@ - (NSString *) parameterToString:(id)param {
}
}

- (NSString *)dateParameterToString:(id)param {
return [param ISO8601String];
+ (NSString *)dateToString:(id)date {
NSTimeZone* timeZone = [SWGDefaultConfiguration sharedConfig].serializationTimeZone;
return [date ISO8601StringWithTimeZone:timeZone usingCalendar:nil];
}

#pragma mark - Utility Methods
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 7.1;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
TARGETED_DEVICE_FAMILY = "1,2";
Expand Down Expand Up @@ -567,7 +567,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 7.1;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
SDKROOT = iphoneos;
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES;
Expand Down
Loading

0 comments on commit 0db4b32

Please sign in to comment.