Skip to content

[Swift6] Remove ParameterConvertible for models #21150

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ extension UUID: ParameterConvertible {
func asParameter(codableHelper: CodableHelper) -> any Sendable { self }
}

extension RawRepresentable where RawValue: ParameterConvertible, RawValue: Sendable {
func asParameter(codableHelper: CodableHelper) -> any Sendable { return self.rawValue }
extension RawRepresentable where RawValue: ParameterConvertible {
func asParameter(codableHelper: CodableHelper) -> any Sendable {
rawValue.asParameter(codableHelper: codableHelper)
}
Comment on lines -54 to +57
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please explain this change?

}

private func encodeIfPossible<T: Sendable>(_ object: T, codableHelper: CodableHelper) -> any Sendable {
Expand Down Expand Up @@ -95,15 +97,6 @@ extension Date: ParameterConvertible {
func asParameter(codableHelper: CodableHelper) -> any Sendable {
return codableHelper.dateFormatter.string(from: self)
}
}

extension ParameterConvertible where Self: Encodable {
func asParameter(codableHelper: CodableHelper) -> any Sendable {
guard let data = try? codableHelper.jsonEncoder.encode(self) else {
fatalError("Could not encode to json: \(self)")
}
return data.asParameter(codableHelper: codableHelper)
Copy link
Contributor

@4brunu 4brunu Apr 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking, would it be wrong to just return the data here? Instead of removing this entire block?

}
}{{/useVapor}}{{#generateModelAdditionalProperties}}

extension String: @retroactive CodingKey {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{^objcCompatible}}{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} {{#useClasses}}final class{{/useClasses}}{{^useClasses}}struct{{/useClasses}} {{{classname}}}: {{^useClasses}}Sendable, {{/useClasses}}{{#useClasses}}{{#readonlyProperties}}@unchecked Sendable, {{/readonlyProperties}}{{/useClasses}}{{#useVapor}}Content{{/useVapor}}{{^useVapor}}Codable{{#useParameterConvertible}}, ParameterConvertible{{/useParameterConvertible}}{{/useVapor}}{{#vendorExtensions.x-swift-hashable}}, Hashable{{/vendorExtensions.x-swift-hashable}} {
{{/objcCompatible}}{{#objcCompatible}}@objcMembers {{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} class {{classname}}: NSObject, Codable{{#useParameterConvertible}}, ParameterConvertible{{/useParameterConvertible}} {
{{^objcCompatible}}{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} {{#useClasses}}final class{{/useClasses}}{{^useClasses}}struct{{/useClasses}} {{{classname}}}: {{^useClasses}}Sendable, {{/useClasses}}{{#useClasses}}{{#readonlyProperties}}@unchecked Sendable, {{/readonlyProperties}}{{/useClasses}}{{#useVapor}}Content{{/useVapor}}{{^useVapor}}Codable{{/useVapor}}{{#vendorExtensions.x-swift-hashable}}, Hashable{{/vendorExtensions.x-swift-hashable}} {
{{/objcCompatible}}{{#objcCompatible}}@objcMembers {{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} class {{classname}}: NSObject, Codable {
{{/objcCompatible}}

{{#allVars}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} enum {{classname}}: {{^useClasses}}Sendable, {{/useClasses}}{{#useClasses}}{{#readonlyProperties}}Sendable, {{/readonlyProperties}}{{/useClasses}}{{#useVapor}}Content{{/useVapor}}{{^useVapor}}Codable{{#useParameterConvertible}}, ParameterConvertible{{/useParameterConvertible}}{{#vendorExtensions.x-swift-hashable}}, Hashable{{/vendorExtensions.x-swift-hashable}}{{/useVapor}} {
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} enum {{classname}}: {{^useClasses}}Sendable, {{/useClasses}}{{#useClasses}}{{#readonlyProperties}}Sendable, {{/readonlyProperties}}{{/useClasses}}{{#useVapor}}Content{{/useVapor}}{{^useVapor}}Codable{{#vendorExtensions.x-swift-hashable}}, Hashable{{/vendorExtensions.x-swift-hashable}}{{/useVapor}} {
{{#oneOf}}
case type{{#transformArrayType}}{{.}}{{/transformArrayType}}({{.}})
{{/oneOf}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@ extension UUID: ParameterConvertible {
func asParameter(codableHelper: CodableHelper) -> any Sendable { self }
}

extension RawRepresentable where RawValue: ParameterConvertible, RawValue: Sendable {
func asParameter(codableHelper: CodableHelper) -> any Sendable { return self.rawValue }
extension RawRepresentable where RawValue: ParameterConvertible {
func asParameter(codableHelper: CodableHelper) -> any Sendable {
rawValue.asParameter(codableHelper: codableHelper)
}
}

private func encodeIfPossible<T: Sendable>(_ object: T, codableHelper: CodableHelper) -> any Sendable {
Expand Down Expand Up @@ -95,15 +97,6 @@ extension Date: ParameterConvertible {
}
}

extension ParameterConvertible where Self: Encodable {
func asParameter(codableHelper: CodableHelper) -> any Sendable {
guard let data = try? codableHelper.jsonEncoder.encode(self) else {
fatalError("Could not encode to json: \(self)")
}
return data.asParameter(codableHelper: codableHelper)
}
}

extension String: @retroactive CodingKey {

public var stringValue: String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

public struct AdditionalPropertiesClass: Sendable, Codable, ParameterConvertible, Hashable {
public struct AdditionalPropertiesClass: Sendable, Codable, Hashable {

public var mapString: [String: String]?
public var mapMapString: [String: [String: String]]?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

public struct Animal: Sendable, Codable, ParameterConvertible, Hashable {
public struct Animal: Sendable, Codable, Hashable {

public var className: String
public var color: String? = "red"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

public struct ApiResponse: Sendable, Codable, ParameterConvertible, Hashable {
public struct ApiResponse: Sendable, Codable, Hashable {

public var code: Int?
public var type: String?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

public struct ArrayOfArrayOfNumberOnly: Sendable, Codable, ParameterConvertible, Hashable {
public struct ArrayOfArrayOfNumberOnly: Sendable, Codable, Hashable {

public var arrayArrayNumber: [[Double]]?

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

public struct ArrayOfNumberOnly: Sendable, Codable, ParameterConvertible, Hashable {
public struct ArrayOfNumberOnly: Sendable, Codable, Hashable {

public var arrayNumber: [Double]?

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

public struct ArrayTest: Sendable, Codable, ParameterConvertible, Hashable {
public struct ArrayTest: Sendable, Codable, Hashable {

public var arrayOfString: [String]?
public var arrayArrayOfInteger: [[Int64]]?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

public struct Capitalization: Sendable, Codable, ParameterConvertible, Hashable {
public struct Capitalization: Sendable, Codable, Hashable {

public var smallCamel: String?
public var capitalCamel: String?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

public struct Cat: Sendable, Codable, ParameterConvertible, Hashable {
public struct Cat: Sendable, Codable, Hashable {

public var className: String
public var color: String? = "red"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

public struct Category: Sendable, Codable, ParameterConvertible, Hashable {
public struct Category: Sendable, Codable, Hashable {

public var id: Int64?
public var name: String? = "default-name"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import Foundation

/** Model for testing model with \&quot;_class\&quot; property */
public struct ClassModel: Sendable, Codable, ParameterConvertible, Hashable {
public struct ClassModel: Sendable, Codable, Hashable {

public var _class: String?

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

public struct Client: Sendable, Codable, ParameterConvertible, Hashable {
public struct Client: Sendable, Codable, Hashable {

public var client: String?

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

public struct Dog: Sendable, Codable, ParameterConvertible, Hashable {
public struct Dog: Sendable, Codable, Hashable {

public var className: String
public var color: String? = "red"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

public struct EnumArrays: Sendable, Codable, ParameterConvertible, Hashable {
public struct EnumArrays: Sendable, Codable, Hashable {

public enum JustSymbol: String, Sendable, Codable, CaseIterable {
case greaterThanOrEqualTo = ">="
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

public struct EnumTest: Sendable, Codable, ParameterConvertible, Hashable {
public struct EnumTest: Sendable, Codable, Hashable {

public enum EnumString: String, Sendable, Codable, CaseIterable {
case upper = "UPPER"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import Foundation

/** Must be named &#x60;File&#x60; for test. */
public struct File: Sendable, Codable, ParameterConvertible, Hashable {
public struct File: Sendable, Codable, Hashable {

/** Test capitalization */
public var sourceURI: String?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

public struct FileSchemaTestClass: Sendable, Codable, ParameterConvertible, Hashable {
public struct FileSchemaTestClass: Sendable, Codable, Hashable {

public var file: File?
public var files: [File]?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

public struct FormatTest: Sendable, Codable, ParameterConvertible, Hashable {
public struct FormatTest: Sendable, Codable, Hashable {

public static let integerRule = NumericRule<Int>(minimum: 10, exclusiveMinimum: false, maximum: 100, exclusiveMaximum: false, multipleOf: nil)
public static let int32Rule = NumericRule<Int>(minimum: 20, exclusiveMinimum: false, maximum: 200, exclusiveMaximum: false, multipleOf: nil)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

public struct HasOnlyReadOnly: Sendable, Codable, ParameterConvertible, Hashable {
public struct HasOnlyReadOnly: Sendable, Codable, Hashable {

public var bar: String?
public var foo: String?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

public struct List: Sendable, Codable, ParameterConvertible, Hashable {
public struct List: Sendable, Codable, Hashable {

public var _123list: String?

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

public struct MapTest: Sendable, Codable, ParameterConvertible, Hashable {
public struct MapTest: Sendable, Codable, Hashable {

public enum MapOfEnumString: String, Sendable, Codable, CaseIterable {
case upper = "UPPER"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

public struct MixedPropertiesAndAdditionalPropertiesClass: Sendable, Codable, ParameterConvertible, Hashable {
public struct MixedPropertiesAndAdditionalPropertiesClass: Sendable, Codable, Hashable {

public var uuid: UUID?
public var dateTime: Date?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import Foundation

/** Model for testing model name starting with number */
public struct Model200Response: Sendable, Codable, ParameterConvertible, Hashable {
public struct Model200Response: Sendable, Codable, Hashable {

public var name: Int?
public var _class: String?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import Foundation

/** Model for testing model name same as property name */
public struct Name: Sendable, Codable, ParameterConvertible, Hashable {
public struct Name: Sendable, Codable, Hashable {

public var name: Int
public var snakeCase: NullEncodable<Int> = .encodeValue(11033)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

public struct NumberOnly: Sendable, Codable, ParameterConvertible, Hashable {
public struct NumberOnly: Sendable, Codable, Hashable {

public var justNumber: Double?

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

public struct Order: Sendable, Codable, ParameterConvertible, Hashable {
public struct Order: Sendable, Codable, Hashable {

public enum Status: String, Sendable, Codable, CaseIterable {
case placed = "placed"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

public struct OuterComposite: Sendable, Codable, ParameterConvertible, Hashable {
public struct OuterComposite: Sendable, Codable, Hashable {

public var myNumber: Double?
public var myString: String?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

public struct Pet: Sendable, Codable, ParameterConvertible, Hashable {
public struct Pet: Sendable, Codable, Hashable {

public enum Status: String, Sendable, Codable, CaseIterable {
case available = "available"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

public struct ReadOnlyFirst: Sendable, Codable, ParameterConvertible, Hashable {
public struct ReadOnlyFirst: Sendable, Codable, Hashable {

public var bar: String?
public var baz: String?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import Foundation

/** Model for testing reserved words */
public struct Return: Sendable, Codable, ParameterConvertible, Hashable {
public struct Return: Sendable, Codable, Hashable {

public var _return: Int?

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

public struct SpecialModelName: Sendable, Codable, ParameterConvertible, Hashable {
public struct SpecialModelName: Sendable, Codable, Hashable {

public var specialPropertyName: Int64?

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

public struct StringBooleanMap: Sendable, Codable, ParameterConvertible, Hashable {
public struct StringBooleanMap: Sendable, Codable, Hashable {


public enum CodingKeys: CodingKey, CaseIterable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

public struct Tag: Sendable, Codable, ParameterConvertible, Hashable {
public struct Tag: Sendable, Codable, Hashable {

public var id: Int64?
public var name: String?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

public struct TypeHolderDefault: Sendable, Codable, ParameterConvertible, Hashable {
public struct TypeHolderDefault: Sendable, Codable, Hashable {

public var stringItem: String = "what"
public var numberItem: Double
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

public struct TypeHolderExample: Sendable, Codable, ParameterConvertible, Hashable {
public struct TypeHolderExample: Sendable, Codable, Hashable {

public var stringItem: String
public var numberItem: Double
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

public struct User: Sendable, Codable, ParameterConvertible, Hashable {
public struct User: Sendable, Codable, Hashable {

public var id: Int64?
public var username: String?
Expand Down
Loading
Loading