[swift5] Refactor encodeToJSON (#10961)

* Add protocol extension method

* execute sample script

* Add Packing.cmake

* Revert "Add Packing.cmake"

This reverts commit cb52547fe34c5d17dd83267daa259b7ee3ddd503.

* Remove empty lines

* Revert FILES

* Add Packing.cmake
This commit is contained in:
Fumito Nakazawa 2021-11-26 01:55:06 +09:00 committed by GitHub
parent 8e303150ae
commit a620853216
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
31 changed files with 219 additions and 585 deletions

View File

@ -11,33 +11,15 @@ import AnyCodable
import PromiseKit{{/usePromiseKit}}{{#useVapor}} import PromiseKit{{/usePromiseKit}}{{#useVapor}}
import Vapor{{/useVapor}}{{^useVapor}} import Vapor{{/useVapor}}{{^useVapor}}
extension Bool: JSONEncodable { extension Bool: JSONEncodable {}
func encodeToJSON() -> Any { return self } extension Float: JSONEncodable {}
} extension Int: JSONEncodable {}
extension Int32: JSONEncodable {}
extension Float: JSONEncodable { extension Int64: JSONEncodable {}
func encodeToJSON() -> Any { return self } extension Double: JSONEncodable {}
} extension String: JSONEncodable {}
extension URL: JSONEncodable {}
extension Int: JSONEncodable { extension UUID: JSONEncodable {}
func encodeToJSON() -> Any { return self }
}
extension Int32: JSONEncodable {
func encodeToJSON() -> Any { return NSNumber(value: self as Int32) }
}
extension Int64: JSONEncodable {
func encodeToJSON() -> Any { return NSNumber(value: self as Int64) }
}
extension Double: JSONEncodable {
func encodeToJSON() -> Any { return self }
}
extension String: JSONEncodable {
func encodeToJSON() -> Any { return self }
}
extension RawRepresentable where RawValue: JSONEncodable { extension RawRepresentable where RawValue: JSONEncodable {
func encodeToJSON() -> Any { return self.rawValue } func encodeToJSON() -> Any { return self.rawValue }
@ -83,18 +65,6 @@ extension Date: JSONEncodable {
func encodeToJSON() -> Any { func encodeToJSON() -> Any {
return CodableHelper.dateFormatter.string(from: self) return CodableHelper.dateFormatter.string(from: self)
} }
}
extension URL: JSONEncodable {
func encodeToJSON() -> Any {
return self
}
}
extension UUID: JSONEncodable {
func encodeToJSON() -> Any {
return self.uuidString
}
}{{/useVapor}}{{#generateModelAdditionalProperties}} }{{/useVapor}}{{#generateModelAdditionalProperties}}
extension String: CodingKey { extension String: CodingKey {

View File

@ -10,6 +10,10 @@ protocol JSONEncodable {
func encodeToJSON() -> Any func encodeToJSON() -> Any
} }
extension JSONEncodable {
func encodeToJSON() -> Any { self }
}
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} enum ErrorResponse: Error { {{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} enum ErrorResponse: Error {
case error(Int, Data?, URLResponse?, Error) case error(Int, Data?, URLResponse?, Error)
} }

View File

@ -0,0 +1,24 @@
set(CPACK_PACKAGE_NAME lib${pkgName})
set(CPACK_PACKAGE_VERSION_MAJOR ${PROJECT_VERSION_MAJOR})
set(CPACK_PACKAGE_VERSION_MINOR ${PROJECT_VERSION_MINOR})
set(CPACK_PACKAGE_VERSION_PATCH ${PROJECT_VERSION_PATCH})
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY ${PROJECT_PACKAGE_DESCRIPTION_SUMMARY})
set(CPACK_PACKAGE_VENDOR ${PROJECT_PACKAGE_VENDOR})
set(CPACK_PACKAGE_CONTACT ${PROJECT_PACKAGE_CONTACT})
set(CPACK_DEBIAN_PACKAGE_MAINTAINER ${PROJECT_PACKAGE_MAINTAINER})
set(CPACK_VERBATIM_VARIABLES YES)
set(CPACK_PACKAGE_INSTALL_DIRECTORY ${CPACK_PACKAGE_NAME})
set(CPACK_PACKAGING_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX})
set(CPACK_DEBIAN_FILE_NAME DEB-DEFAULT)
set(CPACK_DEB_COMPONENT_INSTALL YES)
set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS TRUE)
include(CPack)

View File

@ -9,33 +9,15 @@ import Foundation
import AnyCodable import AnyCodable
#endif #endif
extension Bool: JSONEncodable { extension Bool: JSONEncodable {}
func encodeToJSON() -> Any { return self } extension Float: JSONEncodable {}
} extension Int: JSONEncodable {}
extension Int32: JSONEncodable {}
extension Float: JSONEncodable { extension Int64: JSONEncodable {}
func encodeToJSON() -> Any { return self } extension Double: JSONEncodable {}
} extension String: JSONEncodable {}
extension URL: JSONEncodable {}
extension Int: JSONEncodable { extension UUID: JSONEncodable {}
func encodeToJSON() -> Any { return self }
}
extension Int32: JSONEncodable {
func encodeToJSON() -> Any { return NSNumber(value: self as Int32) }
}
extension Int64: JSONEncodable {
func encodeToJSON() -> Any { return NSNumber(value: self as Int64) }
}
extension Double: JSONEncodable {
func encodeToJSON() -> Any { return self }
}
extension String: JSONEncodable {
func encodeToJSON() -> Any { return self }
}
extension RawRepresentable where RawValue: JSONEncodable { extension RawRepresentable where RawValue: JSONEncodable {
func encodeToJSON() -> Any { return self.rawValue } func encodeToJSON() -> Any { return self.rawValue }
@ -83,18 +65,6 @@ extension Date: JSONEncodable {
} }
} }
extension URL: JSONEncodable {
func encodeToJSON() -> Any {
return self
}
}
extension UUID: JSONEncodable {
func encodeToJSON() -> Any {
return self.uuidString
}
}
extension String: CodingKey { extension String: CodingKey {
public var stringValue: String { public var stringValue: String {

View File

@ -10,6 +10,10 @@ protocol JSONEncodable {
func encodeToJSON() -> Any func encodeToJSON() -> Any
} }
extension JSONEncodable {
func encodeToJSON() -> Any { self }
}
public enum ErrorResponse: Error { public enum ErrorResponse: Error {
case error(Int, Data?, URLResponse?, Error) case error(Int, Data?, URLResponse?, Error)
} }

View File

@ -9,33 +9,15 @@ import Foundation
import AnyCodable import AnyCodable
#endif #endif
extension Bool: JSONEncodable { extension Bool: JSONEncodable {}
func encodeToJSON() -> Any { return self } extension Float: JSONEncodable {}
} extension Int: JSONEncodable {}
extension Int32: JSONEncodable {}
extension Float: JSONEncodable { extension Int64: JSONEncodable {}
func encodeToJSON() -> Any { return self } extension Double: JSONEncodable {}
} extension String: JSONEncodable {}
extension URL: JSONEncodable {}
extension Int: JSONEncodable { extension UUID: JSONEncodable {}
func encodeToJSON() -> Any { return self }
}
extension Int32: JSONEncodable {
func encodeToJSON() -> Any { return NSNumber(value: self as Int32) }
}
extension Int64: JSONEncodable {
func encodeToJSON() -> Any { return NSNumber(value: self as Int64) }
}
extension Double: JSONEncodable {
func encodeToJSON() -> Any { return self }
}
extension String: JSONEncodable {
func encodeToJSON() -> Any { return self }
}
extension RawRepresentable where RawValue: JSONEncodable { extension RawRepresentable where RawValue: JSONEncodable {
func encodeToJSON() -> Any { return self.rawValue } func encodeToJSON() -> Any { return self.rawValue }
@ -83,18 +65,6 @@ extension Date: JSONEncodable {
} }
} }
extension URL: JSONEncodable {
func encodeToJSON() -> Any {
return self
}
}
extension UUID: JSONEncodable {
func encodeToJSON() -> Any {
return self.uuidString
}
}
extension String: CodingKey { extension String: CodingKey {
public var stringValue: String { public var stringValue: String {

View File

@ -10,6 +10,10 @@ protocol JSONEncodable {
func encodeToJSON() -> Any func encodeToJSON() -> Any
} }
extension JSONEncodable {
func encodeToJSON() -> Any { self }
}
public enum ErrorResponse: Error { public enum ErrorResponse: Error {
case error(Int, Data?, URLResponse?, Error) case error(Int, Data?, URLResponse?, Error)
} }

View File

@ -9,33 +9,15 @@ import Foundation
import AnyCodable import AnyCodable
#endif #endif
extension Bool: JSONEncodable { extension Bool: JSONEncodable {}
func encodeToJSON() -> Any { return self } extension Float: JSONEncodable {}
} extension Int: JSONEncodable {}
extension Int32: JSONEncodable {}
extension Float: JSONEncodable { extension Int64: JSONEncodable {}
func encodeToJSON() -> Any { return self } extension Double: JSONEncodable {}
} extension String: JSONEncodable {}
extension URL: JSONEncodable {}
extension Int: JSONEncodable { extension UUID: JSONEncodable {}
func encodeToJSON() -> Any { return self }
}
extension Int32: JSONEncodable {
func encodeToJSON() -> Any { return NSNumber(value: self as Int32) }
}
extension Int64: JSONEncodable {
func encodeToJSON() -> Any { return NSNumber(value: self as Int64) }
}
extension Double: JSONEncodable {
func encodeToJSON() -> Any { return self }
}
extension String: JSONEncodable {
func encodeToJSON() -> Any { return self }
}
extension RawRepresentable where RawValue: JSONEncodable { extension RawRepresentable where RawValue: JSONEncodable {
func encodeToJSON() -> Any { return self.rawValue } func encodeToJSON() -> Any { return self.rawValue }
@ -83,18 +65,6 @@ extension Date: JSONEncodable {
} }
} }
extension URL: JSONEncodable {
func encodeToJSON() -> Any {
return self
}
}
extension UUID: JSONEncodable {
func encodeToJSON() -> Any {
return self.uuidString
}
}
extension String: CodingKey { extension String: CodingKey {
public var stringValue: String { public var stringValue: String {

View File

@ -10,6 +10,10 @@ protocol JSONEncodable {
func encodeToJSON() -> Any func encodeToJSON() -> Any
} }
extension JSONEncodable {
func encodeToJSON() -> Any { self }
}
public enum ErrorResponse: Error { public enum ErrorResponse: Error {
case error(Int, Data?, URLResponse?, Error) case error(Int, Data?, URLResponse?, Error)
} }

View File

@ -9,33 +9,15 @@ import Foundation
import AnyCodable import AnyCodable
#endif #endif
extension Bool: JSONEncodable { extension Bool: JSONEncodable {}
func encodeToJSON() -> Any { return self } extension Float: JSONEncodable {}
} extension Int: JSONEncodable {}
extension Int32: JSONEncodable {}
extension Float: JSONEncodable { extension Int64: JSONEncodable {}
func encodeToJSON() -> Any { return self } extension Double: JSONEncodable {}
} extension String: JSONEncodable {}
extension URL: JSONEncodable {}
extension Int: JSONEncodable { extension UUID: JSONEncodable {}
func encodeToJSON() -> Any { return self }
}
extension Int32: JSONEncodable {
func encodeToJSON() -> Any { return NSNumber(value: self as Int32) }
}
extension Int64: JSONEncodable {
func encodeToJSON() -> Any { return NSNumber(value: self as Int64) }
}
extension Double: JSONEncodable {
func encodeToJSON() -> Any { return self }
}
extension String: JSONEncodable {
func encodeToJSON() -> Any { return self }
}
extension RawRepresentable where RawValue: JSONEncodable { extension RawRepresentable where RawValue: JSONEncodable {
func encodeToJSON() -> Any { return self.rawValue } func encodeToJSON() -> Any { return self.rawValue }
@ -83,18 +65,6 @@ extension Date: JSONEncodable {
} }
} }
extension URL: JSONEncodable {
func encodeToJSON() -> Any {
return self
}
}
extension UUID: JSONEncodable {
func encodeToJSON() -> Any {
return self.uuidString
}
}
extension String: CodingKey { extension String: CodingKey {
public var stringValue: String { public var stringValue: String {

View File

@ -10,6 +10,10 @@ protocol JSONEncodable {
func encodeToJSON() -> Any func encodeToJSON() -> Any
} }
extension JSONEncodable {
func encodeToJSON() -> Any { self }
}
public enum ErrorResponse: Error { public enum ErrorResponse: Error {
case error(Int, Data?, URLResponse?, Error) case error(Int, Data?, URLResponse?, Error)
} }

View File

@ -9,33 +9,15 @@ import Foundation
import AnyCodable import AnyCodable
#endif #endif
extension Bool: JSONEncodable { extension Bool: JSONEncodable {}
func encodeToJSON() -> Any { return self } extension Float: JSONEncodable {}
} extension Int: JSONEncodable {}
extension Int32: JSONEncodable {}
extension Float: JSONEncodable { extension Int64: JSONEncodable {}
func encodeToJSON() -> Any { return self } extension Double: JSONEncodable {}
} extension String: JSONEncodable {}
extension URL: JSONEncodable {}
extension Int: JSONEncodable { extension UUID: JSONEncodable {}
func encodeToJSON() -> Any { return self }
}
extension Int32: JSONEncodable {
func encodeToJSON() -> Any { return NSNumber(value: self as Int32) }
}
extension Int64: JSONEncodable {
func encodeToJSON() -> Any { return NSNumber(value: self as Int64) }
}
extension Double: JSONEncodable {
func encodeToJSON() -> Any { return self }
}
extension String: JSONEncodable {
func encodeToJSON() -> Any { return self }
}
extension RawRepresentable where RawValue: JSONEncodable { extension RawRepresentable where RawValue: JSONEncodable {
func encodeToJSON() -> Any { return self.rawValue } func encodeToJSON() -> Any { return self.rawValue }
@ -83,18 +65,6 @@ extension Date: JSONEncodable {
} }
} }
extension URL: JSONEncodable {
func encodeToJSON() -> Any {
return self
}
}
extension UUID: JSONEncodable {
func encodeToJSON() -> Any {
return self.uuidString
}
}
extension String: CodingKey { extension String: CodingKey {
public var stringValue: String { public var stringValue: String {

View File

@ -10,6 +10,10 @@ protocol JSONEncodable {
func encodeToJSON() -> Any func encodeToJSON() -> Any
} }
extension JSONEncodable {
func encodeToJSON() -> Any { self }
}
public enum ErrorResponse: Error { public enum ErrorResponse: Error {
case error(Int, Data?, URLResponse?, Error) case error(Int, Data?, URLResponse?, Error)
} }

View File

@ -9,33 +9,15 @@ import Foundation
import AnyCodable import AnyCodable
#endif #endif
extension Bool: JSONEncodable { extension Bool: JSONEncodable {}
func encodeToJSON() -> Any { return self } extension Float: JSONEncodable {}
} extension Int: JSONEncodable {}
extension Int32: JSONEncodable {}
extension Float: JSONEncodable { extension Int64: JSONEncodable {}
func encodeToJSON() -> Any { return self } extension Double: JSONEncodable {}
} extension String: JSONEncodable {}
extension URL: JSONEncodable {}
extension Int: JSONEncodable { extension UUID: JSONEncodable {}
func encodeToJSON() -> Any { return self }
}
extension Int32: JSONEncodable {
func encodeToJSON() -> Any { return NSNumber(value: self as Int32) }
}
extension Int64: JSONEncodable {
func encodeToJSON() -> Any { return NSNumber(value: self as Int64) }
}
extension Double: JSONEncodable {
func encodeToJSON() -> Any { return self }
}
extension String: JSONEncodable {
func encodeToJSON() -> Any { return self }
}
extension RawRepresentable where RawValue: JSONEncodable { extension RawRepresentable where RawValue: JSONEncodable {
func encodeToJSON() -> Any { return self.rawValue } func encodeToJSON() -> Any { return self.rawValue }
@ -83,18 +65,6 @@ extension Date: JSONEncodable {
} }
} }
extension URL: JSONEncodable {
func encodeToJSON() -> Any {
return self
}
}
extension UUID: JSONEncodable {
func encodeToJSON() -> Any {
return self.uuidString
}
}
extension String: CodingKey { extension String: CodingKey {
public var stringValue: String { public var stringValue: String {

View File

@ -10,6 +10,10 @@ protocol JSONEncodable {
func encodeToJSON() -> Any func encodeToJSON() -> Any
} }
extension JSONEncodable {
func encodeToJSON() -> Any { self }
}
internal enum ErrorResponse: Error { internal enum ErrorResponse: Error {
case error(Int, Data?, URLResponse?, Error) case error(Int, Data?, URLResponse?, Error)
} }

View File

@ -9,33 +9,15 @@ import Foundation
import AnyCodable import AnyCodable
#endif #endif
extension Bool: JSONEncodable { extension Bool: JSONEncodable {}
func encodeToJSON() -> Any { return self } extension Float: JSONEncodable {}
} extension Int: JSONEncodable {}
extension Int32: JSONEncodable {}
extension Float: JSONEncodable { extension Int64: JSONEncodable {}
func encodeToJSON() -> Any { return self } extension Double: JSONEncodable {}
} extension String: JSONEncodable {}
extension URL: JSONEncodable {}
extension Int: JSONEncodable { extension UUID: JSONEncodable {}
func encodeToJSON() -> Any { return self }
}
extension Int32: JSONEncodable {
func encodeToJSON() -> Any { return NSNumber(value: self as Int32) }
}
extension Int64: JSONEncodable {
func encodeToJSON() -> Any { return NSNumber(value: self as Int64) }
}
extension Double: JSONEncodable {
func encodeToJSON() -> Any { return self }
}
extension String: JSONEncodable {
func encodeToJSON() -> Any { return self }
}
extension RawRepresentable where RawValue: JSONEncodable { extension RawRepresentable where RawValue: JSONEncodable {
func encodeToJSON() -> Any { return self.rawValue } func encodeToJSON() -> Any { return self.rawValue }
@ -83,18 +65,6 @@ extension Date: JSONEncodable {
} }
} }
extension URL: JSONEncodable {
func encodeToJSON() -> Any {
return self
}
}
extension UUID: JSONEncodable {
func encodeToJSON() -> Any {
return self.uuidString
}
}
extension String: CodingKey { extension String: CodingKey {
public var stringValue: String { public var stringValue: String {

View File

@ -10,6 +10,10 @@ protocol JSONEncodable {
func encodeToJSON() -> Any func encodeToJSON() -> Any
} }
extension JSONEncodable {
func encodeToJSON() -> Any { self }
}
public enum ErrorResponse: Error { public enum ErrorResponse: Error {
case error(Int, Data?, URLResponse?, Error) case error(Int, Data?, URLResponse?, Error)
} }

View File

@ -9,33 +9,15 @@ import Foundation
import AnyCodable import AnyCodable
#endif #endif
extension Bool: JSONEncodable { extension Bool: JSONEncodable {}
func encodeToJSON() -> Any { return self } extension Float: JSONEncodable {}
} extension Int: JSONEncodable {}
extension Int32: JSONEncodable {}
extension Float: JSONEncodable { extension Int64: JSONEncodable {}
func encodeToJSON() -> Any { return self } extension Double: JSONEncodable {}
} extension String: JSONEncodable {}
extension URL: JSONEncodable {}
extension Int: JSONEncodable { extension UUID: JSONEncodable {}
func encodeToJSON() -> Any { return self }
}
extension Int32: JSONEncodable {
func encodeToJSON() -> Any { return NSNumber(value: self as Int32) }
}
extension Int64: JSONEncodable {
func encodeToJSON() -> Any { return NSNumber(value: self as Int64) }
}
extension Double: JSONEncodable {
func encodeToJSON() -> Any { return self }
}
extension String: JSONEncodable {
func encodeToJSON() -> Any { return self }
}
extension RawRepresentable where RawValue: JSONEncodable { extension RawRepresentable where RawValue: JSONEncodable {
func encodeToJSON() -> Any { return self.rawValue } func encodeToJSON() -> Any { return self.rawValue }
@ -83,18 +65,6 @@ extension Date: JSONEncodable {
} }
} }
extension URL: JSONEncodable {
func encodeToJSON() -> Any {
return self
}
}
extension UUID: JSONEncodable {
func encodeToJSON() -> Any {
return self.uuidString
}
}
extension String: CodingKey { extension String: CodingKey {
public var stringValue: String { public var stringValue: String {

View File

@ -10,6 +10,10 @@ protocol JSONEncodable {
func encodeToJSON() -> Any func encodeToJSON() -> Any
} }
extension JSONEncodable {
func encodeToJSON() -> Any { self }
}
public enum ErrorResponse: Error { public enum ErrorResponse: Error {
case error(Int, Data?, URLResponse?, Error) case error(Int, Data?, URLResponse?, Error)
} }

View File

@ -10,33 +10,15 @@ import AnyCodable
#endif #endif
import PromiseKit import PromiseKit
extension Bool: JSONEncodable { extension Bool: JSONEncodable {}
func encodeToJSON() -> Any { return self } extension Float: JSONEncodable {}
} extension Int: JSONEncodable {}
extension Int32: JSONEncodable {}
extension Float: JSONEncodable { extension Int64: JSONEncodable {}
func encodeToJSON() -> Any { return self } extension Double: JSONEncodable {}
} extension String: JSONEncodable {}
extension URL: JSONEncodable {}
extension Int: JSONEncodable { extension UUID: JSONEncodable {}
func encodeToJSON() -> Any { return self }
}
extension Int32: JSONEncodable {
func encodeToJSON() -> Any { return NSNumber(value: self as Int32) }
}
extension Int64: JSONEncodable {
func encodeToJSON() -> Any { return NSNumber(value: self as Int64) }
}
extension Double: JSONEncodable {
func encodeToJSON() -> Any { return self }
}
extension String: JSONEncodable {
func encodeToJSON() -> Any { return self }
}
extension RawRepresentable where RawValue: JSONEncodable { extension RawRepresentable where RawValue: JSONEncodable {
func encodeToJSON() -> Any { return self.rawValue } func encodeToJSON() -> Any { return self.rawValue }
@ -84,18 +66,6 @@ extension Date: JSONEncodable {
} }
} }
extension URL: JSONEncodable {
func encodeToJSON() -> Any {
return self
}
}
extension UUID: JSONEncodable {
func encodeToJSON() -> Any {
return self.uuidString
}
}
extension String: CodingKey { extension String: CodingKey {
public var stringValue: String { public var stringValue: String {

View File

@ -10,6 +10,10 @@ protocol JSONEncodable {
func encodeToJSON() -> Any func encodeToJSON() -> Any
} }
extension JSONEncodable {
func encodeToJSON() -> Any { self }
}
public enum ErrorResponse: Error { public enum ErrorResponse: Error {
case error(Int, Data?, URLResponse?, Error) case error(Int, Data?, URLResponse?, Error)
} }

View File

@ -9,33 +9,15 @@ import Foundation
import AnyCodable import AnyCodable
#endif #endif
extension Bool: JSONEncodable { extension Bool: JSONEncodable {}
func encodeToJSON() -> Any { return self } extension Float: JSONEncodable {}
} extension Int: JSONEncodable {}
extension Int32: JSONEncodable {}
extension Float: JSONEncodable { extension Int64: JSONEncodable {}
func encodeToJSON() -> Any { return self } extension Double: JSONEncodable {}
} extension String: JSONEncodable {}
extension URL: JSONEncodable {}
extension Int: JSONEncodable { extension UUID: JSONEncodable {}
func encodeToJSON() -> Any { return self }
}
extension Int32: JSONEncodable {
func encodeToJSON() -> Any { return NSNumber(value: self as Int32) }
}
extension Int64: JSONEncodable {
func encodeToJSON() -> Any { return NSNumber(value: self as Int64) }
}
extension Double: JSONEncodable {
func encodeToJSON() -> Any { return self }
}
extension String: JSONEncodable {
func encodeToJSON() -> Any { return self }
}
extension RawRepresentable where RawValue: JSONEncodable { extension RawRepresentable where RawValue: JSONEncodable {
func encodeToJSON() -> Any { return self.rawValue } func encodeToJSON() -> Any { return self.rawValue }
@ -83,18 +65,6 @@ extension Date: JSONEncodable {
} }
} }
extension URL: JSONEncodable {
func encodeToJSON() -> Any {
return self
}
}
extension UUID: JSONEncodable {
func encodeToJSON() -> Any {
return self.uuidString
}
}
extension String: CodingKey { extension String: CodingKey {
public var stringValue: String { public var stringValue: String {

View File

@ -10,6 +10,10 @@ protocol JSONEncodable {
func encodeToJSON() -> Any func encodeToJSON() -> Any
} }
extension JSONEncodable {
func encodeToJSON() -> Any { self }
}
public enum ErrorResponse: Error { public enum ErrorResponse: Error {
case error(Int, Data?, URLResponse?, Error) case error(Int, Data?, URLResponse?, Error)
} }

View File

@ -9,33 +9,15 @@ import Foundation
import AnyCodable import AnyCodable
#endif #endif
extension Bool: JSONEncodable { extension Bool: JSONEncodable {}
func encodeToJSON() -> Any { return self } extension Float: JSONEncodable {}
} extension Int: JSONEncodable {}
extension Int32: JSONEncodable {}
extension Float: JSONEncodable { extension Int64: JSONEncodable {}
func encodeToJSON() -> Any { return self } extension Double: JSONEncodable {}
} extension String: JSONEncodable {}
extension URL: JSONEncodable {}
extension Int: JSONEncodable { extension UUID: JSONEncodable {}
func encodeToJSON() -> Any { return self }
}
extension Int32: JSONEncodable {
func encodeToJSON() -> Any { return NSNumber(value: self as Int32) }
}
extension Int64: JSONEncodable {
func encodeToJSON() -> Any { return NSNumber(value: self as Int64) }
}
extension Double: JSONEncodable {
func encodeToJSON() -> Any { return self }
}
extension String: JSONEncodable {
func encodeToJSON() -> Any { return self }
}
extension RawRepresentable where RawValue: JSONEncodable { extension RawRepresentable where RawValue: JSONEncodable {
func encodeToJSON() -> Any { return self.rawValue } func encodeToJSON() -> Any { return self.rawValue }
@ -83,18 +65,6 @@ extension Date: JSONEncodable {
} }
} }
extension URL: JSONEncodable {
func encodeToJSON() -> Any {
return self
}
}
extension UUID: JSONEncodable {
func encodeToJSON() -> Any {
return self.uuidString
}
}
extension String: CodingKey { extension String: CodingKey {
public var stringValue: String { public var stringValue: String {

View File

@ -10,6 +10,10 @@ protocol JSONEncodable {
func encodeToJSON() -> Any func encodeToJSON() -> Any
} }
extension JSONEncodable {
func encodeToJSON() -> Any { self }
}
public enum ErrorResponse: Error { public enum ErrorResponse: Error {
case error(Int, Data?, URLResponse?, Error) case error(Int, Data?, URLResponse?, Error)
} }

View File

@ -9,33 +9,15 @@ import Foundation
import AnyCodable import AnyCodable
#endif #endif
extension Bool: JSONEncodable { extension Bool: JSONEncodable {}
func encodeToJSON() -> Any { return self } extension Float: JSONEncodable {}
} extension Int: JSONEncodable {}
extension Int32: JSONEncodable {}
extension Float: JSONEncodable { extension Int64: JSONEncodable {}
func encodeToJSON() -> Any { return self } extension Double: JSONEncodable {}
} extension String: JSONEncodable {}
extension URL: JSONEncodable {}
extension Int: JSONEncodable { extension UUID: JSONEncodable {}
func encodeToJSON() -> Any { return self }
}
extension Int32: JSONEncodable {
func encodeToJSON() -> Any { return NSNumber(value: self as Int32) }
}
extension Int64: JSONEncodable {
func encodeToJSON() -> Any { return NSNumber(value: self as Int64) }
}
extension Double: JSONEncodable {
func encodeToJSON() -> Any { return self }
}
extension String: JSONEncodable {
func encodeToJSON() -> Any { return self }
}
extension RawRepresentable where RawValue: JSONEncodable { extension RawRepresentable where RawValue: JSONEncodable {
func encodeToJSON() -> Any { return self.rawValue } func encodeToJSON() -> Any { return self.rawValue }
@ -83,18 +65,6 @@ extension Date: JSONEncodable {
} }
} }
extension URL: JSONEncodable {
func encodeToJSON() -> Any {
return self
}
}
extension UUID: JSONEncodable {
func encodeToJSON() -> Any {
return self.uuidString
}
}
extension HTTPURLResponse { extension HTTPURLResponse {
var isStatusCodeSuccessful: Bool { var isStatusCodeSuccessful: Bool {
return (200 ..< 300).contains(statusCode) return (200 ..< 300).contains(statusCode)

View File

@ -10,6 +10,10 @@ protocol JSONEncodable {
func encodeToJSON() -> Any func encodeToJSON() -> Any
} }
extension JSONEncodable {
func encodeToJSON() -> Any { self }
}
public enum ErrorResponse: Error { public enum ErrorResponse: Error {
case error(Int, Data?, URLResponse?, Error) case error(Int, Data?, URLResponse?, Error)
} }

View File

@ -9,33 +9,15 @@ import Foundation
import AnyCodable import AnyCodable
#endif #endif
extension Bool: JSONEncodable { extension Bool: JSONEncodable {}
func encodeToJSON() -> Any { return self } extension Float: JSONEncodable {}
} extension Int: JSONEncodable {}
extension Int32: JSONEncodable {}
extension Float: JSONEncodable { extension Int64: JSONEncodable {}
func encodeToJSON() -> Any { return self } extension Double: JSONEncodable {}
} extension String: JSONEncodable {}
extension URL: JSONEncodable {}
extension Int: JSONEncodable { extension UUID: JSONEncodable {}
func encodeToJSON() -> Any { return self }
}
extension Int32: JSONEncodable {
func encodeToJSON() -> Any { return NSNumber(value: self as Int32) }
}
extension Int64: JSONEncodable {
func encodeToJSON() -> Any { return NSNumber(value: self as Int64) }
}
extension Double: JSONEncodable {
func encodeToJSON() -> Any { return self }
}
extension String: JSONEncodable {
func encodeToJSON() -> Any { return self }
}
extension RawRepresentable where RawValue: JSONEncodable { extension RawRepresentable where RawValue: JSONEncodable {
func encodeToJSON() -> Any { return self.rawValue } func encodeToJSON() -> Any { return self.rawValue }
@ -83,18 +65,6 @@ extension Date: JSONEncodable {
} }
} }
extension URL: JSONEncodable {
func encodeToJSON() -> Any {
return self
}
}
extension UUID: JSONEncodable {
func encodeToJSON() -> Any {
return self.uuidString
}
}
extension String: CodingKey { extension String: CodingKey {
public var stringValue: String { public var stringValue: String {

View File

@ -10,6 +10,10 @@ protocol JSONEncodable {
func encodeToJSON() -> Any func encodeToJSON() -> Any
} }
extension JSONEncodable {
func encodeToJSON() -> Any { self }
}
public enum ErrorResponse: Error { public enum ErrorResponse: Error {
case error(Int, Data?, URLResponse?, Error) case error(Int, Data?, URLResponse?, Error)
} }

View File

@ -9,33 +9,15 @@ import Foundation
import AnyCodable import AnyCodable
#endif #endif
extension Bool: JSONEncodable { extension Bool: JSONEncodable {}
func encodeToJSON() -> Any { return self } extension Float: JSONEncodable {}
} extension Int: JSONEncodable {}
extension Int32: JSONEncodable {}
extension Float: JSONEncodable { extension Int64: JSONEncodable {}
func encodeToJSON() -> Any { return self } extension Double: JSONEncodable {}
} extension String: JSONEncodable {}
extension URL: JSONEncodable {}
extension Int: JSONEncodable { extension UUID: JSONEncodable {}
func encodeToJSON() -> Any { return self }
}
extension Int32: JSONEncodable {
func encodeToJSON() -> Any { return NSNumber(value: self as Int32) }
}
extension Int64: JSONEncodable {
func encodeToJSON() -> Any { return NSNumber(value: self as Int64) }
}
extension Double: JSONEncodable {
func encodeToJSON() -> Any { return self }
}
extension String: JSONEncodable {
func encodeToJSON() -> Any { return self }
}
extension RawRepresentable where RawValue: JSONEncodable { extension RawRepresentable where RawValue: JSONEncodable {
func encodeToJSON() -> Any { return self.rawValue } func encodeToJSON() -> Any { return self.rawValue }
@ -83,18 +65,6 @@ extension Date: JSONEncodable {
} }
} }
extension URL: JSONEncodable {
func encodeToJSON() -> Any {
return self
}
}
extension UUID: JSONEncodable {
func encodeToJSON() -> Any {
return self.uuidString
}
}
extension String: CodingKey { extension String: CodingKey {
public var stringValue: String { public var stringValue: String {

View File

@ -10,6 +10,10 @@ protocol JSONEncodable {
func encodeToJSON() -> Any func encodeToJSON() -> Any
} }
extension JSONEncodable {
func encodeToJSON() -> Any { self }
}
public enum ErrorResponse: Error { public enum ErrorResponse: Error {
case error(Int, Data?, URLResponse?, Error) case error(Int, Data?, URLResponse?, Error)
} }