add extension for hashable in swift5 (#7300)

This commit is contained in:
William Cheng 2020-08-26 19:29:29 +08:00 committed by GitHub
parent 98582d5780
commit 11a674f248
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 19 additions and 18 deletions

View File

@ -197,6 +197,7 @@ public class Swift5ClientCodegen extends DefaultCodegen implements CodegenConfig
typeMapping.put("array", "Array"); typeMapping.put("array", "Array");
typeMapping.put("List", "Array"); typeMapping.put("List", "Array");
typeMapping.put("map", "Dictionary"); typeMapping.put("map", "Dictionary");
typeMapping.put("set", "Set");
typeMapping.put("date", "Date"); typeMapping.put("date", "Date");
typeMapping.put("Date", "Date"); typeMapping.put("Date", "Date");
typeMapping.put("DateTime", "Date"); typeMapping.put("DateTime", "Date");

View File

@ -1,5 +1,9 @@
{{^objcCompatible}}{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} struct {{classname}}: Codable { {{/objcCompatible}} {{^objcCompatible}}
{{#objcCompatible}}@objc {{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} class {{classname}}: NSObject, Codable { {{/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}} {{#allVars}}
{{#isEnum}} {{#isEnum}}
@ -86,4 +90,4 @@
case {{name}}{{#vendorExtensions.x-codegen-escaped-property-name}} = "{{{baseName}}}"{{/vendorExtensions.x-codegen-escaped-property-name}}{{/allVars}} case {{name}}{{#vendorExtensions.x-codegen-escaped-property-name}} = "{{{baseName}}}"{{/vendorExtensions.x-codegen-escaped-property-name}}{{/allVars}}
} }
{{/vendorExtensions.x-codegen-has-escaped-property-names}}{{/additionalPropertiesType}} {{/vendorExtensions.x-codegen-has-escaped-property-names}}{{/additionalPropertiesType}}
} }

View File

@ -1134,6 +1134,7 @@ definitions:
xml: xml:
name: Tag name: Tag
Pet: Pet:
x-swift-hashable: true
type: object type: object
required: required:
- name - name

View File

@ -7,7 +7,7 @@
import Foundation import Foundation
public struct Pet: Codable { public struct Pet: Codable, Hashable {
public enum Status: String, Codable, CaseIterable { public enum Status: String, Codable, CaseIterable {
case available = "available" case available = "available"

View File

@ -7,7 +7,7 @@
import Foundation import Foundation
public struct Pet: Codable { public struct Pet: Codable, Hashable {
public enum Status: String, Codable, CaseIterable { public enum Status: String, Codable, CaseIterable {
case available = "available" case available = "available"

View File

@ -7,7 +7,7 @@
import Foundation import Foundation
public struct Pet: Codable { public struct Pet: Codable, Hashable {
public enum Status: String, Codable, CaseIterable { public enum Status: String, Codable, CaseIterable {
case available = "available" case available = "available"

View File

@ -7,7 +7,7 @@
import Foundation import Foundation
internal struct Pet: Codable { internal struct Pet: Codable, Hashable {
internal enum Status: String, Codable, CaseIterable { internal enum Status: String, Codable, CaseIterable {
case available = "available" case available = "available"

View File

@ -8,7 +8,6 @@
import Foundation import Foundation
/** Model for testing model with \"_class\" property */ /** Model for testing model with \"_class\" property */
@objc public class ClassModel: NSObject, Codable { @objc public class ClassModel: NSObject, Codable {
public var _class: String? public var _class: String?

View File

@ -8,7 +8,6 @@
import Foundation import Foundation
/** Must be named `File` for test. */ /** Must be named `File` for test. */
@objc public class File: NSObject, Codable { @objc public class File: NSObject, Codable {
/** Test capitalization */ /** Test capitalization */

View File

@ -8,7 +8,6 @@
import Foundation import Foundation
/** Model for testing model name starting with number */ /** Model for testing model name starting with number */
@objc public class Model200Response: NSObject, Codable { @objc public class Model200Response: NSObject, Codable {
public var name: Int? public var name: Int?

View File

@ -8,7 +8,6 @@
import Foundation import Foundation
/** Model for testing model name same as property name */ /** Model for testing model name same as property name */
@objc public class Name: NSObject, Codable { @objc public class Name: NSObject, Codable {
public var name: Int public var name: Int

View File

@ -7,7 +7,7 @@
import Foundation import Foundation
@objc public class Pet: NSObject, Codable { @objc public class Pet: NSObject, Codable, Hashable {
public enum Status: String, Codable, CaseIterable { public enum Status: String, Codable, CaseIterable {
case available = "available" case available = "available"

View File

@ -8,7 +8,6 @@
import Foundation import Foundation
/** Model for testing reserved words */ /** Model for testing reserved words */
@objc public class Return: NSObject, Codable { @objc public class Return: NSObject, Codable {
public var _return: Int? public var _return: Int?

View File

@ -7,7 +7,7 @@
import Foundation import Foundation
public struct Pet: Codable { public struct Pet: Codable, Hashable {
public enum Status: String, Codable, CaseIterable { public enum Status: String, Codable, CaseIterable {
case available = "available" case available = "available"

View File

@ -7,7 +7,7 @@
import Foundation import Foundation
public struct Pet: Codable { public struct Pet: Codable, Hashable {
public enum Status: String, Codable, CaseIterable { public enum Status: String, Codable, CaseIterable {
case available = "available" case available = "available"

View File

@ -7,7 +7,7 @@
import Foundation import Foundation
public struct Pet: Codable { public struct Pet: Codable, Hashable {
public enum Status: String, Codable, CaseIterable { public enum Status: String, Codable, CaseIterable {
case available = "available" case available = "available"

View File

@ -7,7 +7,7 @@
import Foundation import Foundation
public struct Pet: Codable { public struct Pet: Codable, Hashable {
public enum Status: String, Codable, CaseIterable { public enum Status: String, Codable, CaseIterable {
case available = "available" case available = "available"

View File

@ -7,7 +7,7 @@
import Foundation import Foundation
public struct Pet: Codable { public struct Pet: Codable, Hashable {
public enum Status: String, Codable, CaseIterable { public enum Status: String, Codable, CaseIterable {
case available = "available" case available = "available"