From a620853216ff7fb6848760bf559aff2db1cf946f Mon Sep 17 00:00:00 2001 From: Fumito Nakazawa Date: Fri, 26 Nov 2021 01:55:06 +0900 Subject: [PATCH] [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 --- .../main/resources/swift5/Extensions.mustache | 48 ++++--------------- .../src/main/resources/swift5/Models.mustache | 4 ++ samples/client/petstore/c/Packing.cmake | 24 ++++++++++ .../Classes/OpenAPIs/Extensions.swift | 48 ++++--------------- .../Classes/OpenAPIs/Models.swift | 4 ++ .../Classes/OpenAPIs/Extensions.swift | 48 ++++--------------- .../Classes/OpenAPIs/Models.swift | 4 ++ .../Classes/OpenAPIs/Extensions.swift | 48 ++++--------------- .../Classes/OpenAPIs/Models.swift | 4 ++ .../Classes/OpenAPIs/Extensions.swift | 48 ++++--------------- .../Classes/OpenAPIs/Models.swift | 4 ++ .../Classes/OpenAPIs/Extensions.swift | 48 ++++--------------- .../Classes/OpenAPIs/Models.swift | 4 ++ .../Classes/OpenAPIs/Extensions.swift | 48 ++++--------------- .../Classes/OpenAPIs/Models.swift | 4 ++ .../Classes/OpenAPIs/Extensions.swift | 48 ++++--------------- .../Classes/OpenAPIs/Models.swift | 4 ++ .../Classes/OpenAPIs/Extensions.swift | 48 ++++--------------- .../Classes/OpenAPIs/Models.swift | 4 ++ .../Classes/OpenAPIs/Extensions.swift | 48 ++++--------------- .../Classes/OpenAPIs/Models.swift | 4 ++ .../Classes/OpenAPIs/Extensions.swift | 48 ++++--------------- .../Classes/OpenAPIs/Models.swift | 4 ++ .../Classes/OpenAPIs/Extensions.swift | 48 ++++--------------- .../Classes/OpenAPIs/Models.swift | 4 ++ .../Classes/OpenAPIs/Extensions.swift | 48 ++++--------------- .../Classes/OpenAPIs/Models.swift | 4 ++ .../Sources/PetstoreClient/Extensions.swift | 48 ++++--------------- .../Sources/PetstoreClient/Models.swift | 4 ++ .../Classes/OpenAPIs/Extensions.swift | 48 ++++--------------- .../Classes/OpenAPIs/Models.swift | 4 ++ 31 files changed, 219 insertions(+), 585 deletions(-) create mode 100644 samples/client/petstore/c/Packing.cmake diff --git a/modules/openapi-generator/src/main/resources/swift5/Extensions.mustache b/modules/openapi-generator/src/main/resources/swift5/Extensions.mustache index b286fa9f42a..eb3fd11eb8e 100644 --- a/modules/openapi-generator/src/main/resources/swift5/Extensions.mustache +++ b/modules/openapi-generator/src/main/resources/swift5/Extensions.mustache @@ -11,33 +11,15 @@ import AnyCodable import PromiseKit{{/usePromiseKit}}{{#useVapor}} import Vapor{{/useVapor}}{{^useVapor}} -extension Bool: JSONEncodable { - func encodeToJSON() -> Any { return self } -} - -extension Float: JSONEncodable { - func encodeToJSON() -> Any { return self } -} - -extension Int: 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 Bool: JSONEncodable {} +extension Float: JSONEncodable {} +extension Int: JSONEncodable {} +extension Int32: JSONEncodable {} +extension Int64: JSONEncodable {} +extension Double: JSONEncodable {} +extension String: JSONEncodable {} +extension URL: JSONEncodable {} +extension UUID: JSONEncodable {} extension RawRepresentable where RawValue: JSONEncodable { func encodeToJSON() -> Any { return self.rawValue } @@ -83,18 +65,6 @@ extension Date: JSONEncodable { func encodeToJSON() -> Any { 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}} extension String: CodingKey { diff --git a/modules/openapi-generator/src/main/resources/swift5/Models.mustache b/modules/openapi-generator/src/main/resources/swift5/Models.mustache index e8ca64cdc52..3b2c5eafce1 100644 --- a/modules/openapi-generator/src/main/resources/swift5/Models.mustache +++ b/modules/openapi-generator/src/main/resources/swift5/Models.mustache @@ -10,6 +10,10 @@ protocol JSONEncodable { func encodeToJSON() -> Any } +extension JSONEncodable { + func encodeToJSON() -> Any { self } +} + {{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} enum ErrorResponse: Error { case error(Int, Data?, URLResponse?, Error) } diff --git a/samples/client/petstore/c/Packing.cmake b/samples/client/petstore/c/Packing.cmake new file mode 100644 index 00000000000..15bd4c8d5e9 --- /dev/null +++ b/samples/client/petstore/c/Packing.cmake @@ -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) \ No newline at end of file diff --git a/samples/client/petstore/swift5/alamofireLibrary/PetstoreClient/Classes/OpenAPIs/Extensions.swift b/samples/client/petstore/swift5/alamofireLibrary/PetstoreClient/Classes/OpenAPIs/Extensions.swift index 5831422f09d..e2b73073804 100644 --- a/samples/client/petstore/swift5/alamofireLibrary/PetstoreClient/Classes/OpenAPIs/Extensions.swift +++ b/samples/client/petstore/swift5/alamofireLibrary/PetstoreClient/Classes/OpenAPIs/Extensions.swift @@ -9,33 +9,15 @@ import Foundation import AnyCodable #endif -extension Bool: JSONEncodable { - func encodeToJSON() -> Any { return self } -} - -extension Float: JSONEncodable { - func encodeToJSON() -> Any { return self } -} - -extension Int: 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 Bool: JSONEncodable {} +extension Float: JSONEncodable {} +extension Int: JSONEncodable {} +extension Int32: JSONEncodable {} +extension Int64: JSONEncodable {} +extension Double: JSONEncodable {} +extension String: JSONEncodable {} +extension URL: JSONEncodable {} +extension UUID: JSONEncodable {} extension RawRepresentable where RawValue: JSONEncodable { 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 { public var stringValue: String { diff --git a/samples/client/petstore/swift5/alamofireLibrary/PetstoreClient/Classes/OpenAPIs/Models.swift b/samples/client/petstore/swift5/alamofireLibrary/PetstoreClient/Classes/OpenAPIs/Models.swift index e5802990167..ab4165a9b45 100644 --- a/samples/client/petstore/swift5/alamofireLibrary/PetstoreClient/Classes/OpenAPIs/Models.swift +++ b/samples/client/petstore/swift5/alamofireLibrary/PetstoreClient/Classes/OpenAPIs/Models.swift @@ -10,6 +10,10 @@ protocol JSONEncodable { func encodeToJSON() -> Any } +extension JSONEncodable { + func encodeToJSON() -> Any { self } +} + public enum ErrorResponse: Error { case error(Int, Data?, URLResponse?, Error) } diff --git a/samples/client/petstore/swift5/asyncAwaitLibrary/PetstoreClient/Classes/OpenAPIs/Extensions.swift b/samples/client/petstore/swift5/asyncAwaitLibrary/PetstoreClient/Classes/OpenAPIs/Extensions.swift index 5831422f09d..e2b73073804 100644 --- a/samples/client/petstore/swift5/asyncAwaitLibrary/PetstoreClient/Classes/OpenAPIs/Extensions.swift +++ b/samples/client/petstore/swift5/asyncAwaitLibrary/PetstoreClient/Classes/OpenAPIs/Extensions.swift @@ -9,33 +9,15 @@ import Foundation import AnyCodable #endif -extension Bool: JSONEncodable { - func encodeToJSON() -> Any { return self } -} - -extension Float: JSONEncodable { - func encodeToJSON() -> Any { return self } -} - -extension Int: 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 Bool: JSONEncodable {} +extension Float: JSONEncodable {} +extension Int: JSONEncodable {} +extension Int32: JSONEncodable {} +extension Int64: JSONEncodable {} +extension Double: JSONEncodable {} +extension String: JSONEncodable {} +extension URL: JSONEncodable {} +extension UUID: JSONEncodable {} extension RawRepresentable where RawValue: JSONEncodable { 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 { public var stringValue: String { diff --git a/samples/client/petstore/swift5/asyncAwaitLibrary/PetstoreClient/Classes/OpenAPIs/Models.swift b/samples/client/petstore/swift5/asyncAwaitLibrary/PetstoreClient/Classes/OpenAPIs/Models.swift index e5802990167..ab4165a9b45 100644 --- a/samples/client/petstore/swift5/asyncAwaitLibrary/PetstoreClient/Classes/OpenAPIs/Models.swift +++ b/samples/client/petstore/swift5/asyncAwaitLibrary/PetstoreClient/Classes/OpenAPIs/Models.swift @@ -10,6 +10,10 @@ protocol JSONEncodable { func encodeToJSON() -> Any } +extension JSONEncodable { + func encodeToJSON() -> Any { self } +} + public enum ErrorResponse: Error { case error(Int, Data?, URLResponse?, Error) } diff --git a/samples/client/petstore/swift5/combineLibrary/PetstoreClient/Classes/OpenAPIs/Extensions.swift b/samples/client/petstore/swift5/combineLibrary/PetstoreClient/Classes/OpenAPIs/Extensions.swift index 5831422f09d..e2b73073804 100644 --- a/samples/client/petstore/swift5/combineLibrary/PetstoreClient/Classes/OpenAPIs/Extensions.swift +++ b/samples/client/petstore/swift5/combineLibrary/PetstoreClient/Classes/OpenAPIs/Extensions.swift @@ -9,33 +9,15 @@ import Foundation import AnyCodable #endif -extension Bool: JSONEncodable { - func encodeToJSON() -> Any { return self } -} - -extension Float: JSONEncodable { - func encodeToJSON() -> Any { return self } -} - -extension Int: 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 Bool: JSONEncodable {} +extension Float: JSONEncodable {} +extension Int: JSONEncodable {} +extension Int32: JSONEncodable {} +extension Int64: JSONEncodable {} +extension Double: JSONEncodable {} +extension String: JSONEncodable {} +extension URL: JSONEncodable {} +extension UUID: JSONEncodable {} extension RawRepresentable where RawValue: JSONEncodable { 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 { public var stringValue: String { diff --git a/samples/client/petstore/swift5/combineLibrary/PetstoreClient/Classes/OpenAPIs/Models.swift b/samples/client/petstore/swift5/combineLibrary/PetstoreClient/Classes/OpenAPIs/Models.swift index e5802990167..ab4165a9b45 100644 --- a/samples/client/petstore/swift5/combineLibrary/PetstoreClient/Classes/OpenAPIs/Models.swift +++ b/samples/client/petstore/swift5/combineLibrary/PetstoreClient/Classes/OpenAPIs/Models.swift @@ -10,6 +10,10 @@ protocol JSONEncodable { func encodeToJSON() -> Any } +extension JSONEncodable { + func encodeToJSON() -> Any { self } +} + public enum ErrorResponse: Error { case error(Int, Data?, URLResponse?, Error) } diff --git a/samples/client/petstore/swift5/default/PetstoreClient/Classes/OpenAPIs/Extensions.swift b/samples/client/petstore/swift5/default/PetstoreClient/Classes/OpenAPIs/Extensions.swift index 5831422f09d..e2b73073804 100644 --- a/samples/client/petstore/swift5/default/PetstoreClient/Classes/OpenAPIs/Extensions.swift +++ b/samples/client/petstore/swift5/default/PetstoreClient/Classes/OpenAPIs/Extensions.swift @@ -9,33 +9,15 @@ import Foundation import AnyCodable #endif -extension Bool: JSONEncodable { - func encodeToJSON() -> Any { return self } -} - -extension Float: JSONEncodable { - func encodeToJSON() -> Any { return self } -} - -extension Int: 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 Bool: JSONEncodable {} +extension Float: JSONEncodable {} +extension Int: JSONEncodable {} +extension Int32: JSONEncodable {} +extension Int64: JSONEncodable {} +extension Double: JSONEncodable {} +extension String: JSONEncodable {} +extension URL: JSONEncodable {} +extension UUID: JSONEncodable {} extension RawRepresentable where RawValue: JSONEncodable { 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 { public var stringValue: String { diff --git a/samples/client/petstore/swift5/default/PetstoreClient/Classes/OpenAPIs/Models.swift b/samples/client/petstore/swift5/default/PetstoreClient/Classes/OpenAPIs/Models.swift index e5802990167..ab4165a9b45 100644 --- a/samples/client/petstore/swift5/default/PetstoreClient/Classes/OpenAPIs/Models.swift +++ b/samples/client/petstore/swift5/default/PetstoreClient/Classes/OpenAPIs/Models.swift @@ -10,6 +10,10 @@ protocol JSONEncodable { func encodeToJSON() -> Any } +extension JSONEncodable { + func encodeToJSON() -> Any { self } +} + public enum ErrorResponse: Error { case error(Int, Data?, URLResponse?, Error) } diff --git a/samples/client/petstore/swift5/deprecated/PetstoreClient/Classes/OpenAPIs/Extensions.swift b/samples/client/petstore/swift5/deprecated/PetstoreClient/Classes/OpenAPIs/Extensions.swift index 5831422f09d..e2b73073804 100644 --- a/samples/client/petstore/swift5/deprecated/PetstoreClient/Classes/OpenAPIs/Extensions.swift +++ b/samples/client/petstore/swift5/deprecated/PetstoreClient/Classes/OpenAPIs/Extensions.swift @@ -9,33 +9,15 @@ import Foundation import AnyCodable #endif -extension Bool: JSONEncodable { - func encodeToJSON() -> Any { return self } -} - -extension Float: JSONEncodable { - func encodeToJSON() -> Any { return self } -} - -extension Int: 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 Bool: JSONEncodable {} +extension Float: JSONEncodable {} +extension Int: JSONEncodable {} +extension Int32: JSONEncodable {} +extension Int64: JSONEncodable {} +extension Double: JSONEncodable {} +extension String: JSONEncodable {} +extension URL: JSONEncodable {} +extension UUID: JSONEncodable {} extension RawRepresentable where RawValue: JSONEncodable { 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 { public var stringValue: String { diff --git a/samples/client/petstore/swift5/deprecated/PetstoreClient/Classes/OpenAPIs/Models.swift b/samples/client/petstore/swift5/deprecated/PetstoreClient/Classes/OpenAPIs/Models.swift index e5802990167..ab4165a9b45 100644 --- a/samples/client/petstore/swift5/deprecated/PetstoreClient/Classes/OpenAPIs/Models.swift +++ b/samples/client/petstore/swift5/deprecated/PetstoreClient/Classes/OpenAPIs/Models.swift @@ -10,6 +10,10 @@ protocol JSONEncodable { func encodeToJSON() -> Any } +extension JSONEncodable { + func encodeToJSON() -> Any { self } +} + public enum ErrorResponse: Error { case error(Int, Data?, URLResponse?, Error) } diff --git a/samples/client/petstore/swift5/nonPublicApi/PetstoreClient/Classes/OpenAPIs/Extensions.swift b/samples/client/petstore/swift5/nonPublicApi/PetstoreClient/Classes/OpenAPIs/Extensions.swift index 63647fe3703..255ab49db7b 100644 --- a/samples/client/petstore/swift5/nonPublicApi/PetstoreClient/Classes/OpenAPIs/Extensions.swift +++ b/samples/client/petstore/swift5/nonPublicApi/PetstoreClient/Classes/OpenAPIs/Extensions.swift @@ -9,33 +9,15 @@ import Foundation import AnyCodable #endif -extension Bool: JSONEncodable { - func encodeToJSON() -> Any { return self } -} - -extension Float: JSONEncodable { - func encodeToJSON() -> Any { return self } -} - -extension Int: 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 Bool: JSONEncodable {} +extension Float: JSONEncodable {} +extension Int: JSONEncodable {} +extension Int32: JSONEncodable {} +extension Int64: JSONEncodable {} +extension Double: JSONEncodable {} +extension String: JSONEncodable {} +extension URL: JSONEncodable {} +extension UUID: JSONEncodable {} extension RawRepresentable where RawValue: JSONEncodable { 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 { public var stringValue: String { diff --git a/samples/client/petstore/swift5/nonPublicApi/PetstoreClient/Classes/OpenAPIs/Models.swift b/samples/client/petstore/swift5/nonPublicApi/PetstoreClient/Classes/OpenAPIs/Models.swift index 5db24390bd7..0c1c7548898 100644 --- a/samples/client/petstore/swift5/nonPublicApi/PetstoreClient/Classes/OpenAPIs/Models.swift +++ b/samples/client/petstore/swift5/nonPublicApi/PetstoreClient/Classes/OpenAPIs/Models.swift @@ -10,6 +10,10 @@ protocol JSONEncodable { func encodeToJSON() -> Any } +extension JSONEncodable { + func encodeToJSON() -> Any { self } +} + internal enum ErrorResponse: Error { case error(Int, Data?, URLResponse?, Error) } diff --git a/samples/client/petstore/swift5/objcCompatible/PetstoreClient/Classes/OpenAPIs/Extensions.swift b/samples/client/petstore/swift5/objcCompatible/PetstoreClient/Classes/OpenAPIs/Extensions.swift index 5831422f09d..e2b73073804 100644 --- a/samples/client/petstore/swift5/objcCompatible/PetstoreClient/Classes/OpenAPIs/Extensions.swift +++ b/samples/client/petstore/swift5/objcCompatible/PetstoreClient/Classes/OpenAPIs/Extensions.swift @@ -9,33 +9,15 @@ import Foundation import AnyCodable #endif -extension Bool: JSONEncodable { - func encodeToJSON() -> Any { return self } -} - -extension Float: JSONEncodable { - func encodeToJSON() -> Any { return self } -} - -extension Int: 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 Bool: JSONEncodable {} +extension Float: JSONEncodable {} +extension Int: JSONEncodable {} +extension Int32: JSONEncodable {} +extension Int64: JSONEncodable {} +extension Double: JSONEncodable {} +extension String: JSONEncodable {} +extension URL: JSONEncodable {} +extension UUID: JSONEncodable {} extension RawRepresentable where RawValue: JSONEncodable { 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 { public var stringValue: String { diff --git a/samples/client/petstore/swift5/objcCompatible/PetstoreClient/Classes/OpenAPIs/Models.swift b/samples/client/petstore/swift5/objcCompatible/PetstoreClient/Classes/OpenAPIs/Models.swift index e5802990167..ab4165a9b45 100644 --- a/samples/client/petstore/swift5/objcCompatible/PetstoreClient/Classes/OpenAPIs/Models.swift +++ b/samples/client/petstore/swift5/objcCompatible/PetstoreClient/Classes/OpenAPIs/Models.swift @@ -10,6 +10,10 @@ protocol JSONEncodable { func encodeToJSON() -> Any } +extension JSONEncodable { + func encodeToJSON() -> Any { self } +} + public enum ErrorResponse: Error { case error(Int, Data?, URLResponse?, Error) } diff --git a/samples/client/petstore/swift5/oneOf/PetstoreClient/Classes/OpenAPIs/Extensions.swift b/samples/client/petstore/swift5/oneOf/PetstoreClient/Classes/OpenAPIs/Extensions.swift index 5831422f09d..e2b73073804 100644 --- a/samples/client/petstore/swift5/oneOf/PetstoreClient/Classes/OpenAPIs/Extensions.swift +++ b/samples/client/petstore/swift5/oneOf/PetstoreClient/Classes/OpenAPIs/Extensions.swift @@ -9,33 +9,15 @@ import Foundation import AnyCodable #endif -extension Bool: JSONEncodable { - func encodeToJSON() -> Any { return self } -} - -extension Float: JSONEncodable { - func encodeToJSON() -> Any { return self } -} - -extension Int: 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 Bool: JSONEncodable {} +extension Float: JSONEncodable {} +extension Int: JSONEncodable {} +extension Int32: JSONEncodable {} +extension Int64: JSONEncodable {} +extension Double: JSONEncodable {} +extension String: JSONEncodable {} +extension URL: JSONEncodable {} +extension UUID: JSONEncodable {} extension RawRepresentable where RawValue: JSONEncodable { 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 { public var stringValue: String { diff --git a/samples/client/petstore/swift5/oneOf/PetstoreClient/Classes/OpenAPIs/Models.swift b/samples/client/petstore/swift5/oneOf/PetstoreClient/Classes/OpenAPIs/Models.swift index e5802990167..ab4165a9b45 100644 --- a/samples/client/petstore/swift5/oneOf/PetstoreClient/Classes/OpenAPIs/Models.swift +++ b/samples/client/petstore/swift5/oneOf/PetstoreClient/Classes/OpenAPIs/Models.swift @@ -10,6 +10,10 @@ protocol JSONEncodable { func encodeToJSON() -> Any } +extension JSONEncodable { + func encodeToJSON() -> Any { self } +} + public enum ErrorResponse: Error { case error(Int, Data?, URLResponse?, Error) } diff --git a/samples/client/petstore/swift5/promisekitLibrary/PetstoreClient/Classes/OpenAPIs/Extensions.swift b/samples/client/petstore/swift5/promisekitLibrary/PetstoreClient/Classes/OpenAPIs/Extensions.swift index 2c1ceeb385b..cc93d4c30d3 100644 --- a/samples/client/petstore/swift5/promisekitLibrary/PetstoreClient/Classes/OpenAPIs/Extensions.swift +++ b/samples/client/petstore/swift5/promisekitLibrary/PetstoreClient/Classes/OpenAPIs/Extensions.swift @@ -10,33 +10,15 @@ import AnyCodable #endif import PromiseKit -extension Bool: JSONEncodable { - func encodeToJSON() -> Any { return self } -} - -extension Float: JSONEncodable { - func encodeToJSON() -> Any { return self } -} - -extension Int: 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 Bool: JSONEncodable {} +extension Float: JSONEncodable {} +extension Int: JSONEncodable {} +extension Int32: JSONEncodable {} +extension Int64: JSONEncodable {} +extension Double: JSONEncodable {} +extension String: JSONEncodable {} +extension URL: JSONEncodable {} +extension UUID: JSONEncodable {} extension RawRepresentable where RawValue: JSONEncodable { 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 { public var stringValue: String { diff --git a/samples/client/petstore/swift5/promisekitLibrary/PetstoreClient/Classes/OpenAPIs/Models.swift b/samples/client/petstore/swift5/promisekitLibrary/PetstoreClient/Classes/OpenAPIs/Models.swift index e5802990167..ab4165a9b45 100644 --- a/samples/client/petstore/swift5/promisekitLibrary/PetstoreClient/Classes/OpenAPIs/Models.swift +++ b/samples/client/petstore/swift5/promisekitLibrary/PetstoreClient/Classes/OpenAPIs/Models.swift @@ -10,6 +10,10 @@ protocol JSONEncodable { func encodeToJSON() -> Any } +extension JSONEncodable { + func encodeToJSON() -> Any { self } +} + public enum ErrorResponse: Error { case error(Int, Data?, URLResponse?, Error) } diff --git a/samples/client/petstore/swift5/readonlyProperties/PetstoreClient/Classes/OpenAPIs/Extensions.swift b/samples/client/petstore/swift5/readonlyProperties/PetstoreClient/Classes/OpenAPIs/Extensions.swift index 5831422f09d..e2b73073804 100644 --- a/samples/client/petstore/swift5/readonlyProperties/PetstoreClient/Classes/OpenAPIs/Extensions.swift +++ b/samples/client/petstore/swift5/readonlyProperties/PetstoreClient/Classes/OpenAPIs/Extensions.swift @@ -9,33 +9,15 @@ import Foundation import AnyCodable #endif -extension Bool: JSONEncodable { - func encodeToJSON() -> Any { return self } -} - -extension Float: JSONEncodable { - func encodeToJSON() -> Any { return self } -} - -extension Int: 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 Bool: JSONEncodable {} +extension Float: JSONEncodable {} +extension Int: JSONEncodable {} +extension Int32: JSONEncodable {} +extension Int64: JSONEncodable {} +extension Double: JSONEncodable {} +extension String: JSONEncodable {} +extension URL: JSONEncodable {} +extension UUID: JSONEncodable {} extension RawRepresentable where RawValue: JSONEncodable { 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 { public var stringValue: String { diff --git a/samples/client/petstore/swift5/readonlyProperties/PetstoreClient/Classes/OpenAPIs/Models.swift b/samples/client/petstore/swift5/readonlyProperties/PetstoreClient/Classes/OpenAPIs/Models.swift index e5802990167..ab4165a9b45 100644 --- a/samples/client/petstore/swift5/readonlyProperties/PetstoreClient/Classes/OpenAPIs/Models.swift +++ b/samples/client/petstore/swift5/readonlyProperties/PetstoreClient/Classes/OpenAPIs/Models.swift @@ -10,6 +10,10 @@ protocol JSONEncodable { func encodeToJSON() -> Any } +extension JSONEncodable { + func encodeToJSON() -> Any { self } +} + public enum ErrorResponse: Error { case error(Int, Data?, URLResponse?, Error) } diff --git a/samples/client/petstore/swift5/resultLibrary/PetstoreClient/Classes/OpenAPIs/Extensions.swift b/samples/client/petstore/swift5/resultLibrary/PetstoreClient/Classes/OpenAPIs/Extensions.swift index 5831422f09d..e2b73073804 100644 --- a/samples/client/petstore/swift5/resultLibrary/PetstoreClient/Classes/OpenAPIs/Extensions.swift +++ b/samples/client/petstore/swift5/resultLibrary/PetstoreClient/Classes/OpenAPIs/Extensions.swift @@ -9,33 +9,15 @@ import Foundation import AnyCodable #endif -extension Bool: JSONEncodable { - func encodeToJSON() -> Any { return self } -} - -extension Float: JSONEncodable { - func encodeToJSON() -> Any { return self } -} - -extension Int: 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 Bool: JSONEncodable {} +extension Float: JSONEncodable {} +extension Int: JSONEncodable {} +extension Int32: JSONEncodable {} +extension Int64: JSONEncodable {} +extension Double: JSONEncodable {} +extension String: JSONEncodable {} +extension URL: JSONEncodable {} +extension UUID: JSONEncodable {} extension RawRepresentable where RawValue: JSONEncodable { 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 { public var stringValue: String { diff --git a/samples/client/petstore/swift5/resultLibrary/PetstoreClient/Classes/OpenAPIs/Models.swift b/samples/client/petstore/swift5/resultLibrary/PetstoreClient/Classes/OpenAPIs/Models.swift index e5802990167..ab4165a9b45 100644 --- a/samples/client/petstore/swift5/resultLibrary/PetstoreClient/Classes/OpenAPIs/Models.swift +++ b/samples/client/petstore/swift5/resultLibrary/PetstoreClient/Classes/OpenAPIs/Models.swift @@ -10,6 +10,10 @@ protocol JSONEncodable { func encodeToJSON() -> Any } +extension JSONEncodable { + func encodeToJSON() -> Any { self } +} + public enum ErrorResponse: Error { case error(Int, Data?, URLResponse?, Error) } diff --git a/samples/client/petstore/swift5/rxswiftLibrary/PetstoreClient/Classes/OpenAPIs/Extensions.swift b/samples/client/petstore/swift5/rxswiftLibrary/PetstoreClient/Classes/OpenAPIs/Extensions.swift index 4077c82552a..570ea5f64bd 100644 --- a/samples/client/petstore/swift5/rxswiftLibrary/PetstoreClient/Classes/OpenAPIs/Extensions.swift +++ b/samples/client/petstore/swift5/rxswiftLibrary/PetstoreClient/Classes/OpenAPIs/Extensions.swift @@ -9,33 +9,15 @@ import Foundation import AnyCodable #endif -extension Bool: JSONEncodable { - func encodeToJSON() -> Any { return self } -} - -extension Float: JSONEncodable { - func encodeToJSON() -> Any { return self } -} - -extension Int: 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 Bool: JSONEncodable {} +extension Float: JSONEncodable {} +extension Int: JSONEncodable {} +extension Int32: JSONEncodable {} +extension Int64: JSONEncodable {} +extension Double: JSONEncodable {} +extension String: JSONEncodable {} +extension URL: JSONEncodable {} +extension UUID: JSONEncodable {} extension RawRepresentable where RawValue: JSONEncodable { 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 { var isStatusCodeSuccessful: Bool { return (200 ..< 300).contains(statusCode) diff --git a/samples/client/petstore/swift5/rxswiftLibrary/PetstoreClient/Classes/OpenAPIs/Models.swift b/samples/client/petstore/swift5/rxswiftLibrary/PetstoreClient/Classes/OpenAPIs/Models.swift index e5802990167..ab4165a9b45 100644 --- a/samples/client/petstore/swift5/rxswiftLibrary/PetstoreClient/Classes/OpenAPIs/Models.swift +++ b/samples/client/petstore/swift5/rxswiftLibrary/PetstoreClient/Classes/OpenAPIs/Models.swift @@ -10,6 +10,10 @@ protocol JSONEncodable { func encodeToJSON() -> Any } +extension JSONEncodable { + func encodeToJSON() -> Any { self } +} + public enum ErrorResponse: Error { case error(Int, Data?, URLResponse?, Error) } diff --git a/samples/client/petstore/swift5/urlsessionLibrary/Sources/PetstoreClient/Extensions.swift b/samples/client/petstore/swift5/urlsessionLibrary/Sources/PetstoreClient/Extensions.swift index 5831422f09d..e2b73073804 100644 --- a/samples/client/petstore/swift5/urlsessionLibrary/Sources/PetstoreClient/Extensions.swift +++ b/samples/client/petstore/swift5/urlsessionLibrary/Sources/PetstoreClient/Extensions.swift @@ -9,33 +9,15 @@ import Foundation import AnyCodable #endif -extension Bool: JSONEncodable { - func encodeToJSON() -> Any { return self } -} - -extension Float: JSONEncodable { - func encodeToJSON() -> Any { return self } -} - -extension Int: 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 Bool: JSONEncodable {} +extension Float: JSONEncodable {} +extension Int: JSONEncodable {} +extension Int32: JSONEncodable {} +extension Int64: JSONEncodable {} +extension Double: JSONEncodable {} +extension String: JSONEncodable {} +extension URL: JSONEncodable {} +extension UUID: JSONEncodable {} extension RawRepresentable where RawValue: JSONEncodable { 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 { public var stringValue: String { diff --git a/samples/client/petstore/swift5/urlsessionLibrary/Sources/PetstoreClient/Models.swift b/samples/client/petstore/swift5/urlsessionLibrary/Sources/PetstoreClient/Models.swift index e5802990167..ab4165a9b45 100644 --- a/samples/client/petstore/swift5/urlsessionLibrary/Sources/PetstoreClient/Models.swift +++ b/samples/client/petstore/swift5/urlsessionLibrary/Sources/PetstoreClient/Models.swift @@ -10,6 +10,10 @@ protocol JSONEncodable { func encodeToJSON() -> Any } +extension JSONEncodable { + func encodeToJSON() -> Any { self } +} + public enum ErrorResponse: Error { case error(Int, Data?, URLResponse?, Error) } diff --git a/samples/client/petstore/swift5/x-swift-hashable/PetstoreClient/Classes/OpenAPIs/Extensions.swift b/samples/client/petstore/swift5/x-swift-hashable/PetstoreClient/Classes/OpenAPIs/Extensions.swift index 5831422f09d..e2b73073804 100644 --- a/samples/client/petstore/swift5/x-swift-hashable/PetstoreClient/Classes/OpenAPIs/Extensions.swift +++ b/samples/client/petstore/swift5/x-swift-hashable/PetstoreClient/Classes/OpenAPIs/Extensions.swift @@ -9,33 +9,15 @@ import Foundation import AnyCodable #endif -extension Bool: JSONEncodable { - func encodeToJSON() -> Any { return self } -} - -extension Float: JSONEncodable { - func encodeToJSON() -> Any { return self } -} - -extension Int: 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 Bool: JSONEncodable {} +extension Float: JSONEncodable {} +extension Int: JSONEncodable {} +extension Int32: JSONEncodable {} +extension Int64: JSONEncodable {} +extension Double: JSONEncodable {} +extension String: JSONEncodable {} +extension URL: JSONEncodable {} +extension UUID: JSONEncodable {} extension RawRepresentable where RawValue: JSONEncodable { 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 { public var stringValue: String { diff --git a/samples/client/petstore/swift5/x-swift-hashable/PetstoreClient/Classes/OpenAPIs/Models.swift b/samples/client/petstore/swift5/x-swift-hashable/PetstoreClient/Classes/OpenAPIs/Models.swift index e5802990167..ab4165a9b45 100644 --- a/samples/client/petstore/swift5/x-swift-hashable/PetstoreClient/Classes/OpenAPIs/Models.swift +++ b/samples/client/petstore/swift5/x-swift-hashable/PetstoreClient/Classes/OpenAPIs/Models.swift @@ -10,6 +10,10 @@ protocol JSONEncodable { func encodeToJSON() -> Any } +extension JSONEncodable { + func encodeToJSON() -> Any { self } +} + public enum ErrorResponse: Error { case error(Int, Data?, URLResponse?, Error) }