From 38d92525a7d21b920c93ca7bdb4eb9e00721abb7 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Wed, 26 Aug 2020 17:49:11 +0800 Subject: [PATCH] add extension for hashable in swift5 --- .../codegen/languages/Swift5ClientCodegen.java | 1 + .../src/main/resources/swift5/modelObject.mustache | 10 +++++++--- ...etstore-with-fake-endpoints-models-for-testing.yaml | 1 + .../PetstoreClient/Classes/OpenAPIs/Models/Pet.swift | 2 +- .../PetstoreClient/Classes/OpenAPIs/Models/Pet.swift | 2 +- .../PetstoreClient/Classes/OpenAPIs/Models/Pet.swift | 2 +- .../PetstoreClient/Classes/OpenAPIs/Models/Pet.swift | 2 +- .../Classes/OpenAPIs/Models/ClassModel.swift | 1 - .../PetstoreClient/Classes/OpenAPIs/Models/File.swift | 1 - .../Classes/OpenAPIs/Models/Model200Response.swift | 1 - .../PetstoreClient/Classes/OpenAPIs/Models/Name.swift | 1 - .../PetstoreClient/Classes/OpenAPIs/Models/Pet.swift | 2 +- .../Classes/OpenAPIs/Models/Return.swift | 1 - .../PetstoreClient/Classes/OpenAPIs/Models/Pet.swift | 2 +- .../PetstoreClient/Classes/OpenAPIs/Models/Pet.swift | 2 +- .../PetstoreClient/Classes/OpenAPIs/Models/Pet.swift | 2 +- .../PetstoreClient/Classes/OpenAPIs/Models/Pet.swift | 2 +- .../PetstoreClient/Classes/OpenAPIs/Models/Pet.swift | 2 +- 18 files changed, 19 insertions(+), 18 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/Swift5ClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/Swift5ClientCodegen.java index 3eb2c0ee6508..628ede8f2f31 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/Swift5ClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/Swift5ClientCodegen.java @@ -197,6 +197,7 @@ public Swift5ClientCodegen() { typeMapping.put("array", "Array"); typeMapping.put("List", "Array"); typeMapping.put("map", "Dictionary"); + typeMapping.put("set", "Set"); typeMapping.put("date", "Date"); typeMapping.put("Date", "Date"); typeMapping.put("DateTime", "Date"); diff --git a/modules/openapi-generator/src/main/resources/swift5/modelObject.mustache b/modules/openapi-generator/src/main/resources/swift5/modelObject.mustache index 086bf4bce74f..ab306247543c 100644 --- a/modules/openapi-generator/src/main/resources/swift5/modelObject.mustache +++ b/modules/openapi-generator/src/main/resources/swift5/modelObject.mustache @@ -1,5 +1,9 @@ -{{^objcCompatible}}{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} struct {{classname}}: Codable { {{/objcCompatible}} -{{#objcCompatible}}@objc {{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} class {{classname}}: NSObject, Codable { {{/objcCompatible}} +{{^objcCompatible}} +{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} struct {{classname}}: Codable{{#vendorExtensions.x-swift-hashable}}, Hashable{{/vendorExtensions.x-swift-hashable}} { +{{/objcCompatible}} +{{#objcCompatible}} +@objc {{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} class {{classname}}: NSObject, Codable{{#vendorExtensions.x-swift-hashable}}, Hashable{{/vendorExtensions.x-swift-hashable}} { +{{/objcCompatible}} {{#allVars}} {{#isEnum}} @@ -86,4 +90,4 @@ case {{name}}{{#vendorExtensions.x-codegen-escaped-property-name}} = "{{{baseName}}}"{{/vendorExtensions.x-codegen-escaped-property-name}}{{/allVars}} } {{/vendorExtensions.x-codegen-has-escaped-property-names}}{{/additionalPropertiesType}} -} \ No newline at end of file +} diff --git a/modules/openapi-generator/src/test/resources/2_0/swift/petstore-with-fake-endpoints-models-for-testing.yaml b/modules/openapi-generator/src/test/resources/2_0/swift/petstore-with-fake-endpoints-models-for-testing.yaml index bc690cd78386..505aa0dd631a 100644 --- a/modules/openapi-generator/src/test/resources/2_0/swift/petstore-with-fake-endpoints-models-for-testing.yaml +++ b/modules/openapi-generator/src/test/resources/2_0/swift/petstore-with-fake-endpoints-models-for-testing.yaml @@ -1134,6 +1134,7 @@ definitions: xml: name: Tag Pet: + x-swift-hashable: true type: object required: - name diff --git a/samples/client/petstore/swift5/alamofireLibrary/PetstoreClient/Classes/OpenAPIs/Models/Pet.swift b/samples/client/petstore/swift5/alamofireLibrary/PetstoreClient/Classes/OpenAPIs/Models/Pet.swift index caea19425d85..1bc823d3e960 100644 --- a/samples/client/petstore/swift5/alamofireLibrary/PetstoreClient/Classes/OpenAPIs/Models/Pet.swift +++ b/samples/client/petstore/swift5/alamofireLibrary/PetstoreClient/Classes/OpenAPIs/Models/Pet.swift @@ -7,7 +7,7 @@ import Foundation -public struct Pet: Codable { +public struct Pet: Codable, Hashable { public enum Status: String, Codable, CaseIterable { case available = "available" diff --git a/samples/client/petstore/swift5/combineLibrary/PetstoreClient/Classes/OpenAPIs/Models/Pet.swift b/samples/client/petstore/swift5/combineLibrary/PetstoreClient/Classes/OpenAPIs/Models/Pet.swift index caea19425d85..1bc823d3e960 100644 --- a/samples/client/petstore/swift5/combineLibrary/PetstoreClient/Classes/OpenAPIs/Models/Pet.swift +++ b/samples/client/petstore/swift5/combineLibrary/PetstoreClient/Classes/OpenAPIs/Models/Pet.swift @@ -7,7 +7,7 @@ import Foundation -public struct Pet: Codable { +public struct Pet: Codable, Hashable { public enum Status: String, Codable, CaseIterable { case available = "available" diff --git a/samples/client/petstore/swift5/default/PetstoreClient/Classes/OpenAPIs/Models/Pet.swift b/samples/client/petstore/swift5/default/PetstoreClient/Classes/OpenAPIs/Models/Pet.swift index caea19425d85..1bc823d3e960 100644 --- a/samples/client/petstore/swift5/default/PetstoreClient/Classes/OpenAPIs/Models/Pet.swift +++ b/samples/client/petstore/swift5/default/PetstoreClient/Classes/OpenAPIs/Models/Pet.swift @@ -7,7 +7,7 @@ import Foundation -public struct Pet: Codable { +public struct Pet: Codable, Hashable { public enum Status: String, Codable, CaseIterable { case available = "available" diff --git a/samples/client/petstore/swift5/nonPublicApi/PetstoreClient/Classes/OpenAPIs/Models/Pet.swift b/samples/client/petstore/swift5/nonPublicApi/PetstoreClient/Classes/OpenAPIs/Models/Pet.swift index 6d0dee3d3d39..c388433da77b 100644 --- a/samples/client/petstore/swift5/nonPublicApi/PetstoreClient/Classes/OpenAPIs/Models/Pet.swift +++ b/samples/client/petstore/swift5/nonPublicApi/PetstoreClient/Classes/OpenAPIs/Models/Pet.swift @@ -7,7 +7,7 @@ import Foundation -internal struct Pet: Codable { +internal struct Pet: Codable, Hashable { internal enum Status: String, Codable, CaseIterable { case available = "available" diff --git a/samples/client/petstore/swift5/objcCompatible/PetstoreClient/Classes/OpenAPIs/Models/ClassModel.swift b/samples/client/petstore/swift5/objcCompatible/PetstoreClient/Classes/OpenAPIs/Models/ClassModel.swift index 2005900e6b52..648f3a6bfb5a 100644 --- a/samples/client/petstore/swift5/objcCompatible/PetstoreClient/Classes/OpenAPIs/Models/ClassModel.swift +++ b/samples/client/petstore/swift5/objcCompatible/PetstoreClient/Classes/OpenAPIs/Models/ClassModel.swift @@ -8,7 +8,6 @@ import Foundation /** Model for testing model with \"_class\" property */ - @objc public class ClassModel: NSObject, Codable { public var _class: String? diff --git a/samples/client/petstore/swift5/objcCompatible/PetstoreClient/Classes/OpenAPIs/Models/File.swift b/samples/client/petstore/swift5/objcCompatible/PetstoreClient/Classes/OpenAPIs/Models/File.swift index 4c6ab7da6c89..5124dd3b089d 100644 --- a/samples/client/petstore/swift5/objcCompatible/PetstoreClient/Classes/OpenAPIs/Models/File.swift +++ b/samples/client/petstore/swift5/objcCompatible/PetstoreClient/Classes/OpenAPIs/Models/File.swift @@ -8,7 +8,6 @@ import Foundation /** Must be named `File` for test. */ - @objc public class File: NSObject, Codable { /** Test capitalization */ diff --git a/samples/client/petstore/swift5/objcCompatible/PetstoreClient/Classes/OpenAPIs/Models/Model200Response.swift b/samples/client/petstore/swift5/objcCompatible/PetstoreClient/Classes/OpenAPIs/Models/Model200Response.swift index 6814183719d9..89c612262d2f 100644 --- a/samples/client/petstore/swift5/objcCompatible/PetstoreClient/Classes/OpenAPIs/Models/Model200Response.swift +++ b/samples/client/petstore/swift5/objcCompatible/PetstoreClient/Classes/OpenAPIs/Models/Model200Response.swift @@ -8,7 +8,6 @@ import Foundation /** Model for testing model name starting with number */ - @objc public class Model200Response: NSObject, Codable { public var name: Int? diff --git a/samples/client/petstore/swift5/objcCompatible/PetstoreClient/Classes/OpenAPIs/Models/Name.swift b/samples/client/petstore/swift5/objcCompatible/PetstoreClient/Classes/OpenAPIs/Models/Name.swift index 6ecf78e38859..15b0507a4785 100644 --- a/samples/client/petstore/swift5/objcCompatible/PetstoreClient/Classes/OpenAPIs/Models/Name.swift +++ b/samples/client/petstore/swift5/objcCompatible/PetstoreClient/Classes/OpenAPIs/Models/Name.swift @@ -8,7 +8,6 @@ import Foundation /** Model for testing model name same as property name */ - @objc public class Name: NSObject, Codable { public var name: Int diff --git a/samples/client/petstore/swift5/objcCompatible/PetstoreClient/Classes/OpenAPIs/Models/Pet.swift b/samples/client/petstore/swift5/objcCompatible/PetstoreClient/Classes/OpenAPIs/Models/Pet.swift index e17ada14c425..b38ff2e23a72 100644 --- a/samples/client/petstore/swift5/objcCompatible/PetstoreClient/Classes/OpenAPIs/Models/Pet.swift +++ b/samples/client/petstore/swift5/objcCompatible/PetstoreClient/Classes/OpenAPIs/Models/Pet.swift @@ -7,7 +7,7 @@ import Foundation -@objc public class Pet: NSObject, Codable { +@objc public class Pet: NSObject, Codable, Hashable { public enum Status: String, Codable, CaseIterable { case available = "available" diff --git a/samples/client/petstore/swift5/objcCompatible/PetstoreClient/Classes/OpenAPIs/Models/Return.swift b/samples/client/petstore/swift5/objcCompatible/PetstoreClient/Classes/OpenAPIs/Models/Return.swift index 9f886e6d507b..e589a9c20048 100644 --- a/samples/client/petstore/swift5/objcCompatible/PetstoreClient/Classes/OpenAPIs/Models/Return.swift +++ b/samples/client/petstore/swift5/objcCompatible/PetstoreClient/Classes/OpenAPIs/Models/Return.swift @@ -8,7 +8,6 @@ import Foundation /** Model for testing reserved words */ - @objc public class Return: NSObject, Codable { public var _return: Int? diff --git a/samples/client/petstore/swift5/promisekitLibrary/PetstoreClient/Classes/OpenAPIs/Models/Pet.swift b/samples/client/petstore/swift5/promisekitLibrary/PetstoreClient/Classes/OpenAPIs/Models/Pet.swift index caea19425d85..1bc823d3e960 100644 --- a/samples/client/petstore/swift5/promisekitLibrary/PetstoreClient/Classes/OpenAPIs/Models/Pet.swift +++ b/samples/client/petstore/swift5/promisekitLibrary/PetstoreClient/Classes/OpenAPIs/Models/Pet.swift @@ -7,7 +7,7 @@ import Foundation -public struct Pet: Codable { +public struct Pet: Codable, Hashable { public enum Status: String, Codable, CaseIterable { case available = "available" diff --git a/samples/client/petstore/swift5/readonlyProperties/PetstoreClient/Classes/OpenAPIs/Models/Pet.swift b/samples/client/petstore/swift5/readonlyProperties/PetstoreClient/Classes/OpenAPIs/Models/Pet.swift index f13bd2f2c31b..561d18526968 100644 --- a/samples/client/petstore/swift5/readonlyProperties/PetstoreClient/Classes/OpenAPIs/Models/Pet.swift +++ b/samples/client/petstore/swift5/readonlyProperties/PetstoreClient/Classes/OpenAPIs/Models/Pet.swift @@ -7,7 +7,7 @@ import Foundation -public struct Pet: Codable { +public struct Pet: Codable, Hashable { public enum Status: String, Codable, CaseIterable { case available = "available" diff --git a/samples/client/petstore/swift5/resultLibrary/PetstoreClient/Classes/OpenAPIs/Models/Pet.swift b/samples/client/petstore/swift5/resultLibrary/PetstoreClient/Classes/OpenAPIs/Models/Pet.swift index caea19425d85..1bc823d3e960 100644 --- a/samples/client/petstore/swift5/resultLibrary/PetstoreClient/Classes/OpenAPIs/Models/Pet.swift +++ b/samples/client/petstore/swift5/resultLibrary/PetstoreClient/Classes/OpenAPIs/Models/Pet.swift @@ -7,7 +7,7 @@ import Foundation -public struct Pet: Codable { +public struct Pet: Codable, Hashable { public enum Status: String, Codable, CaseIterable { case available = "available" diff --git a/samples/client/petstore/swift5/rxswiftLibrary/PetstoreClient/Classes/OpenAPIs/Models/Pet.swift b/samples/client/petstore/swift5/rxswiftLibrary/PetstoreClient/Classes/OpenAPIs/Models/Pet.swift index caea19425d85..1bc823d3e960 100644 --- a/samples/client/petstore/swift5/rxswiftLibrary/PetstoreClient/Classes/OpenAPIs/Models/Pet.swift +++ b/samples/client/petstore/swift5/rxswiftLibrary/PetstoreClient/Classes/OpenAPIs/Models/Pet.swift @@ -7,7 +7,7 @@ import Foundation -public struct Pet: Codable { +public struct Pet: Codable, Hashable { public enum Status: String, Codable, CaseIterable { case available = "available" diff --git a/samples/client/petstore/swift5/urlsessionLibrary/PetstoreClient/Classes/OpenAPIs/Models/Pet.swift b/samples/client/petstore/swift5/urlsessionLibrary/PetstoreClient/Classes/OpenAPIs/Models/Pet.swift index caea19425d85..1bc823d3e960 100644 --- a/samples/client/petstore/swift5/urlsessionLibrary/PetstoreClient/Classes/OpenAPIs/Models/Pet.swift +++ b/samples/client/petstore/swift5/urlsessionLibrary/PetstoreClient/Classes/OpenAPIs/Models/Pet.swift @@ -7,7 +7,7 @@ import Foundation -public struct Pet: Codable { +public struct Pet: Codable, Hashable { public enum Status: String, Codable, CaseIterable { case available = "available"