forked from loafle/openapi-generator-original
[swift5] adds configuration of response success ranges (#13598)
* add successfulCodeRange to configuration * generate samples
This commit is contained in:
parent
085e1e58e5
commit
4beee6c8c4
@ -21,7 +21,11 @@ extension {{projectName}}API {
|
|||||||
// This value is used to configure the date formatter that is used to serialize dates into JSON format.
|
// This value is used to configure the date formatter that is used to serialize dates into JSON format.
|
||||||
// You must set it prior to encoding any dates, and it will only be read once.
|
// You must set it prior to encoding any dates, and it will only be read once.
|
||||||
@available(*, unavailable, message: "To set a different date format, use CodableHelper.dateFormatter instead.")
|
@available(*, unavailable, message: "To set a different date format, use CodableHelper.dateFormatter instead.")
|
||||||
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} static var dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ"{{/useVapor}}{{#useAlamofire}}
|
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} static var dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ"
|
||||||
|
/// Configures the range of HTTP status codes that will result in a successful response
|
||||||
|
///
|
||||||
|
/// If a HTTP status code is outside of this range the response will be interpreted as failed.
|
||||||
|
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} static var successfulStatusCodeRange: Range = 200..<300{{/useVapor}}{{#useAlamofire}}
|
||||||
/// ResponseSerializer that will be used by the generator for `Data` responses
|
/// ResponseSerializer that will be used by the generator for `Data` responses
|
||||||
///
|
///
|
||||||
/// If unchanged, Alamofires default `DataResponseSerializer` will be used.
|
/// If unchanged, Alamofires default `DataResponseSerializer` will be used.
|
||||||
@ -33,7 +37,7 @@ extension {{projectName}}API {
|
|||||||
}
|
}
|
||||||
{{#useAlamofire}}
|
{{#useAlamofire}}
|
||||||
|
|
||||||
/// Type-erased response serializer
|
/// Type-erased ResponseSerializer
|
||||||
///
|
///
|
||||||
/// This is needed in order to use `ResponseSerializer` as a Type in `Configuration`. Obsolete with `any` keyword in Swift >= 5.7
|
/// This is needed in order to use `ResponseSerializer` as a Type in `Configuration`. Obsolete with `any` keyword in Swift >= 5.7
|
||||||
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} struct AnyResponseSerializer<T>: ResponseSerializer {
|
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} struct AnyResponseSerializer<T>: ResponseSerializer {
|
||||||
|
@ -190,7 +190,7 @@ extension KeyedDecodingContainerProtocol {
|
|||||||
|
|
||||||
extension HTTPURLResponse {
|
extension HTTPURLResponse {
|
||||||
var isStatusCodeSuccessful: Bool {
|
var isStatusCodeSuccessful: Bool {
|
||||||
return (200 ..< 300).contains(statusCode)
|
return Configuration.successfulStatusCodeRange.contains(statusCode)
|
||||||
}
|
}
|
||||||
}{{/useVapor}}{{#usePromiseKit}}
|
}{{/useVapor}}{{#usePromiseKit}}
|
||||||
|
|
||||||
|
@ -165,7 +165,7 @@ private var managerStore = SynchronizedDictionary<String, Alamofire.Session>()
|
|||||||
managerStore[managerId] = nil
|
managerStore[managerId] = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
let validatedRequest = request.validate()
|
let validatedRequest = request.validate(statusCode: Configuration.successfulStatusCodeRange)
|
||||||
|
|
||||||
switch T.self {
|
switch T.self {
|
||||||
case is Void.Type:
|
case is Void.Type:
|
||||||
@ -259,7 +259,7 @@ private var managerStore = SynchronizedDictionary<String, Alamofire.Session>()
|
|||||||
managerStore[managerId] = nil
|
managerStore[managerId] = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
let validatedRequest = request.validate()
|
let validatedRequest = request.validate(statusCode: Configuration.successfulStatusCodeRange)
|
||||||
|
|
||||||
switch T.self {
|
switch T.self {
|
||||||
case is String.Type:
|
case is String.Type:
|
||||||
|
@ -165,7 +165,7 @@ open class AlamofireRequestBuilder<T>: RequestBuilder<T> {
|
|||||||
managerStore[managerId] = nil
|
managerStore[managerId] = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
let validatedRequest = request.validate()
|
let validatedRequest = request.validate(statusCode: Configuration.successfulStatusCodeRange)
|
||||||
|
|
||||||
switch T.self {
|
switch T.self {
|
||||||
case is Void.Type:
|
case is Void.Type:
|
||||||
@ -259,7 +259,7 @@ open class AlamofireDecodableRequestBuilder<T: Decodable>: AlamofireRequestBuild
|
|||||||
managerStore[managerId] = nil
|
managerStore[managerId] = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
let validatedRequest = request.validate()
|
let validatedRequest = request.validate(statusCode: Configuration.successfulStatusCodeRange)
|
||||||
|
|
||||||
switch T.self {
|
switch T.self {
|
||||||
case is String.Type:
|
case is String.Type:
|
||||||
|
@ -13,6 +13,10 @@ open class Configuration {
|
|||||||
// You must set it prior to encoding any dates, and it will only be read once.
|
// You must set it prior to encoding any dates, and it will only be read once.
|
||||||
@available(*, unavailable, message: "To set a different date format, use CodableHelper.dateFormatter instead.")
|
@available(*, unavailable, message: "To set a different date format, use CodableHelper.dateFormatter instead.")
|
||||||
public static var dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ"
|
public static var dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ"
|
||||||
|
/// Configures the range of HTTP status codes that will result in a successful response
|
||||||
|
///
|
||||||
|
/// If a HTTP status code is outside of this range the response will be interpreted as failed.
|
||||||
|
public static var successfulStatusCodeRange: Range = 200..<300
|
||||||
/// ResponseSerializer that will be used by the generator for `Data` responses
|
/// ResponseSerializer that will be used by the generator for `Data` responses
|
||||||
///
|
///
|
||||||
/// If unchanged, Alamofires default `DataResponseSerializer` will be used.
|
/// If unchanged, Alamofires default `DataResponseSerializer` will be used.
|
||||||
@ -23,7 +27,7 @@ open class Configuration {
|
|||||||
public static var stringResponseSerializer: AnyResponseSerializer<String> = AnyResponseSerializer(StringResponseSerializer())
|
public static var stringResponseSerializer: AnyResponseSerializer<String> = AnyResponseSerializer(StringResponseSerializer())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Type-erased response serializer
|
/// Type-erased ResponseSerializer
|
||||||
///
|
///
|
||||||
/// This is needed in order to use `ResponseSerializer` as a Type in `Configuration`. Obsolete with `any` keyword in Swift >= 5.7
|
/// This is needed in order to use `ResponseSerializer` as a Type in `Configuration`. Obsolete with `any` keyword in Swift >= 5.7
|
||||||
public struct AnyResponseSerializer<T>: ResponseSerializer {
|
public struct AnyResponseSerializer<T>: ResponseSerializer {
|
||||||
|
@ -188,6 +188,6 @@ extension KeyedDecodingContainerProtocol {
|
|||||||
|
|
||||||
extension HTTPURLResponse {
|
extension HTTPURLResponse {
|
||||||
var isStatusCodeSuccessful: Bool {
|
var isStatusCodeSuccessful: Bool {
|
||||||
return (200 ..< 300).contains(statusCode)
|
return Configuration.successfulStatusCodeRange.contains(statusCode)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,4 +12,8 @@ open class Configuration {
|
|||||||
// You must set it prior to encoding any dates, and it will only be read once.
|
// You must set it prior to encoding any dates, and it will only be read once.
|
||||||
@available(*, unavailable, message: "To set a different date format, use CodableHelper.dateFormatter instead.")
|
@available(*, unavailable, message: "To set a different date format, use CodableHelper.dateFormatter instead.")
|
||||||
public static var dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ"
|
public static var dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ"
|
||||||
|
/// Configures the range of HTTP status codes that will result in a successful response
|
||||||
|
///
|
||||||
|
/// If a HTTP status code is outside of this range the response will be interpreted as failed.
|
||||||
|
public static var successfulStatusCodeRange: Range = 200..<300
|
||||||
}
|
}
|
||||||
|
@ -188,6 +188,6 @@ extension KeyedDecodingContainerProtocol {
|
|||||||
|
|
||||||
extension HTTPURLResponse {
|
extension HTTPURLResponse {
|
||||||
var isStatusCodeSuccessful: Bool {
|
var isStatusCodeSuccessful: Bool {
|
||||||
return (200 ..< 300).contains(statusCode)
|
return Configuration.successfulStatusCodeRange.contains(statusCode)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,4 +12,8 @@ open class Configuration {
|
|||||||
// You must set it prior to encoding any dates, and it will only be read once.
|
// You must set it prior to encoding any dates, and it will only be read once.
|
||||||
@available(*, unavailable, message: "To set a different date format, use CodableHelper.dateFormatter instead.")
|
@available(*, unavailable, message: "To set a different date format, use CodableHelper.dateFormatter instead.")
|
||||||
public static var dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ"
|
public static var dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ"
|
||||||
|
/// Configures the range of HTTP status codes that will result in a successful response
|
||||||
|
///
|
||||||
|
/// If a HTTP status code is outside of this range the response will be interpreted as failed.
|
||||||
|
public static var successfulStatusCodeRange: Range = 200..<300
|
||||||
}
|
}
|
||||||
|
@ -188,6 +188,6 @@ extension KeyedDecodingContainerProtocol {
|
|||||||
|
|
||||||
extension HTTPURLResponse {
|
extension HTTPURLResponse {
|
||||||
var isStatusCodeSuccessful: Bool {
|
var isStatusCodeSuccessful: Bool {
|
||||||
return (200 ..< 300).contains(statusCode)
|
return Configuration.successfulStatusCodeRange.contains(statusCode)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,4 +12,8 @@ open class Configuration {
|
|||||||
// You must set it prior to encoding any dates, and it will only be read once.
|
// You must set it prior to encoding any dates, and it will only be read once.
|
||||||
@available(*, unavailable, message: "To set a different date format, use CodableHelper.dateFormatter instead.")
|
@available(*, unavailable, message: "To set a different date format, use CodableHelper.dateFormatter instead.")
|
||||||
public static var dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ"
|
public static var dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ"
|
||||||
|
/// Configures the range of HTTP status codes that will result in a successful response
|
||||||
|
///
|
||||||
|
/// If a HTTP status code is outside of this range the response will be interpreted as failed.
|
||||||
|
public static var successfulStatusCodeRange: Range = 200..<300
|
||||||
}
|
}
|
||||||
|
@ -188,6 +188,6 @@ extension KeyedDecodingContainerProtocol {
|
|||||||
|
|
||||||
extension HTTPURLResponse {
|
extension HTTPURLResponse {
|
||||||
var isStatusCodeSuccessful: Bool {
|
var isStatusCodeSuccessful: Bool {
|
||||||
return (200 ..< 300).contains(statusCode)
|
return Configuration.successfulStatusCodeRange.contains(statusCode)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,4 +12,8 @@ open class Configuration {
|
|||||||
// You must set it prior to encoding any dates, and it will only be read once.
|
// You must set it prior to encoding any dates, and it will only be read once.
|
||||||
@available(*, unavailable, message: "To set a different date format, use CodableHelper.dateFormatter instead.")
|
@available(*, unavailable, message: "To set a different date format, use CodableHelper.dateFormatter instead.")
|
||||||
public static var dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ"
|
public static var dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ"
|
||||||
|
/// Configures the range of HTTP status codes that will result in a successful response
|
||||||
|
///
|
||||||
|
/// If a HTTP status code is outside of this range the response will be interpreted as failed.
|
||||||
|
public static var successfulStatusCodeRange: Range = 200..<300
|
||||||
}
|
}
|
||||||
|
@ -188,6 +188,6 @@ extension KeyedDecodingContainerProtocol {
|
|||||||
|
|
||||||
extension HTTPURLResponse {
|
extension HTTPURLResponse {
|
||||||
var isStatusCodeSuccessful: Bool {
|
var isStatusCodeSuccessful: Bool {
|
||||||
return (200 ..< 300).contains(statusCode)
|
return Configuration.successfulStatusCodeRange.contains(statusCode)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,4 +12,8 @@ open class Configuration {
|
|||||||
// You must set it prior to encoding any dates, and it will only be read once.
|
// You must set it prior to encoding any dates, and it will only be read once.
|
||||||
@available(*, unavailable, message: "To set a different date format, use CodableHelper.dateFormatter instead.")
|
@available(*, unavailable, message: "To set a different date format, use CodableHelper.dateFormatter instead.")
|
||||||
public static var dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ"
|
public static var dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ"
|
||||||
|
/// Configures the range of HTTP status codes that will result in a successful response
|
||||||
|
///
|
||||||
|
/// If a HTTP status code is outside of this range the response will be interpreted as failed.
|
||||||
|
public static var successfulStatusCodeRange: Range = 200..<300
|
||||||
}
|
}
|
||||||
|
@ -188,6 +188,6 @@ extension KeyedDecodingContainerProtocol {
|
|||||||
|
|
||||||
extension HTTPURLResponse {
|
extension HTTPURLResponse {
|
||||||
var isStatusCodeSuccessful: Bool {
|
var isStatusCodeSuccessful: Bool {
|
||||||
return (200 ..< 300).contains(statusCode)
|
return Configuration.successfulStatusCodeRange.contains(statusCode)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,4 +12,8 @@ internal class Configuration {
|
|||||||
// You must set it prior to encoding any dates, and it will only be read once.
|
// You must set it prior to encoding any dates, and it will only be read once.
|
||||||
@available(*, unavailable, message: "To set a different date format, use CodableHelper.dateFormatter instead.")
|
@available(*, unavailable, message: "To set a different date format, use CodableHelper.dateFormatter instead.")
|
||||||
internal static var dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ"
|
internal static var dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ"
|
||||||
|
/// Configures the range of HTTP status codes that will result in a successful response
|
||||||
|
///
|
||||||
|
/// If a HTTP status code is outside of this range the response will be interpreted as failed.
|
||||||
|
internal static var successfulStatusCodeRange: Range = 200..<300
|
||||||
}
|
}
|
||||||
|
@ -188,6 +188,6 @@ extension KeyedDecodingContainerProtocol {
|
|||||||
|
|
||||||
extension HTTPURLResponse {
|
extension HTTPURLResponse {
|
||||||
var isStatusCodeSuccessful: Bool {
|
var isStatusCodeSuccessful: Bool {
|
||||||
return (200 ..< 300).contains(statusCode)
|
return Configuration.successfulStatusCodeRange.contains(statusCode)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,4 +12,8 @@ open class Configuration {
|
|||||||
// You must set it prior to encoding any dates, and it will only be read once.
|
// You must set it prior to encoding any dates, and it will only be read once.
|
||||||
@available(*, unavailable, message: "To set a different date format, use CodableHelper.dateFormatter instead.")
|
@available(*, unavailable, message: "To set a different date format, use CodableHelper.dateFormatter instead.")
|
||||||
public static var dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ"
|
public static var dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ"
|
||||||
|
/// Configures the range of HTTP status codes that will result in a successful response
|
||||||
|
///
|
||||||
|
/// If a HTTP status code is outside of this range the response will be interpreted as failed.
|
||||||
|
public static var successfulStatusCodeRange: Range = 200..<300
|
||||||
}
|
}
|
||||||
|
@ -188,6 +188,6 @@ extension KeyedDecodingContainerProtocol {
|
|||||||
|
|
||||||
extension HTTPURLResponse {
|
extension HTTPURLResponse {
|
||||||
var isStatusCodeSuccessful: Bool {
|
var isStatusCodeSuccessful: Bool {
|
||||||
return (200 ..< 300).contains(statusCode)
|
return Configuration.successfulStatusCodeRange.contains(statusCode)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,4 +12,8 @@ open class Configuration {
|
|||||||
// You must set it prior to encoding any dates, and it will only be read once.
|
// You must set it prior to encoding any dates, and it will only be read once.
|
||||||
@available(*, unavailable, message: "To set a different date format, use CodableHelper.dateFormatter instead.")
|
@available(*, unavailable, message: "To set a different date format, use CodableHelper.dateFormatter instead.")
|
||||||
public static var dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ"
|
public static var dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ"
|
||||||
|
/// Configures the range of HTTP status codes that will result in a successful response
|
||||||
|
///
|
||||||
|
/// If a HTTP status code is outside of this range the response will be interpreted as failed.
|
||||||
|
public static var successfulStatusCodeRange: Range = 200..<300
|
||||||
}
|
}
|
||||||
|
@ -188,6 +188,6 @@ extension KeyedDecodingContainerProtocol {
|
|||||||
|
|
||||||
extension HTTPURLResponse {
|
extension HTTPURLResponse {
|
||||||
var isStatusCodeSuccessful: Bool {
|
var isStatusCodeSuccessful: Bool {
|
||||||
return (200 ..< 300).contains(statusCode)
|
return Configuration.successfulStatusCodeRange.contains(statusCode)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,4 +12,8 @@ open class Configuration {
|
|||||||
// You must set it prior to encoding any dates, and it will only be read once.
|
// You must set it prior to encoding any dates, and it will only be read once.
|
||||||
@available(*, unavailable, message: "To set a different date format, use CodableHelper.dateFormatter instead.")
|
@available(*, unavailable, message: "To set a different date format, use CodableHelper.dateFormatter instead.")
|
||||||
public static var dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ"
|
public static var dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ"
|
||||||
|
/// Configures the range of HTTP status codes that will result in a successful response
|
||||||
|
///
|
||||||
|
/// If a HTTP status code is outside of this range the response will be interpreted as failed.
|
||||||
|
public static var successfulStatusCodeRange: Range = 200..<300
|
||||||
}
|
}
|
||||||
|
@ -189,7 +189,7 @@ extension KeyedDecodingContainerProtocol {
|
|||||||
|
|
||||||
extension HTTPURLResponse {
|
extension HTTPURLResponse {
|
||||||
var isStatusCodeSuccessful: Bool {
|
var isStatusCodeSuccessful: Bool {
|
||||||
return (200 ..< 300).contains(statusCode)
|
return Configuration.successfulStatusCodeRange.contains(statusCode)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,4 +12,8 @@ open class Configuration {
|
|||||||
// You must set it prior to encoding any dates, and it will only be read once.
|
// You must set it prior to encoding any dates, and it will only be read once.
|
||||||
@available(*, unavailable, message: "To set a different date format, use CodableHelper.dateFormatter instead.")
|
@available(*, unavailable, message: "To set a different date format, use CodableHelper.dateFormatter instead.")
|
||||||
public static var dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ"
|
public static var dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ"
|
||||||
|
/// Configures the range of HTTP status codes that will result in a successful response
|
||||||
|
///
|
||||||
|
/// If a HTTP status code is outside of this range the response will be interpreted as failed.
|
||||||
|
public static var successfulStatusCodeRange: Range = 200..<300
|
||||||
}
|
}
|
||||||
|
@ -188,6 +188,6 @@ extension KeyedDecodingContainerProtocol {
|
|||||||
|
|
||||||
extension HTTPURLResponse {
|
extension HTTPURLResponse {
|
||||||
var isStatusCodeSuccessful: Bool {
|
var isStatusCodeSuccessful: Bool {
|
||||||
return (200 ..< 300).contains(statusCode)
|
return Configuration.successfulStatusCodeRange.contains(statusCode)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,4 +12,8 @@ open class Configuration {
|
|||||||
// You must set it prior to encoding any dates, and it will only be read once.
|
// You must set it prior to encoding any dates, and it will only be read once.
|
||||||
@available(*, unavailable, message: "To set a different date format, use CodableHelper.dateFormatter instead.")
|
@available(*, unavailable, message: "To set a different date format, use CodableHelper.dateFormatter instead.")
|
||||||
public static var dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ"
|
public static var dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ"
|
||||||
|
/// Configures the range of HTTP status codes that will result in a successful response
|
||||||
|
///
|
||||||
|
/// If a HTTP status code is outside of this range the response will be interpreted as failed.
|
||||||
|
public static var successfulStatusCodeRange: Range = 200..<300
|
||||||
}
|
}
|
||||||
|
@ -188,6 +188,6 @@ extension KeyedDecodingContainerProtocol {
|
|||||||
|
|
||||||
extension HTTPURLResponse {
|
extension HTTPURLResponse {
|
||||||
var isStatusCodeSuccessful: Bool {
|
var isStatusCodeSuccessful: Bool {
|
||||||
return (200 ..< 300).contains(statusCode)
|
return Configuration.successfulStatusCodeRange.contains(statusCode)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,4 +12,8 @@ open class Configuration {
|
|||||||
// You must set it prior to encoding any dates, and it will only be read once.
|
// You must set it prior to encoding any dates, and it will only be read once.
|
||||||
@available(*, unavailable, message: "To set a different date format, use CodableHelper.dateFormatter instead.")
|
@available(*, unavailable, message: "To set a different date format, use CodableHelper.dateFormatter instead.")
|
||||||
public static var dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ"
|
public static var dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ"
|
||||||
|
/// Configures the range of HTTP status codes that will result in a successful response
|
||||||
|
///
|
||||||
|
/// If a HTTP status code is outside of this range the response will be interpreted as failed.
|
||||||
|
public static var successfulStatusCodeRange: Range = 200..<300
|
||||||
}
|
}
|
||||||
|
@ -102,6 +102,6 @@ extension JSONEncodable where Self: Encodable {
|
|||||||
|
|
||||||
extension HTTPURLResponse {
|
extension HTTPURLResponse {
|
||||||
var isStatusCodeSuccessful: Bool {
|
var isStatusCodeSuccessful: Bool {
|
||||||
return (200 ..< 300).contains(statusCode)
|
return Configuration.successfulStatusCodeRange.contains(statusCode)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,10 @@ open class Configuration {
|
|||||||
// You must set it prior to encoding any dates, and it will only be read once.
|
// You must set it prior to encoding any dates, and it will only be read once.
|
||||||
@available(*, unavailable, message: "To set a different date format, use CodableHelper.dateFormatter instead.")
|
@available(*, unavailable, message: "To set a different date format, use CodableHelper.dateFormatter instead.")
|
||||||
public static var dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ"
|
public static var dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ"
|
||||||
|
/// Configures the range of HTTP status codes that will result in a successful response
|
||||||
|
///
|
||||||
|
/// If a HTTP status code is outside of this range the response will be interpreted as failed.
|
||||||
|
public static var successfulStatusCodeRange: Range = 200..<300
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -188,6 +188,6 @@ extension KeyedDecodingContainerProtocol {
|
|||||||
|
|
||||||
extension HTTPURLResponse {
|
extension HTTPURLResponse {
|
||||||
var isStatusCodeSuccessful: Bool {
|
var isStatusCodeSuccessful: Bool {
|
||||||
return (200 ..< 300).contains(statusCode)
|
return Configuration.successfulStatusCodeRange.contains(statusCode)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,4 +12,8 @@ open class Configuration {
|
|||||||
// You must set it prior to encoding any dates, and it will only be read once.
|
// You must set it prior to encoding any dates, and it will only be read once.
|
||||||
@available(*, unavailable, message: "To set a different date format, use CodableHelper.dateFormatter instead.")
|
@available(*, unavailable, message: "To set a different date format, use CodableHelper.dateFormatter instead.")
|
||||||
public static var dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ"
|
public static var dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ"
|
||||||
|
/// Configures the range of HTTP status codes that will result in a successful response
|
||||||
|
///
|
||||||
|
/// If a HTTP status code is outside of this range the response will be interpreted as failed.
|
||||||
|
public static var successfulStatusCodeRange: Range = 200..<300
|
||||||
}
|
}
|
||||||
|
@ -188,6 +188,6 @@ extension KeyedDecodingContainerProtocol {
|
|||||||
|
|
||||||
extension HTTPURLResponse {
|
extension HTTPURLResponse {
|
||||||
var isStatusCodeSuccessful: Bool {
|
var isStatusCodeSuccessful: Bool {
|
||||||
return (200 ..< 300).contains(statusCode)
|
return Configuration.successfulStatusCodeRange.contains(statusCode)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user