[swift][client] make QueryStringEncodable return any Sendable (#21142)

* [swift][client] make QueryStringEncodable return any Sendable

* [swift][client] rename QueryStringEncodable to ParameterConvertible

* [swift][client] update migration docs

* Revert "[swift][client] update migration docs"

This reverts commit 00a490536df393c4075e3e739b2e33446f614988.

* [swift][client] rename QueryStringEncodable to ParameterConvertible
This commit is contained in:
Bruno Coelho 2025-04-25 14:40:58 +01:00 committed by GitHub
parent 44c342bddd
commit f950ac97e8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
472 changed files with 1499 additions and 1569 deletions

View File

@ -56,7 +56,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|useBacktickEscapes|Escape reserved words using backticks (default: false)| |false|
|useClasses|Use final classes for models instead of structs (default: false)| |false|
|useCustomDateWithoutTime|Uses a custom type to decode and encode dates without time information to support OpenAPIs date format (default: false)| |false|
|useJsonEncodable|Make models conform to JSONEncodable protocol (default: true)| |true|
|useParameterConvertible|Make models conform to ParameterConvertible protocol (default: true)| |true|
|useSPMFileStructure|Use SPM file structure and set the source path to Sources/{{projectName}} (default: true).| |null|
|validatable|Make validation rules and validator for model properties (default: true)| |true|

View File

@ -72,7 +72,7 @@ public class Swift6ClientCodegen extends DefaultCodegen implements CodegenConfig
public static final String GENERATE_MODEL_ADDITIONAL_PROPERTIES = "generateModelAdditionalProperties";
public static final String HASHABLE_MODELS = "hashableModels";
public static final String IDENTIFIABLE_MODELS = "identifiableModels";
public static final String USE_JSON_ENCODABLE = "useJsonEncodable";
public static final String USE_PARAMETER_CONVERTIBLE = "useParameterConvertible";
public static final String MAP_FILE_BINARY_TO_DATA = "mapFileBinaryToData";
public static final String USE_CUSTOM_DATE_WITHOUT_TIME = "useCustomDateWithoutTime";
public static final String VALIDATABLE = "validatable";
@ -115,7 +115,7 @@ public class Swift6ClientCodegen extends DefaultCodegen implements CodegenConfig
@Setter
protected boolean identifiableModels = true;
@Setter
protected boolean useJsonEncodable = true;
protected boolean useParameterConvertible = true;
@Getter
@Setter
protected boolean mapFileBinaryToData = false;
@ -335,8 +335,8 @@ public class Swift6ClientCodegen extends DefaultCodegen implements CodegenConfig
"Make models conform to Identifiable when an id is present (default: true)")
.defaultValue(Boolean.TRUE.toString()));
cliOptions.add(new CliOption(USE_JSON_ENCODABLE,
"Make models conform to JSONEncodable protocol (default: true)")
cliOptions.add(new CliOption(USE_PARAMETER_CONVERTIBLE,
"Make models conform to ParameterConvertible protocol (default: true)")
.defaultValue(Boolean.TRUE.toString()));
cliOptions.add(new CliOption(MAP_FILE_BINARY_TO_DATA,
@ -560,10 +560,10 @@ public class Swift6ClientCodegen extends DefaultCodegen implements CodegenConfig
}
additionalProperties.put(IDENTIFIABLE_MODELS, identifiableModels);
if (additionalProperties.containsKey(USE_JSON_ENCODABLE)) {
setUseJsonEncodable(convertPropertyToBooleanAndWriteBack(USE_JSON_ENCODABLE));
if (additionalProperties.containsKey(USE_PARAMETER_CONVERTIBLE)) {
setUseParameterConvertible(convertPropertyToBooleanAndWriteBack(USE_PARAMETER_CONVERTIBLE));
}
additionalProperties.put(USE_JSON_ENCODABLE, useJsonEncodable);
additionalProperties.put(USE_PARAMETER_CONVERTIBLE, useParameterConvertible);
if (additionalProperties.containsKey(MAP_FILE_BINARY_TO_DATA)) {
setMapFileBinaryToData(convertPropertyToBooleanAndWriteBack(MAP_FILE_BINARY_TO_DATA));

View File

@ -11,78 +11,73 @@ import FoundationNetworking
@preconcurrency import PromiseKit{{/usePromiseKit}}{{#useVapor}}
import Vapor{{/useVapor}}{{^useVapor}}
extension QueryStringEncodable {
@_disfavoredOverload
func encodeToQueryString(codableHelper: CodableHelper) -> String { String(describing: self) }
extension Bool: ParameterConvertible {
func asParameter(codableHelper: CodableHelper) -> any Sendable { self }
}
extension Bool: QueryStringEncodable {
func encodeToQueryString(codableHelper: CodableHelper) -> String { String(describing: self) }
extension Float: ParameterConvertible {
func asParameter(codableHelper: CodableHelper) -> any Sendable { self }
}
extension Float: QueryStringEncodable {
func encodeToQueryString(codableHelper: CodableHelper) -> String { String(describing: self) }
extension Int: ParameterConvertible {
func asParameter(codableHelper: CodableHelper) -> any Sendable { self }
}
extension Int: QueryStringEncodable {
func encodeToQueryString(codableHelper: CodableHelper) -> String { String(describing: self) }
extension Int32: ParameterConvertible {
func asParameter(codableHelper: CodableHelper) -> any Sendable { self }
}
extension Int32: QueryStringEncodable {
func encodeToQueryString(codableHelper: CodableHelper) -> String { String(describing: self) }
extension Int64: ParameterConvertible {
func asParameter(codableHelper: CodableHelper) -> any Sendable { self }
}
extension Int64: QueryStringEncodable {
func encodeToQueryString(codableHelper: CodableHelper) -> String { String(describing: self) }
extension Double: ParameterConvertible {
func asParameter(codableHelper: CodableHelper) -> any Sendable { self }
}
extension Double: QueryStringEncodable {
func encodeToQueryString(codableHelper: CodableHelper) -> String { String(describing: self) }
extension Decimal: ParameterConvertible {
func asParameter(codableHelper: CodableHelper) -> any Sendable { self }
}
extension Decimal: QueryStringEncodable {
func encodeToQueryString(codableHelper: CodableHelper) -> String { String(describing: self) }
extension String: ParameterConvertible {
func asParameter(codableHelper: CodableHelper) -> any Sendable { self }
}
extension String: QueryStringEncodable {
func encodeToQueryString(codableHelper: CodableHelper) -> String { String(describing: self) }
extension URL: ParameterConvertible {
func asParameter(codableHelper: CodableHelper) -> any Sendable { self }
}
extension URL: QueryStringEncodable {
func encodeToQueryString(codableHelper: CodableHelper) -> String { String(describing: self) }
extension UUID: ParameterConvertible {
func asParameter(codableHelper: CodableHelper) -> any Sendable { self }
}
extension UUID: QueryStringEncodable {
func encodeToQueryString(codableHelper: CodableHelper) -> String { String(describing: self) }
extension RawRepresentable where RawValue: ParameterConvertible, RawValue: Sendable {
func asParameter(codableHelper: CodableHelper) -> any Sendable { return self.rawValue }
}
extension RawRepresentable where RawValue: QueryStringEncodable {
func encodeToQueryString(codableHelper: CodableHelper) -> String { String(describing: rawValue) }
}
private func encodeIfPossible<T>(_ object: T, codableHelper: CodableHelper) -> String {
if let encodableObject = object as? QueryStringEncodable {
return encodableObject.encodeToQueryString(codableHelper: codableHelper)
private func encodeIfPossible<T: Sendable>(_ object: T, codableHelper: CodableHelper) -> any Sendable {
if let encodableObject = object as? ParameterConvertible {
return encodableObject.asParameter(codableHelper: codableHelper)
} else {
return String(describing: object)
return object
}
}
extension Array {
func encodeToQueryString(codableHelper: CodableHelper) -> [String] {
extension Array where Element: Sendable {
func asParameter(codableHelper: CodableHelper) -> any Sendable {
return self.map { encodeIfPossible($0, codableHelper: codableHelper) }
}
}
extension Set {
func encodeToQueryString(codableHelper: CodableHelper) -> [String] {
return Array(self).encodeToQueryString(codableHelper: codableHelper)
extension Set where Element: Sendable {
func asParameter(codableHelper: CodableHelper) -> any Sendable {
return Array(self).asParameter(codableHelper: codableHelper)
}
}
extension Dictionary {
func encodeToQueryString(codableHelper: CodableHelper) -> [Key: String] {
var dictionary = [Key: String]()
extension Dictionary where Key: Sendable, Value: Sendable {
func asParameter(codableHelper: CodableHelper) -> any Sendable {
var dictionary = [Key: any Sendable]()
for (key, value) in self {
dictionary[key] = encodeIfPossible(value, codableHelper: codableHelper)
}
@ -90,24 +85,24 @@ extension Dictionary {
}
}
extension Data: QueryStringEncodable {
func encodeToQueryString(codableHelper: CodableHelper) -> String {
extension Data: ParameterConvertible {
func asParameter(codableHelper: CodableHelper) -> any Sendable {
return self.base64EncodedString(options: Data.Base64EncodingOptions())
}
}
extension Date: QueryStringEncodable {
func encodeToQueryString(codableHelper: CodableHelper) -> String {
extension Date: ParameterConvertible {
func asParameter(codableHelper: CodableHelper) -> any Sendable {
return codableHelper.dateFormatter.string(from: self)
}
}
extension QueryStringEncodable where Self: Encodable {
func encodeToQueryString(codableHelper: CodableHelper) -> String {
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.encodeToQueryString(codableHelper: codableHelper)
return data.asParameter(codableHelper: codableHelper)
}
}{{/useVapor}}{{#generateModelAdditionalProperties}}

View File

@ -10,8 +10,8 @@ import FoundationNetworking
#endif{{#useAlamofire}}
import Alamofire{{/useAlamofire}}
protocol QueryStringEncodable {
func encodeToQueryString(codableHelper: CodableHelper) -> String
protocol ParameterConvertible {
func asParameter(codableHelper: CodableHelper) -> any Sendable
}
/// An enum where the last case value can be used as a default catch-all.

View File

@ -76,8 +76,8 @@ import Foundation
}
}
extension OpenAPIDateWithoutTime: QueryStringEncodable {
func encodeToQueryString(codableHelper: CodableHelper) -> String {
extension OpenAPIDateWithoutTime: ParameterConvertible {
func asParameter(codableHelper: CodableHelper) -> any Sendable {
return OpenISO8601DateFormatter.withoutTime.string(from: self.normalizedWrappedDate())
}
}

View File

@ -1 +1 @@
"{{baseName}}": {{#isQueryParam}}(wrappedValue: {{/isQueryParam}}{{paramName}}{{^required}}?{{/required}}.encodeToQueryString(codableHelper: apiConfiguration.codableHelper){{#isQueryParam}}, isExplode: {{isExplode}}){{/isQueryParam}}
"{{baseName}}": {{#isQueryParam}}(wrappedValue: {{/isQueryParam}}{{paramName}}{{^required}}?{{/required}}.asParameter(codableHelper: apiConfiguration.codableHelper){{#isQueryParam}}, isExplode: {{isExplode}}){{/isQueryParam}}

View File

@ -1,4 +1,4 @@
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} enum {{classname}}: {{dataType}}, Sendable, {{#useVapor}}Content, Hashable{{/useVapor}}{{^useVapor}}Codable{{^isString}}{{^isInteger}}{{^isFloat}}{{^isDouble}}{{#useJsonEncodable}}, QueryStringEncodable{{/useJsonEncodable}}{{/isDouble}}{{/isFloat}}{{/isInteger}}{{/isString}}{{/useVapor}}, CaseIterable{{#enumUnknownDefaultCase}}{{#isInteger}}, CaseIterableDefaultsLast{{/isInteger}}{{#isFloat}}, CaseIterableDefaultsLast{{/isFloat}}{{#isDouble}}, CaseIterableDefaultsLast{{/isDouble}}{{#isString}}, CaseIterableDefaultsLast{{/isString}}{{/enumUnknownDefaultCase}} {
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} enum {{classname}}: {{dataType}}, Sendable, {{#useVapor}}Content, Hashable{{/useVapor}}{{^useVapor}}Codable{{^isString}}{{^isInteger}}{{^isFloat}}{{^isDouble}}{{#useParameterConvertible}}, ParameterConvertible{{/useParameterConvertible}}{{/isDouble}}{{/isFloat}}{{/isInteger}}{{/isString}}{{/useVapor}}, CaseIterable{{#enumUnknownDefaultCase}}{{#isInteger}}, CaseIterableDefaultsLast{{/isInteger}}{{#isFloat}}, CaseIterableDefaultsLast{{/isFloat}}{{#isDouble}}, CaseIterableDefaultsLast{{/isDouble}}{{#isString}}, CaseIterableDefaultsLast{{/isString}}{{/enumUnknownDefaultCase}} {
{{#allowableValues}}
{{#enumVars}}
case {{{name}}} = {{{value}}}

View File

@ -1,4 +1,4 @@
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} enum {{enumName}}: {{^isContainer}}{{dataType}}{{/isContainer}}{{#isContainer}}String{{/isContainer}}, Sendable, {{#useVapor}}Content, Hashable{{/useVapor}}{{^useVapor}}Codable{{^isContainer}}{{^isString}}{{^isInteger}}{{^isFloat}}{{^isDouble}}{{#useJsonEncodable}}, QueryStringEncodable{{/useJsonEncodable}}{{/isDouble}}{{/isFloat}}{{/isInteger}}{{/isString}}{{/isContainer}}{{/useVapor}}, CaseIterable{{#enumUnknownDefaultCase}}{{#isInteger}}, CaseIterableDefaultsLast{{/isInteger}}{{#isFloat}}, CaseIterableDefaultsLast{{/isFloat}}{{#isDouble}}, CaseIterableDefaultsLast{{/isDouble}}{{#isString}}, CaseIterableDefaultsLast{{/isString}}{{#isContainer}}, CaseIterableDefaultsLast{{/isContainer}}{{/enumUnknownDefaultCase}} {
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} enum {{enumName}}: {{^isContainer}}{{dataType}}{{/isContainer}}{{#isContainer}}String{{/isContainer}}, Sendable, {{#useVapor}}Content, Hashable{{/useVapor}}{{^useVapor}}Codable{{^isContainer}}{{^isString}}{{^isInteger}}{{^isFloat}}{{^isDouble}}{{#useParameterConvertible}}, ParameterConvertible{{/useParameterConvertible}}{{/isDouble}}{{/isFloat}}{{/isInteger}}{{/isString}}{{/isContainer}}{{/useVapor}}, CaseIterable{{#enumUnknownDefaultCase}}{{#isInteger}}, CaseIterableDefaultsLast{{/isInteger}}{{#isFloat}}, CaseIterableDefaultsLast{{/isFloat}}{{#isDouble}}, CaseIterableDefaultsLast{{/isDouble}}{{#isString}}, CaseIterableDefaultsLast{{/isString}}{{#isContainer}}, CaseIterableDefaultsLast{{/isContainer}}{{/enumUnknownDefaultCase}} {
{{#allowableValues}}
{{#enumVars}}
case {{{name}}} = {{{value}}}

View File

@ -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{{#useJsonEncodable}}, QueryStringEncodable{{/useJsonEncodable}}{{/useVapor}}{{#vendorExtensions.x-swift-hashable}}, Hashable{{/vendorExtensions.x-swift-hashable}} {
{{/objcCompatible}}{{#objcCompatible}}@objcMembers {{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} class {{classname}}: NSObject, Codable{{#useJsonEncodable}}, QueryStringEncodable{{/useJsonEncodable}} {
{{^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}}
{{#allVars}}

View File

@ -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{{#useJsonEncodable}}, QueryStringEncodable{{/useJsonEncodable}}{{#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{{#useParameterConvertible}}, ParameterConvertible{{/useParameterConvertible}}{{#vendorExtensions.x-swift-hashable}}, Hashable{{/vendorExtensions.x-swift-hashable}}{{/useVapor}} {
{{#oneOf}}
case type{{#transformArrayType}}{{.}}{{/transformArrayType}}({{.}})
{{/oneOf}}

View File

@ -48,7 +48,7 @@ public class Swift6ClientCodegenOptionsProvider implements OptionsProvider {
public static final String GENERATE_MODEL_ADDITIONAL_PROPERTIES_VALUE = "true";
public static final String HASHABLE_MODELS_VALUE = "true";
public static final String IDENTIFIABLE_MODELS_VALUE = "true";
public static final String USE_JSON_ENCODABLE_VALUE = "true";
public static final String USE_PARAMETER_CONVERTIBLE_VALUE = "true";
public static final String ALLOW_UNICODE_IDENTIFIERS_VALUE = "false";
public static final String PREPEND_FORM_OR_BODY_PARAMETERS_VALUE = "true";
public static final String LIBRARY_VALUE = "alamofire";
@ -99,7 +99,7 @@ public class Swift6ClientCodegenOptionsProvider implements OptionsProvider {
GENERATE_MODEL_ADDITIONAL_PROPERTIES_VALUE)
.put(Swift6ClientCodegen.HASHABLE_MODELS, HASHABLE_MODELS_VALUE)
.put(Swift6ClientCodegen.IDENTIFIABLE_MODELS, IDENTIFIABLE_MODELS_VALUE)
.put(Swift6ClientCodegen.USE_JSON_ENCODABLE, USE_JSON_ENCODABLE_VALUE)
.put(Swift6ClientCodegen.USE_PARAMETER_CONVERTIBLE, USE_PARAMETER_CONVERTIBLE_VALUE)
.put(Swift6ClientCodegen.MAP_FILE_BINARY_TO_DATA, "false")
.put(Swift6ClientCodegen.USE_CUSTOM_DATE_WITHOUT_TIME, "false")
.put(Swift6ClientCodegen.VALIDATABLE, "true")

View File

@ -257,7 +257,7 @@ open class FakeAPI {
var localVariableUrlComponents = URLComponents(string: localVariableURLString)
localVariableUrlComponents?.queryItems = APIHelper.mapValuesToQueryItems([
"query": (wrappedValue: query.encodeToQueryString(codableHelper: apiConfiguration.codableHelper), isExplode: false),
"query": (wrappedValue: query.asParameter(codableHelper: apiConfiguration.codableHelper), isExplode: false),
])
let localVariableNillableHeaders: [String: (any Sendable)?] = [
@ -376,20 +376,20 @@ open class FakeAPI {
let localVariablePath = "/fake"
let localVariableURLString = apiConfiguration.basePath + localVariablePath
let localVariableFormParams: [String: (any Sendable)?] = [
"integer": integer?.encodeToQueryString(codableHelper: apiConfiguration.codableHelper),
"int32": int32?.encodeToQueryString(codableHelper: apiConfiguration.codableHelper),
"int64": int64?.encodeToQueryString(codableHelper: apiConfiguration.codableHelper),
"number": number.encodeToQueryString(codableHelper: apiConfiguration.codableHelper),
"float": float?.encodeToQueryString(codableHelper: apiConfiguration.codableHelper),
"double": double.encodeToQueryString(codableHelper: apiConfiguration.codableHelper),
"string": string?.encodeToQueryString(codableHelper: apiConfiguration.codableHelper),
"pattern_without_delimiter": patternWithoutDelimiter.encodeToQueryString(codableHelper: apiConfiguration.codableHelper),
"byte": byte.encodeToQueryString(codableHelper: apiConfiguration.codableHelper),
"binary": binary?.encodeToQueryString(codableHelper: apiConfiguration.codableHelper),
"date": date?.encodeToQueryString(codableHelper: apiConfiguration.codableHelper),
"dateTime": dateTime?.encodeToQueryString(codableHelper: apiConfiguration.codableHelper),
"password": password?.encodeToQueryString(codableHelper: apiConfiguration.codableHelper),
"callback": callback?.encodeToQueryString(codableHelper: apiConfiguration.codableHelper),
"integer": integer?.asParameter(codableHelper: apiConfiguration.codableHelper),
"int32": int32?.asParameter(codableHelper: apiConfiguration.codableHelper),
"int64": int64?.asParameter(codableHelper: apiConfiguration.codableHelper),
"number": number.asParameter(codableHelper: apiConfiguration.codableHelper),
"float": float?.asParameter(codableHelper: apiConfiguration.codableHelper),
"double": double.asParameter(codableHelper: apiConfiguration.codableHelper),
"string": string?.asParameter(codableHelper: apiConfiguration.codableHelper),
"pattern_without_delimiter": patternWithoutDelimiter.asParameter(codableHelper: apiConfiguration.codableHelper),
"byte": byte.asParameter(codableHelper: apiConfiguration.codableHelper),
"binary": binary?.asParameter(codableHelper: apiConfiguration.codableHelper),
"date": date?.asParameter(codableHelper: apiConfiguration.codableHelper),
"dateTime": dateTime?.asParameter(codableHelper: apiConfiguration.codableHelper),
"password": password?.asParameter(codableHelper: apiConfiguration.codableHelper),
"callback": callback?.asParameter(codableHelper: apiConfiguration.codableHelper),
]
let localVariableNonNullParameters = APIHelper.rejectNil(localVariableFormParams)
@ -520,8 +520,8 @@ open class FakeAPI {
let localVariablePath = "/fake"
let localVariableURLString = apiConfiguration.basePath + localVariablePath
let localVariableFormParams: [String: (any Sendable)?] = [
"enum_form_string_array": enumFormStringArray?.encodeToQueryString(codableHelper: apiConfiguration.codableHelper),
"enum_form_string": enumFormString?.encodeToQueryString(codableHelper: apiConfiguration.codableHelper),
"enum_form_string_array": enumFormStringArray?.asParameter(codableHelper: apiConfiguration.codableHelper),
"enum_form_string": enumFormString?.asParameter(codableHelper: apiConfiguration.codableHelper),
]
let localVariableNonNullParameters = APIHelper.rejectNil(localVariableFormParams)
@ -529,16 +529,16 @@ open class FakeAPI {
var localVariableUrlComponents = URLComponents(string: localVariableURLString)
localVariableUrlComponents?.queryItems = APIHelper.mapValuesToQueryItems([
"enum_query_string_array": (wrappedValue: enumQueryStringArray?.encodeToQueryString(codableHelper: apiConfiguration.codableHelper), isExplode: false),
"enum_query_string": (wrappedValue: enumQueryString?.encodeToQueryString(codableHelper: apiConfiguration.codableHelper), isExplode: false),
"enum_query_integer": (wrappedValue: enumQueryInteger?.encodeToQueryString(codableHelper: apiConfiguration.codableHelper), isExplode: false),
"enum_query_double": (wrappedValue: enumQueryDouble?.encodeToQueryString(codableHelper: apiConfiguration.codableHelper), isExplode: false),
"enum_query_string_array": (wrappedValue: enumQueryStringArray?.asParameter(codableHelper: apiConfiguration.codableHelper), isExplode: false),
"enum_query_string": (wrappedValue: enumQueryString?.asParameter(codableHelper: apiConfiguration.codableHelper), isExplode: false),
"enum_query_integer": (wrappedValue: enumQueryInteger?.asParameter(codableHelper: apiConfiguration.codableHelper), isExplode: false),
"enum_query_double": (wrappedValue: enumQueryDouble?.asParameter(codableHelper: apiConfiguration.codableHelper), isExplode: false),
])
let localVariableNillableHeaders: [String: (any Sendable)?] = [
"Content-Type": "application/x-www-form-urlencoded",
"enum_header_string_array": enumHeaderStringArray?.encodeToQueryString(codableHelper: apiConfiguration.codableHelper),
"enum_header_string": enumHeaderString?.encodeToQueryString(codableHelper: apiConfiguration.codableHelper),
"enum_header_string_array": enumHeaderStringArray?.asParameter(codableHelper: apiConfiguration.codableHelper),
"enum_header_string": enumHeaderString?.asParameter(codableHelper: apiConfiguration.codableHelper),
]
let localVariableHeaderParameters = APIHelper.rejectNilHeaders(localVariableNillableHeaders)
@ -592,15 +592,15 @@ open class FakeAPI {
var localVariableUrlComponents = URLComponents(string: localVariableURLString)
localVariableUrlComponents?.queryItems = APIHelper.mapValuesToQueryItems([
"required_string_group": (wrappedValue: requiredStringGroup.encodeToQueryString(codableHelper: apiConfiguration.codableHelper), isExplode: false),
"required_int64_group": (wrappedValue: requiredInt64Group.encodeToQueryString(codableHelper: apiConfiguration.codableHelper), isExplode: false),
"string_group": (wrappedValue: stringGroup?.encodeToQueryString(codableHelper: apiConfiguration.codableHelper), isExplode: false),
"int64_group": (wrappedValue: int64Group?.encodeToQueryString(codableHelper: apiConfiguration.codableHelper), isExplode: false),
"required_string_group": (wrappedValue: requiredStringGroup.asParameter(codableHelper: apiConfiguration.codableHelper), isExplode: false),
"required_int64_group": (wrappedValue: requiredInt64Group.asParameter(codableHelper: apiConfiguration.codableHelper), isExplode: false),
"string_group": (wrappedValue: stringGroup?.asParameter(codableHelper: apiConfiguration.codableHelper), isExplode: false),
"int64_group": (wrappedValue: int64Group?.asParameter(codableHelper: apiConfiguration.codableHelper), isExplode: false),
])
let localVariableNillableHeaders: [String: (any Sendable)?] = [
"required_boolean_group": requiredBooleanGroup.encodeToQueryString(codableHelper: apiConfiguration.codableHelper),
"boolean_group": booleanGroup?.encodeToQueryString(codableHelper: apiConfiguration.codableHelper),
"required_boolean_group": requiredBooleanGroup.asParameter(codableHelper: apiConfiguration.codableHelper),
"boolean_group": booleanGroup?.asParameter(codableHelper: apiConfiguration.codableHelper),
]
let localVariableHeaderParameters = APIHelper.rejectNilHeaders(localVariableNillableHeaders)
@ -686,8 +686,8 @@ open class FakeAPI {
let localVariablePath = "/fake/jsonFormData"
let localVariableURLString = apiConfiguration.basePath + localVariablePath
let localVariableFormParams: [String: (any Sendable)?] = [
"param": param.encodeToQueryString(codableHelper: apiConfiguration.codableHelper),
"param2": param2.encodeToQueryString(codableHelper: apiConfiguration.codableHelper),
"param": param.asParameter(codableHelper: apiConfiguration.codableHelper),
"param2": param2.asParameter(codableHelper: apiConfiguration.codableHelper),
]
let localVariableNonNullParameters = APIHelper.rejectNil(localVariableFormParams)

View File

@ -101,7 +101,7 @@ open class PetAPI {
let localVariableUrlComponents = URLComponents(string: localVariableURLString)
let localVariableNillableHeaders: [String: (any Sendable)?] = [
"api_key": apiKey?.encodeToQueryString(codableHelper: apiConfiguration.codableHelper),
"api_key": apiKey?.asParameter(codableHelper: apiConfiguration.codableHelper),
]
let localVariableHeaderParameters = APIHelper.rejectNilHeaders(localVariableNillableHeaders)
@ -157,7 +157,7 @@ open class PetAPI {
var localVariableUrlComponents = URLComponents(string: localVariableURLString)
localVariableUrlComponents?.queryItems = APIHelper.mapValuesToQueryItems([
"status": (wrappedValue: status.encodeToQueryString(codableHelper: apiConfiguration.codableHelper), isExplode: false),
"status": (wrappedValue: status.asParameter(codableHelper: apiConfiguration.codableHelper), isExplode: false),
])
let localVariableNillableHeaders: [String: (any Sendable)?] = [
@ -210,7 +210,7 @@ open class PetAPI {
var localVariableUrlComponents = URLComponents(string: localVariableURLString)
localVariableUrlComponents?.queryItems = APIHelper.mapValuesToQueryItems([
"tags": (wrappedValue: tags.encodeToQueryString(codableHelper: apiConfiguration.codableHelper), isExplode: false),
"tags": (wrappedValue: tags.asParameter(codableHelper: apiConfiguration.codableHelper), isExplode: false),
])
let localVariableNillableHeaders: [String: (any Sendable)?] = [
@ -362,8 +362,8 @@ open class PetAPI {
localVariablePath = localVariablePath.replacingOccurrences(of: "{petId}", with: petIdPostEscape, options: .literal, range: nil)
let localVariableURLString = apiConfiguration.basePath + localVariablePath
let localVariableFormParams: [String: (any Sendable)?] = [
"name": name?.encodeToQueryString(codableHelper: apiConfiguration.codableHelper),
"status": status?.encodeToQueryString(codableHelper: apiConfiguration.codableHelper),
"name": name?.asParameter(codableHelper: apiConfiguration.codableHelper),
"status": status?.asParameter(codableHelper: apiConfiguration.codableHelper),
]
let localVariableNonNullParameters = APIHelper.rejectNil(localVariableFormParams)
@ -422,8 +422,8 @@ open class PetAPI {
localVariablePath = localVariablePath.replacingOccurrences(of: "{petId}", with: petIdPostEscape, options: .literal, range: nil)
let localVariableURLString = apiConfiguration.basePath + localVariablePath
let localVariableFormParams: [String: (any Sendable)?] = [
"additionalMetadata": additionalMetadata?.encodeToQueryString(codableHelper: apiConfiguration.codableHelper),
"file": file?.encodeToQueryString(codableHelper: apiConfiguration.codableHelper),
"additionalMetadata": additionalMetadata?.asParameter(codableHelper: apiConfiguration.codableHelper),
"file": file?.asParameter(codableHelper: apiConfiguration.codableHelper),
]
let localVariableNonNullParameters = APIHelper.rejectNil(localVariableFormParams)
@ -482,8 +482,8 @@ open class PetAPI {
localVariablePath = localVariablePath.replacingOccurrences(of: "{petId}", with: petIdPostEscape, options: .literal, range: nil)
let localVariableURLString = apiConfiguration.basePath + localVariablePath
let localVariableFormParams: [String: (any Sendable)?] = [
"additionalMetadata": additionalMetadata?.encodeToQueryString(codableHelper: apiConfiguration.codableHelper),
"requiredFile": requiredFile.encodeToQueryString(codableHelper: apiConfiguration.codableHelper),
"additionalMetadata": additionalMetadata?.asParameter(codableHelper: apiConfiguration.codableHelper),
"requiredFile": requiredFile.asParameter(codableHelper: apiConfiguration.codableHelper),
]
let localVariableNonNullParameters = APIHelper.rejectNil(localVariableFormParams)

View File

@ -273,8 +273,8 @@ open class UserAPI {
var localVariableUrlComponents = URLComponents(string: localVariableURLString)
localVariableUrlComponents?.queryItems = APIHelper.mapValuesToQueryItems([
"username": (wrappedValue: username.encodeToQueryString(codableHelper: apiConfiguration.codableHelper), isExplode: false),
"password": (wrappedValue: password.encodeToQueryString(codableHelper: apiConfiguration.codableHelper), isExplode: false),
"username": (wrappedValue: username.asParameter(codableHelper: apiConfiguration.codableHelper), isExplode: false),
"password": (wrappedValue: password.asParameter(codableHelper: apiConfiguration.codableHelper), isExplode: false),
])
let localVariableNillableHeaders: [String: (any Sendable)?] = [

View File

@ -9,78 +9,73 @@ import Foundation
import FoundationNetworking
#endif
extension QueryStringEncodable {
@_disfavoredOverload
func encodeToQueryString(codableHelper: CodableHelper) -> String { String(describing: self) }
extension Bool: ParameterConvertible {
func asParameter(codableHelper: CodableHelper) -> any Sendable { self }
}
extension Bool: QueryStringEncodable {
func encodeToQueryString(codableHelper: CodableHelper) -> String { String(describing: self) }
extension Float: ParameterConvertible {
func asParameter(codableHelper: CodableHelper) -> any Sendable { self }
}
extension Float: QueryStringEncodable {
func encodeToQueryString(codableHelper: CodableHelper) -> String { String(describing: self) }
extension Int: ParameterConvertible {
func asParameter(codableHelper: CodableHelper) -> any Sendable { self }
}
extension Int: QueryStringEncodable {
func encodeToQueryString(codableHelper: CodableHelper) -> String { String(describing: self) }
extension Int32: ParameterConvertible {
func asParameter(codableHelper: CodableHelper) -> any Sendable { self }
}
extension Int32: QueryStringEncodable {
func encodeToQueryString(codableHelper: CodableHelper) -> String { String(describing: self) }
extension Int64: ParameterConvertible {
func asParameter(codableHelper: CodableHelper) -> any Sendable { self }
}
extension Int64: QueryStringEncodable {
func encodeToQueryString(codableHelper: CodableHelper) -> String { String(describing: self) }
extension Double: ParameterConvertible {
func asParameter(codableHelper: CodableHelper) -> any Sendable { self }
}
extension Double: QueryStringEncodable {
func encodeToQueryString(codableHelper: CodableHelper) -> String { String(describing: self) }
extension Decimal: ParameterConvertible {
func asParameter(codableHelper: CodableHelper) -> any Sendable { self }
}
extension Decimal: QueryStringEncodable {
func encodeToQueryString(codableHelper: CodableHelper) -> String { String(describing: self) }
extension String: ParameterConvertible {
func asParameter(codableHelper: CodableHelper) -> any Sendable { self }
}
extension String: QueryStringEncodable {
func encodeToQueryString(codableHelper: CodableHelper) -> String { String(describing: self) }
extension URL: ParameterConvertible {
func asParameter(codableHelper: CodableHelper) -> any Sendable { self }
}
extension URL: QueryStringEncodable {
func encodeToQueryString(codableHelper: CodableHelper) -> String { String(describing: self) }
extension UUID: ParameterConvertible {
func asParameter(codableHelper: CodableHelper) -> any Sendable { self }
}
extension UUID: QueryStringEncodable {
func encodeToQueryString(codableHelper: CodableHelper) -> String { String(describing: self) }
extension RawRepresentable where RawValue: ParameterConvertible, RawValue: Sendable {
func asParameter(codableHelper: CodableHelper) -> any Sendable { return self.rawValue }
}
extension RawRepresentable where RawValue: QueryStringEncodable {
func encodeToQueryString(codableHelper: CodableHelper) -> String { String(describing: rawValue) }
}
private func encodeIfPossible<T>(_ object: T, codableHelper: CodableHelper) -> String {
if let encodableObject = object as? QueryStringEncodable {
return encodableObject.encodeToQueryString(codableHelper: codableHelper)
private func encodeIfPossible<T: Sendable>(_ object: T, codableHelper: CodableHelper) -> any Sendable {
if let encodableObject = object as? ParameterConvertible {
return encodableObject.asParameter(codableHelper: codableHelper)
} else {
return String(describing: object)
return object
}
}
extension Array {
func encodeToQueryString(codableHelper: CodableHelper) -> [String] {
extension Array where Element: Sendable {
func asParameter(codableHelper: CodableHelper) -> any Sendable {
return self.map { encodeIfPossible($0, codableHelper: codableHelper) }
}
}
extension Set {
func encodeToQueryString(codableHelper: CodableHelper) -> [String] {
return Array(self).encodeToQueryString(codableHelper: codableHelper)
extension Set where Element: Sendable {
func asParameter(codableHelper: CodableHelper) -> any Sendable {
return Array(self).asParameter(codableHelper: codableHelper)
}
}
extension Dictionary {
func encodeToQueryString(codableHelper: CodableHelper) -> [Key: String] {
var dictionary = [Key: String]()
extension Dictionary where Key: Sendable, Value: Sendable {
func asParameter(codableHelper: CodableHelper) -> any Sendable {
var dictionary = [Key: any Sendable]()
for (key, value) in self {
dictionary[key] = encodeIfPossible(value, codableHelper: codableHelper)
}
@ -88,24 +83,24 @@ extension Dictionary {
}
}
extension Data: QueryStringEncodable {
func encodeToQueryString(codableHelper: CodableHelper) -> String {
extension Data: ParameterConvertible {
func asParameter(codableHelper: CodableHelper) -> any Sendable {
return self.base64EncodedString(options: Data.Base64EncodingOptions())
}
}
extension Date: QueryStringEncodable {
func encodeToQueryString(codableHelper: CodableHelper) -> String {
extension Date: ParameterConvertible {
func asParameter(codableHelper: CodableHelper) -> any Sendable {
return codableHelper.dateFormatter.string(from: self)
}
}
extension QueryStringEncodable where Self: Encodable {
func encodeToQueryString(codableHelper: CodableHelper) -> String {
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.encodeToQueryString(codableHelper: codableHelper)
return data.asParameter(codableHelper: codableHelper)
}
}

View File

@ -10,8 +10,8 @@ import FoundationNetworking
#endif
import Alamofire
protocol QueryStringEncodable {
func encodeToQueryString(codableHelper: CodableHelper) -> String
protocol ParameterConvertible {
func asParameter(codableHelper: CodableHelper) -> any Sendable
}
/// An enum where the last case value can be used as a default catch-all.

View File

@ -76,8 +76,8 @@ public struct OpenAPIDateWithoutTime: Sendable, Codable, Hashable, Equatable {
}
}
extension OpenAPIDateWithoutTime: QueryStringEncodable {
func encodeToQueryString(codableHelper: CodableHelper) -> String {
extension OpenAPIDateWithoutTime: ParameterConvertible {
func asParameter(codableHelper: CodableHelper) -> any Sendable {
return OpenISO8601DateFormatter.withoutTime.string(from: self.normalizedWrappedDate())
}
}

View File

@ -7,7 +7,7 @@
import Foundation
public struct AdditionalPropertiesClass: Sendable, Codable, QueryStringEncodable, Hashable {
public struct AdditionalPropertiesClass: Sendable, Codable, ParameterConvertible, Hashable {
public var mapString: [String: String]?
public var mapMapString: [String: [String: String]]?

View File

@ -7,7 +7,7 @@
import Foundation
public struct Animal: Sendable, Codable, QueryStringEncodable, Hashable {
public struct Animal: Sendable, Codable, ParameterConvertible, Hashable {
public var className: String
public var color: String? = "red"

View File

@ -7,7 +7,7 @@
import Foundation
public struct ApiResponse: Sendable, Codable, QueryStringEncodable, Hashable {
public struct ApiResponse: Sendable, Codable, ParameterConvertible, Hashable {
public var code: Int?
public var type: String?

View File

@ -7,7 +7,7 @@
import Foundation
public struct ArrayOfArrayOfNumberOnly: Sendable, Codable, QueryStringEncodable, Hashable {
public struct ArrayOfArrayOfNumberOnly: Sendable, Codable, ParameterConvertible, Hashable {
public var arrayArrayNumber: [[Double]]?

View File

@ -7,7 +7,7 @@
import Foundation
public struct ArrayOfNumberOnly: Sendable, Codable, QueryStringEncodable, Hashable {
public struct ArrayOfNumberOnly: Sendable, Codable, ParameterConvertible, Hashable {
public var arrayNumber: [Double]?

View File

@ -7,7 +7,7 @@
import Foundation
public struct ArrayTest: Sendable, Codable, QueryStringEncodable, Hashable {
public struct ArrayTest: Sendable, Codable, ParameterConvertible, Hashable {
public var arrayOfString: [String]?
public var arrayArrayOfInteger: [[Int64]]?

View File

@ -7,7 +7,7 @@
import Foundation
public struct Capitalization: Sendable, Codable, QueryStringEncodable, Hashable {
public struct Capitalization: Sendable, Codable, ParameterConvertible, Hashable {
public var smallCamel: String?
public var capitalCamel: String?

View File

@ -7,7 +7,7 @@
import Foundation
public struct Cat: Sendable, Codable, QueryStringEncodable, Hashable {
public struct Cat: Sendable, Codable, ParameterConvertible, Hashable {
public var className: String
public var color: String? = "red"

View File

@ -7,7 +7,7 @@
import Foundation
public struct Category: Sendable, Codable, QueryStringEncodable, Hashable {
public struct Category: Sendable, Codable, ParameterConvertible, Hashable {
public var id: Int64?
public var name: String? = "default-name"

View File

@ -8,7 +8,7 @@
import Foundation
/** Model for testing model with \&quot;_class\&quot; property */
public struct ClassModel: Sendable, Codable, QueryStringEncodable, Hashable {
public struct ClassModel: Sendable, Codable, ParameterConvertible, Hashable {
public var _class: String?

View File

@ -7,7 +7,7 @@
import Foundation
public struct Client: Sendable, Codable, QueryStringEncodable, Hashable {
public struct Client: Sendable, Codable, ParameterConvertible, Hashable {
public var client: String?

View File

@ -7,7 +7,7 @@
import Foundation
public struct Dog: Sendable, Codable, QueryStringEncodable, Hashable {
public struct Dog: Sendable, Codable, ParameterConvertible, Hashable {
public var className: String
public var color: String? = "red"

View File

@ -7,7 +7,7 @@
import Foundation
public struct EnumArrays: Sendable, Codable, QueryStringEncodable, Hashable {
public struct EnumArrays: Sendable, Codable, ParameterConvertible, Hashable {
public enum JustSymbol: String, Sendable, Codable, CaseIterable {
case greaterThanOrEqualTo = ">="

View File

@ -7,7 +7,7 @@
import Foundation
public struct EnumTest: Sendable, Codable, QueryStringEncodable, Hashable {
public struct EnumTest: Sendable, Codable, ParameterConvertible, Hashable {
public enum EnumString: String, Sendable, Codable, CaseIterable {
case upper = "UPPER"

View File

@ -8,7 +8,7 @@
import Foundation
/** Must be named &#x60;File&#x60; for test. */
public struct File: Sendable, Codable, QueryStringEncodable, Hashable {
public struct File: Sendable, Codable, ParameterConvertible, Hashable {
/** Test capitalization */
public var sourceURI: String?

View File

@ -7,7 +7,7 @@
import Foundation
public struct FileSchemaTestClass: Sendable, Codable, QueryStringEncodable, Hashable {
public struct FileSchemaTestClass: Sendable, Codable, ParameterConvertible, Hashable {
public var file: File?
public var files: [File]?

View File

@ -7,7 +7,7 @@
import Foundation
public struct FormatTest: Sendable, Codable, QueryStringEncodable, Hashable {
public struct FormatTest: Sendable, Codable, ParameterConvertible, 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)

View File

@ -7,7 +7,7 @@
import Foundation
public struct HasOnlyReadOnly: Sendable, Codable, QueryStringEncodable, Hashable {
public struct HasOnlyReadOnly: Sendable, Codable, ParameterConvertible, Hashable {
public var bar: String?
public var foo: String?

View File

@ -7,7 +7,7 @@
import Foundation
public struct List: Sendable, Codable, QueryStringEncodable, Hashable {
public struct List: Sendable, Codable, ParameterConvertible, Hashable {
public var _123list: String?

View File

@ -7,7 +7,7 @@
import Foundation
public struct MapTest: Sendable, Codable, QueryStringEncodable, Hashable {
public struct MapTest: Sendable, Codable, ParameterConvertible, Hashable {
public enum MapOfEnumString: String, Sendable, Codable, CaseIterable {
case upper = "UPPER"

View File

@ -7,7 +7,7 @@
import Foundation
public struct MixedPropertiesAndAdditionalPropertiesClass: Sendable, Codable, QueryStringEncodable, Hashable {
public struct MixedPropertiesAndAdditionalPropertiesClass: Sendable, Codable, ParameterConvertible, Hashable {
public var uuid: UUID?
public var dateTime: Date?

View File

@ -8,7 +8,7 @@
import Foundation
/** Model for testing model name starting with number */
public struct Model200Response: Sendable, Codable, QueryStringEncodable, Hashable {
public struct Model200Response: Sendable, Codable, ParameterConvertible, Hashable {
public var name: Int?
public var _class: String?

View File

@ -8,7 +8,7 @@
import Foundation
/** Model for testing model name same as property name */
public struct Name: Sendable, Codable, QueryStringEncodable, Hashable {
public struct Name: Sendable, Codable, ParameterConvertible, Hashable {
public var name: Int
public var snakeCase: NullEncodable<Int> = .encodeValue(11033)

View File

@ -7,7 +7,7 @@
import Foundation
public struct NumberOnly: Sendable, Codable, QueryStringEncodable, Hashable {
public struct NumberOnly: Sendable, Codable, ParameterConvertible, Hashable {
public var justNumber: Double?

View File

@ -7,7 +7,7 @@
import Foundation
public struct Order: Sendable, Codable, QueryStringEncodable, Hashable {
public struct Order: Sendable, Codable, ParameterConvertible, Hashable {
public enum Status: String, Sendable, Codable, CaseIterable {
case placed = "placed"

View File

@ -7,7 +7,7 @@
import Foundation
public struct OuterComposite: Sendable, Codable, QueryStringEncodable, Hashable {
public struct OuterComposite: Sendable, Codable, ParameterConvertible, Hashable {
public var myNumber: Double?
public var myString: String?

View File

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

View File

@ -7,7 +7,7 @@
import Foundation
public struct ReadOnlyFirst: Sendable, Codable, QueryStringEncodable, Hashable {
public struct ReadOnlyFirst: Sendable, Codable, ParameterConvertible, Hashable {
public var bar: String?
public var baz: String?

View File

@ -8,7 +8,7 @@
import Foundation
/** Model for testing reserved words */
public struct Return: Sendable, Codable, QueryStringEncodable, Hashable {
public struct Return: Sendable, Codable, ParameterConvertible, Hashable {
public var _return: Int?

View File

@ -7,7 +7,7 @@
import Foundation
public struct SpecialModelName: Sendable, Codable, QueryStringEncodable, Hashable {
public struct SpecialModelName: Sendable, Codable, ParameterConvertible, Hashable {
public var specialPropertyName: Int64?

View File

@ -7,7 +7,7 @@
import Foundation
public struct StringBooleanMap: Sendable, Codable, QueryStringEncodable, Hashable {
public struct StringBooleanMap: Sendable, Codable, ParameterConvertible, Hashable {
public enum CodingKeys: CodingKey, CaseIterable {

View File

@ -7,7 +7,7 @@
import Foundation
public struct Tag: Sendable, Codable, QueryStringEncodable, Hashable {
public struct Tag: Sendable, Codable, ParameterConvertible, Hashable {
public var id: Int64?
public var name: String?

View File

@ -7,7 +7,7 @@
import Foundation
public struct TypeHolderDefault: Sendable, Codable, QueryStringEncodable, Hashable {
public struct TypeHolderDefault: Sendable, Codable, ParameterConvertible, Hashable {
public var stringItem: String = "what"
public var numberItem: Double

View File

@ -7,7 +7,7 @@
import Foundation
public struct TypeHolderExample: Sendable, Codable, QueryStringEncodable, Hashable {
public struct TypeHolderExample: Sendable, Codable, ParameterConvertible, Hashable {
public var stringItem: String
public var numberItem: Double

View File

@ -7,7 +7,7 @@
import Foundation
public struct User: Sendable, Codable, QueryStringEncodable, Hashable {
public struct User: Sendable, Codable, ParameterConvertible, Hashable {
public var id: Int64?
public var username: String?

View File

@ -27,7 +27,7 @@ class DateFormatTests: XCTestCase {
super.tearDown()
}
func testencodeToQueryStringAlwaysResultsInUTCEncodedDate() {
func testAsParameterAlwaysResultsInUTCEncodedDate() {
var dateComponents = DateComponents()
dateComponents.calendar = Calendar(identifier: .gregorian)
dateComponents.year = 2018
@ -47,7 +47,7 @@ class DateFormatTests: XCTestCase {
return
}
var encodedDate = utcDate.encodeToQueryString(codableHelper: PetstoreClientAPIConfiguration.shared.codableHelper) as! String
var encodedDate = utcDate.asParameter(codableHelper: PetstoreClientAPIConfiguration.shared.codableHelper) as! String
XCTAssert(encodedDate.hasSuffix("Z"))
// test with a positive timzone offset from UTC
@ -59,7 +59,7 @@ class DateFormatTests: XCTestCase {
return
}
encodedDate = nonUTCDate1.encodeToQueryString(codableHelper: PetstoreClientAPIConfiguration.shared.codableHelper) as! String
encodedDate = nonUTCDate1.asParameter(codableHelper: PetstoreClientAPIConfiguration.shared.codableHelper) as! String
XCTAssert(encodedDate.hasSuffix("Z"))
// test with a negative timzone offset from UTC
@ -71,7 +71,7 @@ class DateFormatTests: XCTestCase {
return
}
encodedDate = nonUTCDate2.encodeToQueryString(codableHelper: PetstoreClientAPIConfiguration.shared.codableHelper) as! String
encodedDate = nonUTCDate2.asParameter(codableHelper: PetstoreClientAPIConfiguration.shared.codableHelper) as! String
XCTAssert(encodedDate.hasSuffix("Z"))
}

View File

@ -847,7 +847,7 @@ open class FakeAPI {
var localVariableUrlComponents = URLComponents(string: localVariableURLString)
localVariableUrlComponents?.queryItems = APIHelper.mapValuesToQueryItems([
"query": (wrappedValue: query.encodeToQueryString(codableHelper: apiConfiguration.codableHelper), isExplode: false),
"query": (wrappedValue: query.asParameter(codableHelper: apiConfiguration.codableHelper), isExplode: false),
])
let localVariableNillableHeaders: [String: (any Sendable)?] = [
@ -1233,20 +1233,20 @@ open class FakeAPI {
let localVariablePath = "/fake"
let localVariableURLString = apiConfiguration.basePath + localVariablePath
let localVariableFormParams: [String: (any Sendable)?] = [
"integer": integer?.encodeToQueryString(codableHelper: apiConfiguration.codableHelper),
"int32": int32?.encodeToQueryString(codableHelper: apiConfiguration.codableHelper),
"int64": int64?.encodeToQueryString(codableHelper: apiConfiguration.codableHelper),
"number": number.encodeToQueryString(codableHelper: apiConfiguration.codableHelper),
"float": float?.encodeToQueryString(codableHelper: apiConfiguration.codableHelper),
"double": double.encodeToQueryString(codableHelper: apiConfiguration.codableHelper),
"string": string?.encodeToQueryString(codableHelper: apiConfiguration.codableHelper),
"pattern_without_delimiter": patternWithoutDelimiter.encodeToQueryString(codableHelper: apiConfiguration.codableHelper),
"byte": byte.encodeToQueryString(codableHelper: apiConfiguration.codableHelper),
"binary": binary?.encodeToQueryString(codableHelper: apiConfiguration.codableHelper),
"date": date?.encodeToQueryString(codableHelper: apiConfiguration.codableHelper),
"dateTime": dateTime?.encodeToQueryString(codableHelper: apiConfiguration.codableHelper),
"password": password?.encodeToQueryString(codableHelper: apiConfiguration.codableHelper),
"callback": callback?.encodeToQueryString(codableHelper: apiConfiguration.codableHelper),
"integer": integer?.asParameter(codableHelper: apiConfiguration.codableHelper),
"int32": int32?.asParameter(codableHelper: apiConfiguration.codableHelper),
"int64": int64?.asParameter(codableHelper: apiConfiguration.codableHelper),
"number": number.asParameter(codableHelper: apiConfiguration.codableHelper),
"float": float?.asParameter(codableHelper: apiConfiguration.codableHelper),
"double": double.asParameter(codableHelper: apiConfiguration.codableHelper),
"string": string?.asParameter(codableHelper: apiConfiguration.codableHelper),
"pattern_without_delimiter": patternWithoutDelimiter.asParameter(codableHelper: apiConfiguration.codableHelper),
"byte": byte.asParameter(codableHelper: apiConfiguration.codableHelper),
"binary": binary?.asParameter(codableHelper: apiConfiguration.codableHelper),
"date": date?.asParameter(codableHelper: apiConfiguration.codableHelper),
"dateTime": dateTime?.asParameter(codableHelper: apiConfiguration.codableHelper),
"password": password?.asParameter(codableHelper: apiConfiguration.codableHelper),
"callback": callback?.asParameter(codableHelper: apiConfiguration.codableHelper),
]
let localVariableNonNullParameters = APIHelper.rejectNil(localVariableFormParams)
@ -1513,8 +1513,8 @@ open class FakeAPI {
let localVariablePath = "/fake"
let localVariableURLString = apiConfiguration.basePath + localVariablePath
let localVariableFormParams: [String: (any Sendable)?] = [
"enum_form_string_array": enumFormStringArray?.encodeToQueryString(codableHelper: apiConfiguration.codableHelper),
"enum_form_string": enumFormString?.encodeToQueryString(codableHelper: apiConfiguration.codableHelper),
"enum_form_string_array": enumFormStringArray?.asParameter(codableHelper: apiConfiguration.codableHelper),
"enum_form_string": enumFormString?.asParameter(codableHelper: apiConfiguration.codableHelper),
]
let localVariableNonNullParameters = APIHelper.rejectNil(localVariableFormParams)
@ -1522,16 +1522,16 @@ open class FakeAPI {
var localVariableUrlComponents = URLComponents(string: localVariableURLString)
localVariableUrlComponents?.queryItems = APIHelper.mapValuesToQueryItems([
"enum_query_string_array": (wrappedValue: enumQueryStringArray?.encodeToQueryString(codableHelper: apiConfiguration.codableHelper), isExplode: false),
"enum_query_string": (wrappedValue: enumQueryString?.encodeToQueryString(codableHelper: apiConfiguration.codableHelper), isExplode: false),
"enum_query_integer": (wrappedValue: enumQueryInteger?.encodeToQueryString(codableHelper: apiConfiguration.codableHelper), isExplode: false),
"enum_query_double": (wrappedValue: enumQueryDouble?.encodeToQueryString(codableHelper: apiConfiguration.codableHelper), isExplode: false),
"enum_query_string_array": (wrappedValue: enumQueryStringArray?.asParameter(codableHelper: apiConfiguration.codableHelper), isExplode: false),
"enum_query_string": (wrappedValue: enumQueryString?.asParameter(codableHelper: apiConfiguration.codableHelper), isExplode: false),
"enum_query_integer": (wrappedValue: enumQueryInteger?.asParameter(codableHelper: apiConfiguration.codableHelper), isExplode: false),
"enum_query_double": (wrappedValue: enumQueryDouble?.asParameter(codableHelper: apiConfiguration.codableHelper), isExplode: false),
])
let localVariableNillableHeaders: [String: (any Sendable)?] = [
"Content-Type": "application/x-www-form-urlencoded",
"enum_header_string_array": enumHeaderStringArray?.encodeToQueryString(codableHelper: apiConfiguration.codableHelper),
"enum_header_string": enumHeaderString?.encodeToQueryString(codableHelper: apiConfiguration.codableHelper),
"enum_header_string_array": enumHeaderStringArray?.asParameter(codableHelper: apiConfiguration.codableHelper),
"enum_header_string": enumHeaderString?.asParameter(codableHelper: apiConfiguration.codableHelper),
]
let localVariableHeaderParameters = APIHelper.rejectNilHeaders(localVariableNillableHeaders)
@ -1711,15 +1711,15 @@ open class FakeAPI {
var localVariableUrlComponents = URLComponents(string: localVariableURLString)
localVariableUrlComponents?.queryItems = APIHelper.mapValuesToQueryItems([
"required_string_group": (wrappedValue: requiredStringGroup.encodeToQueryString(codableHelper: apiConfiguration.codableHelper), isExplode: false),
"required_int64_group": (wrappedValue: requiredInt64Group.encodeToQueryString(codableHelper: apiConfiguration.codableHelper), isExplode: false),
"string_group": (wrappedValue: stringGroup?.encodeToQueryString(codableHelper: apiConfiguration.codableHelper), isExplode: false),
"int64_group": (wrappedValue: int64Group?.encodeToQueryString(codableHelper: apiConfiguration.codableHelper), isExplode: false),
"required_string_group": (wrappedValue: requiredStringGroup.asParameter(codableHelper: apiConfiguration.codableHelper), isExplode: false),
"required_int64_group": (wrappedValue: requiredInt64Group.asParameter(codableHelper: apiConfiguration.codableHelper), isExplode: false),
"string_group": (wrappedValue: stringGroup?.asParameter(codableHelper: apiConfiguration.codableHelper), isExplode: false),
"int64_group": (wrappedValue: int64Group?.asParameter(codableHelper: apiConfiguration.codableHelper), isExplode: false),
])
let localVariableNillableHeaders: [String: (any Sendable)?] = [
"required_boolean_group": requiredBooleanGroup.encodeToQueryString(codableHelper: apiConfiguration.codableHelper),
"boolean_group": booleanGroup?.encodeToQueryString(codableHelper: apiConfiguration.codableHelper),
"required_boolean_group": requiredBooleanGroup.asParameter(codableHelper: apiConfiguration.codableHelper),
"boolean_group": booleanGroup?.asParameter(codableHelper: apiConfiguration.codableHelper),
]
let localVariableHeaderParameters = APIHelper.rejectNilHeaders(localVariableNillableHeaders)
@ -2012,8 +2012,8 @@ open class FakeAPI {
let localVariablePath = "/fake/jsonFormData"
let localVariableURLString = apiConfiguration.basePath + localVariablePath
let localVariableFormParams: [String: (any Sendable)?] = [
"param": param.encodeToQueryString(codableHelper: apiConfiguration.codableHelper),
"param2": param2.encodeToQueryString(codableHelper: apiConfiguration.codableHelper),
"param": param.asParameter(codableHelper: apiConfiguration.codableHelper),
"param2": param2.asParameter(codableHelper: apiConfiguration.codableHelper),
]
let localVariableNonNullParameters = APIHelper.rejectNil(localVariableFormParams)

View File

@ -317,7 +317,7 @@ open class PetAPI {
let localVariableUrlComponents = URLComponents(string: localVariableURLString)
let localVariableNillableHeaders: [String: (any Sendable)?] = [
"api_key": apiKey?.encodeToQueryString(codableHelper: apiConfiguration.codableHelper),
"api_key": apiKey?.asParameter(codableHelper: apiConfiguration.codableHelper),
]
let localVariableHeaderParameters = APIHelper.rejectNilHeaders(localVariableNillableHeaders)
@ -474,7 +474,7 @@ open class PetAPI {
var localVariableUrlComponents = URLComponents(string: localVariableURLString)
localVariableUrlComponents?.queryItems = APIHelper.mapValuesToQueryItems([
"status": (wrappedValue: status.encodeToQueryString(codableHelper: apiConfiguration.codableHelper), isExplode: false),
"status": (wrappedValue: status.asParameter(codableHelper: apiConfiguration.codableHelper), isExplode: false),
])
let localVariableNillableHeaders: [String: (any Sendable)?] = [
@ -633,7 +633,7 @@ open class PetAPI {
var localVariableUrlComponents = URLComponents(string: localVariableURLString)
localVariableUrlComponents?.queryItems = APIHelper.mapValuesToQueryItems([
"tags": (wrappedValue: tags.encodeToQueryString(codableHelper: apiConfiguration.codableHelper), isExplode: false),
"tags": (wrappedValue: tags.asParameter(codableHelper: apiConfiguration.codableHelper), isExplode: false),
])
let localVariableNillableHeaders: [String: (any Sendable)?] = [
@ -1098,8 +1098,8 @@ open class PetAPI {
localVariablePath = localVariablePath.replacingOccurrences(of: "{petId}", with: petIdPostEscape, options: .literal, range: nil)
let localVariableURLString = apiConfiguration.basePath + localVariablePath
let localVariableFormParams: [String: (any Sendable)?] = [
"name": name?.encodeToQueryString(codableHelper: apiConfiguration.codableHelper),
"status": status?.encodeToQueryString(codableHelper: apiConfiguration.codableHelper),
"name": name?.asParameter(codableHelper: apiConfiguration.codableHelper),
"status": status?.asParameter(codableHelper: apiConfiguration.codableHelper),
]
let localVariableNonNullParameters = APIHelper.rejectNil(localVariableFormParams)
@ -1269,8 +1269,8 @@ open class PetAPI {
localVariablePath = localVariablePath.replacingOccurrences(of: "{petId}", with: petIdPostEscape, options: .literal, range: nil)
let localVariableURLString = apiConfiguration.basePath + localVariablePath
let localVariableFormParams: [String: (any Sendable)?] = [
"additionalMetadata": additionalMetadata?.encodeToQueryString(codableHelper: apiConfiguration.codableHelper),
"file": file?.encodeToQueryString(codableHelper: apiConfiguration.codableHelper),
"additionalMetadata": additionalMetadata?.asParameter(codableHelper: apiConfiguration.codableHelper),
"file": file?.asParameter(codableHelper: apiConfiguration.codableHelper),
]
let localVariableNonNullParameters = APIHelper.rejectNil(localVariableFormParams)
@ -1440,8 +1440,8 @@ open class PetAPI {
localVariablePath = localVariablePath.replacingOccurrences(of: "{petId}", with: petIdPostEscape, options: .literal, range: nil)
let localVariableURLString = apiConfiguration.basePath + localVariablePath
let localVariableFormParams: [String: (any Sendable)?] = [
"additionalMetadata": additionalMetadata?.encodeToQueryString(codableHelper: apiConfiguration.codableHelper),
"requiredFile": requiredFile.encodeToQueryString(codableHelper: apiConfiguration.codableHelper),
"additionalMetadata": additionalMetadata?.asParameter(codableHelper: apiConfiguration.codableHelper),
"requiredFile": requiredFile.asParameter(codableHelper: apiConfiguration.codableHelper),
]
let localVariableNonNullParameters = APIHelper.rejectNil(localVariableFormParams)

View File

@ -893,8 +893,8 @@ open class UserAPI {
var localVariableUrlComponents = URLComponents(string: localVariableURLString)
localVariableUrlComponents?.queryItems = APIHelper.mapValuesToQueryItems([
"username": (wrappedValue: username.encodeToQueryString(codableHelper: apiConfiguration.codableHelper), isExplode: false),
"password": (wrappedValue: password.encodeToQueryString(codableHelper: apiConfiguration.codableHelper), isExplode: false),
"username": (wrappedValue: username.asParameter(codableHelper: apiConfiguration.codableHelper), isExplode: false),
"password": (wrappedValue: password.asParameter(codableHelper: apiConfiguration.codableHelper), isExplode: false),
])
let localVariableNillableHeaders: [String: (any Sendable)?] = [

View File

@ -10,78 +10,73 @@ import FoundationNetworking
#endif
@preconcurrency import PromiseKit
extension QueryStringEncodable {
@_disfavoredOverload
func encodeToQueryString(codableHelper: CodableHelper) -> String { String(describing: self) }
extension Bool: ParameterConvertible {
func asParameter(codableHelper: CodableHelper) -> any Sendable { self }
}
extension Bool: QueryStringEncodable {
func encodeToQueryString(codableHelper: CodableHelper) -> String { String(describing: self) }
extension Float: ParameterConvertible {
func asParameter(codableHelper: CodableHelper) -> any Sendable { self }
}
extension Float: QueryStringEncodable {
func encodeToQueryString(codableHelper: CodableHelper) -> String { String(describing: self) }
extension Int: ParameterConvertible {
func asParameter(codableHelper: CodableHelper) -> any Sendable { self }
}
extension Int: QueryStringEncodable {
func encodeToQueryString(codableHelper: CodableHelper) -> String { String(describing: self) }
extension Int32: ParameterConvertible {
func asParameter(codableHelper: CodableHelper) -> any Sendable { self }
}
extension Int32: QueryStringEncodable {
func encodeToQueryString(codableHelper: CodableHelper) -> String { String(describing: self) }
extension Int64: ParameterConvertible {
func asParameter(codableHelper: CodableHelper) -> any Sendable { self }
}
extension Int64: QueryStringEncodable {
func encodeToQueryString(codableHelper: CodableHelper) -> String { String(describing: self) }
extension Double: ParameterConvertible {
func asParameter(codableHelper: CodableHelper) -> any Sendable { self }
}
extension Double: QueryStringEncodable {
func encodeToQueryString(codableHelper: CodableHelper) -> String { String(describing: self) }
extension Decimal: ParameterConvertible {
func asParameter(codableHelper: CodableHelper) -> any Sendable { self }
}
extension Decimal: QueryStringEncodable {
func encodeToQueryString(codableHelper: CodableHelper) -> String { String(describing: self) }
extension String: ParameterConvertible {
func asParameter(codableHelper: CodableHelper) -> any Sendable { self }
}
extension String: QueryStringEncodable {
func encodeToQueryString(codableHelper: CodableHelper) -> String { String(describing: self) }
extension URL: ParameterConvertible {
func asParameter(codableHelper: CodableHelper) -> any Sendable { self }
}
extension URL: QueryStringEncodable {
func encodeToQueryString(codableHelper: CodableHelper) -> String { String(describing: self) }
extension UUID: ParameterConvertible {
func asParameter(codableHelper: CodableHelper) -> any Sendable { self }
}
extension UUID: QueryStringEncodable {
func encodeToQueryString(codableHelper: CodableHelper) -> String { String(describing: self) }
extension RawRepresentable where RawValue: ParameterConvertible, RawValue: Sendable {
func asParameter(codableHelper: CodableHelper) -> any Sendable { return self.rawValue }
}
extension RawRepresentable where RawValue: QueryStringEncodable {
func encodeToQueryString(codableHelper: CodableHelper) -> String { String(describing: rawValue) }
}
private func encodeIfPossible<T>(_ object: T, codableHelper: CodableHelper) -> String {
if let encodableObject = object as? QueryStringEncodable {
return encodableObject.encodeToQueryString(codableHelper: codableHelper)
private func encodeIfPossible<T: Sendable>(_ object: T, codableHelper: CodableHelper) -> any Sendable {
if let encodableObject = object as? ParameterConvertible {
return encodableObject.asParameter(codableHelper: codableHelper)
} else {
return String(describing: object)
return object
}
}
extension Array {
func encodeToQueryString(codableHelper: CodableHelper) -> [String] {
extension Array where Element: Sendable {
func asParameter(codableHelper: CodableHelper) -> any Sendable {
return self.map { encodeIfPossible($0, codableHelper: codableHelper) }
}
}
extension Set {
func encodeToQueryString(codableHelper: CodableHelper) -> [String] {
return Array(self).encodeToQueryString(codableHelper: codableHelper)
extension Set where Element: Sendable {
func asParameter(codableHelper: CodableHelper) -> any Sendable {
return Array(self).asParameter(codableHelper: codableHelper)
}
}
extension Dictionary {
func encodeToQueryString(codableHelper: CodableHelper) -> [Key: String] {
var dictionary = [Key: String]()
extension Dictionary where Key: Sendable, Value: Sendable {
func asParameter(codableHelper: CodableHelper) -> any Sendable {
var dictionary = [Key: any Sendable]()
for (key, value) in self {
dictionary[key] = encodeIfPossible(value, codableHelper: codableHelper)
}
@ -89,24 +84,24 @@ extension Dictionary {
}
}
extension Data: QueryStringEncodable {
func encodeToQueryString(codableHelper: CodableHelper) -> String {
extension Data: ParameterConvertible {
func asParameter(codableHelper: CodableHelper) -> any Sendable {
return self.base64EncodedString(options: Data.Base64EncodingOptions())
}
}
extension Date: QueryStringEncodable {
func encodeToQueryString(codableHelper: CodableHelper) -> String {
extension Date: ParameterConvertible {
func asParameter(codableHelper: CodableHelper) -> any Sendable {
return codableHelper.dateFormatter.string(from: self)
}
}
extension QueryStringEncodable where Self: Encodable {
func encodeToQueryString(codableHelper: CodableHelper) -> String {
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.encodeToQueryString(codableHelper: codableHelper)
return data.asParameter(codableHelper: codableHelper)
}
}

View File

@ -10,8 +10,8 @@ import FoundationNetworking
#endif
import Alamofire
protocol QueryStringEncodable {
func encodeToQueryString(codableHelper: CodableHelper) -> String
protocol ParameterConvertible {
func asParameter(codableHelper: CodableHelper) -> any Sendable
}
/// An enum where the last case value can be used as a default catch-all.

View File

@ -7,7 +7,7 @@
import Foundation
public struct AdditionalPropertiesClass: Sendable, Codable, QueryStringEncodable, Hashable {
public struct AdditionalPropertiesClass: Sendable, Codable, ParameterConvertible, Hashable {
public var mapString: [String: String]?
public var mapMapString: [String: [String: String]]?

View File

@ -7,7 +7,7 @@
import Foundation
public struct Animal: Sendable, Codable, QueryStringEncodable, Hashable {
public struct Animal: Sendable, Codable, ParameterConvertible, Hashable {
public var className: String
public var color: String? = "red"

View File

@ -7,7 +7,7 @@
import Foundation
public struct ApiResponse: Sendable, Codable, QueryStringEncodable, Hashable {
public struct ApiResponse: Sendable, Codable, ParameterConvertible, Hashable {
public var code: Int?
public var type: String?

View File

@ -7,7 +7,7 @@
import Foundation
public struct ArrayOfArrayOfNumberOnly: Sendable, Codable, QueryStringEncodable, Hashable {
public struct ArrayOfArrayOfNumberOnly: Sendable, Codable, ParameterConvertible, Hashable {
public var arrayArrayNumber: [[Double]]?

View File

@ -7,7 +7,7 @@
import Foundation
public struct ArrayOfNumberOnly: Sendable, Codable, QueryStringEncodable, Hashable {
public struct ArrayOfNumberOnly: Sendable, Codable, ParameterConvertible, Hashable {
public var arrayNumber: [Double]?

View File

@ -7,7 +7,7 @@
import Foundation
public struct ArrayTest: Sendable, Codable, QueryStringEncodable, Hashable {
public struct ArrayTest: Sendable, Codable, ParameterConvertible, Hashable {
public var arrayOfString: [String]?
public var arrayArrayOfInteger: [[Int64]]?

View File

@ -7,7 +7,7 @@
import Foundation
public struct Capitalization: Sendable, Codable, QueryStringEncodable, Hashable {
public struct Capitalization: Sendable, Codable, ParameterConvertible, Hashable {
public var smallCamel: String?
public var capitalCamel: String?

View File

@ -7,7 +7,7 @@
import Foundation
public struct Cat: Sendable, Codable, QueryStringEncodable, Hashable {
public struct Cat: Sendable, Codable, ParameterConvertible, Hashable {
public var className: String
public var color: String? = "red"

View File

@ -7,7 +7,7 @@
import Foundation
public struct Category: Sendable, Codable, QueryStringEncodable, Hashable {
public struct Category: Sendable, Codable, ParameterConvertible, Hashable {
public var id: Int64?
public var name: String? = "default-name"

View File

@ -8,7 +8,7 @@
import Foundation
/** Model for testing model with \&quot;_class\&quot; property */
public struct ClassModel: Sendable, Codable, QueryStringEncodable, Hashable {
public struct ClassModel: Sendable, Codable, ParameterConvertible, Hashable {
public var _class: String?

View File

@ -7,7 +7,7 @@
import Foundation
public struct Client: Sendable, Codable, QueryStringEncodable, Hashable {
public struct Client: Sendable, Codable, ParameterConvertible, Hashable {
public var client: String?

View File

@ -7,7 +7,7 @@
import Foundation
public struct Dog: Sendable, Codable, QueryStringEncodable, Hashable {
public struct Dog: Sendable, Codable, ParameterConvertible, Hashable {
public var className: String
public var color: String? = "red"

View File

@ -7,7 +7,7 @@
import Foundation
public struct EnumArrays: Sendable, Codable, QueryStringEncodable, Hashable {
public struct EnumArrays: Sendable, Codable, ParameterConvertible, Hashable {
public enum JustSymbol: String, Sendable, Codable, CaseIterable {
case greaterThanOrEqualTo = ">="

View File

@ -7,7 +7,7 @@
import Foundation
public struct EnumTest: Sendable, Codable, QueryStringEncodable, Hashable {
public struct EnumTest: Sendable, Codable, ParameterConvertible, Hashable {
public enum EnumString: String, Sendable, Codable, CaseIterable {
case upper = "UPPER"

View File

@ -8,7 +8,7 @@
import Foundation
/** Must be named &#x60;File&#x60; for test. */
public struct File: Sendable, Codable, QueryStringEncodable, Hashable {
public struct File: Sendable, Codable, ParameterConvertible, Hashable {
/** Test capitalization */
public var sourceURI: String?

View File

@ -7,7 +7,7 @@
import Foundation
public struct FileSchemaTestClass: Sendable, Codable, QueryStringEncodable, Hashable {
public struct FileSchemaTestClass: Sendable, Codable, ParameterConvertible, Hashable {
public var file: File?
public var files: [File]?

View File

@ -7,7 +7,7 @@
import Foundation
public struct FormatTest: Sendable, Codable, QueryStringEncodable, Hashable {
public struct FormatTest: Sendable, Codable, ParameterConvertible, 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)

View File

@ -7,7 +7,7 @@
import Foundation
public struct HasOnlyReadOnly: Sendable, Codable, QueryStringEncodable, Hashable {
public struct HasOnlyReadOnly: Sendable, Codable, ParameterConvertible, Hashable {
public var bar: String?
public var foo: String?

View File

@ -7,7 +7,7 @@
import Foundation
public struct List: Sendable, Codable, QueryStringEncodable, Hashable {
public struct List: Sendable, Codable, ParameterConvertible, Hashable {
public var _123list: String?

View File

@ -7,7 +7,7 @@
import Foundation
public struct MapTest: Sendable, Codable, QueryStringEncodable, Hashable {
public struct MapTest: Sendable, Codable, ParameterConvertible, Hashable {
public enum MapOfEnumString: String, Sendable, Codable, CaseIterable {
case upper = "UPPER"

View File

@ -7,7 +7,7 @@
import Foundation
public struct MixedPropertiesAndAdditionalPropertiesClass: Sendable, Codable, QueryStringEncodable, Hashable {
public struct MixedPropertiesAndAdditionalPropertiesClass: Sendable, Codable, ParameterConvertible, Hashable {
public var uuid: UUID?
public var dateTime: Date?

View File

@ -8,7 +8,7 @@
import Foundation
/** Model for testing model name starting with number */
public struct Model200Response: Sendable, Codable, QueryStringEncodable, Hashable {
public struct Model200Response: Sendable, Codable, ParameterConvertible, Hashable {
public var name: Int?
public var _class: String?

View File

@ -8,7 +8,7 @@
import Foundation
/** Model for testing model name same as property name */
public struct Name: Sendable, Codable, QueryStringEncodable, Hashable {
public struct Name: Sendable, Codable, ParameterConvertible, Hashable {
public var name: Int
public var snakeCase: NullEncodable<Int> = .encodeValue(11033)

View File

@ -7,7 +7,7 @@
import Foundation
public struct NumberOnly: Sendable, Codable, QueryStringEncodable, Hashable {
public struct NumberOnly: Sendable, Codable, ParameterConvertible, Hashable {
public var justNumber: Double?

View File

@ -7,7 +7,7 @@
import Foundation
public struct Order: Sendable, Codable, QueryStringEncodable, Hashable {
public struct Order: Sendable, Codable, ParameterConvertible, Hashable {
public enum Status: String, Sendable, Codable, CaseIterable {
case placed = "placed"

View File

@ -7,7 +7,7 @@
import Foundation
public struct OuterComposite: Sendable, Codable, QueryStringEncodable, Hashable {
public struct OuterComposite: Sendable, Codable, ParameterConvertible, Hashable {
public var myNumber: Double?
public var myString: String?

View File

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

View File

@ -7,7 +7,7 @@
import Foundation
public struct ReadOnlyFirst: Sendable, Codable, QueryStringEncodable, Hashable {
public struct ReadOnlyFirst: Sendable, Codable, ParameterConvertible, Hashable {
public var bar: String?
public var baz: String?

View File

@ -8,7 +8,7 @@
import Foundation
/** Model for testing reserved words */
public struct Return: Sendable, Codable, QueryStringEncodable, Hashable {
public struct Return: Sendable, Codable, ParameterConvertible, Hashable {
public var _return: Int?

View File

@ -7,7 +7,7 @@
import Foundation
public struct SpecialModelName: Sendable, Codable, QueryStringEncodable, Hashable {
public struct SpecialModelName: Sendable, Codable, ParameterConvertible, Hashable {
public var specialPropertyName: Int64?

View File

@ -7,7 +7,7 @@
import Foundation
public struct Tag: Sendable, Codable, QueryStringEncodable, Hashable {
public struct Tag: Sendable, Codable, ParameterConvertible, Hashable {
public var id: Int64?
public var name: String?

View File

@ -7,7 +7,7 @@
import Foundation
public struct TypeHolderDefault: Sendable, Codable, QueryStringEncodable, Hashable {
public struct TypeHolderDefault: Sendable, Codable, ParameterConvertible, Hashable {
public var stringItem: String = "what"
public var numberItem: Double

View File

@ -7,7 +7,7 @@
import Foundation
public struct TypeHolderExample: Sendable, Codable, QueryStringEncodable, Hashable {
public struct TypeHolderExample: Sendable, Codable, ParameterConvertible, Hashable {
public var stringItem: String
public var numberItem: Double

View File

@ -7,7 +7,7 @@
import Foundation
public struct User: Sendable, Codable, QueryStringEncodable, Hashable {
public struct User: Sendable, Codable, ParameterConvertible, Hashable {
public var id: Int64?
public var username: String?

View File

@ -215,7 +215,7 @@ open class FakeAPI {
var localVariableUrlComponents = URLComponents(string: localVariableURLString)
localVariableUrlComponents?.queryItems = APIHelper.mapValuesToQueryItems([
"query": (wrappedValue: query.encodeToQueryString(codableHelper: apiConfiguration.codableHelper), isExplode: false),
"query": (wrappedValue: query.asParameter(codableHelper: apiConfiguration.codableHelper), isExplode: false),
])
let localVariableNillableHeaders: [String: (any Sendable)?] = [
@ -320,20 +320,20 @@ open class FakeAPI {
let localVariablePath = "/fake"
let localVariableURLString = apiConfiguration.basePath + localVariablePath
let localVariableFormParams: [String: (any Sendable)?] = [
"integer": integer?.encodeToQueryString(codableHelper: apiConfiguration.codableHelper),
"int32": int32?.encodeToQueryString(codableHelper: apiConfiguration.codableHelper),
"int64": int64?.encodeToQueryString(codableHelper: apiConfiguration.codableHelper),
"number": number.encodeToQueryString(codableHelper: apiConfiguration.codableHelper),
"float": float?.encodeToQueryString(codableHelper: apiConfiguration.codableHelper),
"double": double.encodeToQueryString(codableHelper: apiConfiguration.codableHelper),
"string": string?.encodeToQueryString(codableHelper: apiConfiguration.codableHelper),
"pattern_without_delimiter": patternWithoutDelimiter.encodeToQueryString(codableHelper: apiConfiguration.codableHelper),
"byte": byte.encodeToQueryString(codableHelper: apiConfiguration.codableHelper),
"binary": binary?.encodeToQueryString(codableHelper: apiConfiguration.codableHelper),
"date": date?.encodeToQueryString(codableHelper: apiConfiguration.codableHelper),
"dateTime": dateTime?.encodeToQueryString(codableHelper: apiConfiguration.codableHelper),
"password": password?.encodeToQueryString(codableHelper: apiConfiguration.codableHelper),
"callback": callback?.encodeToQueryString(codableHelper: apiConfiguration.codableHelper),
"integer": integer?.asParameter(codableHelper: apiConfiguration.codableHelper),
"int32": int32?.asParameter(codableHelper: apiConfiguration.codableHelper),
"int64": int64?.asParameter(codableHelper: apiConfiguration.codableHelper),
"number": number.asParameter(codableHelper: apiConfiguration.codableHelper),
"float": float?.asParameter(codableHelper: apiConfiguration.codableHelper),
"double": double.asParameter(codableHelper: apiConfiguration.codableHelper),
"string": string?.asParameter(codableHelper: apiConfiguration.codableHelper),
"pattern_without_delimiter": patternWithoutDelimiter.asParameter(codableHelper: apiConfiguration.codableHelper),
"byte": byte.asParameter(codableHelper: apiConfiguration.codableHelper),
"binary": binary?.asParameter(codableHelper: apiConfiguration.codableHelper),
"date": date?.asParameter(codableHelper: apiConfiguration.codableHelper),
"dateTime": dateTime?.asParameter(codableHelper: apiConfiguration.codableHelper),
"password": password?.asParameter(codableHelper: apiConfiguration.codableHelper),
"callback": callback?.asParameter(codableHelper: apiConfiguration.codableHelper),
]
let localVariableNonNullParameters = APIHelper.rejectNil(localVariableFormParams)
@ -457,8 +457,8 @@ open class FakeAPI {
let localVariablePath = "/fake"
let localVariableURLString = apiConfiguration.basePath + localVariablePath
let localVariableFormParams: [String: (any Sendable)?] = [
"enum_form_string_array": enumFormStringArray?.encodeToQueryString(codableHelper: apiConfiguration.codableHelper),
"enum_form_string": enumFormString?.encodeToQueryString(codableHelper: apiConfiguration.codableHelper),
"enum_form_string_array": enumFormStringArray?.asParameter(codableHelper: apiConfiguration.codableHelper),
"enum_form_string": enumFormString?.asParameter(codableHelper: apiConfiguration.codableHelper),
]
let localVariableNonNullParameters = APIHelper.rejectNil(localVariableFormParams)
@ -466,16 +466,16 @@ open class FakeAPI {
var localVariableUrlComponents = URLComponents(string: localVariableURLString)
localVariableUrlComponents?.queryItems = APIHelper.mapValuesToQueryItems([
"enum_query_string_array": (wrappedValue: enumQueryStringArray?.encodeToQueryString(codableHelper: apiConfiguration.codableHelper), isExplode: false),
"enum_query_string": (wrappedValue: enumQueryString?.encodeToQueryString(codableHelper: apiConfiguration.codableHelper), isExplode: false),
"enum_query_integer": (wrappedValue: enumQueryInteger?.encodeToQueryString(codableHelper: apiConfiguration.codableHelper), isExplode: false),
"enum_query_double": (wrappedValue: enumQueryDouble?.encodeToQueryString(codableHelper: apiConfiguration.codableHelper), isExplode: false),
"enum_query_string_array": (wrappedValue: enumQueryStringArray?.asParameter(codableHelper: apiConfiguration.codableHelper), isExplode: false),
"enum_query_string": (wrappedValue: enumQueryString?.asParameter(codableHelper: apiConfiguration.codableHelper), isExplode: false),
"enum_query_integer": (wrappedValue: enumQueryInteger?.asParameter(codableHelper: apiConfiguration.codableHelper), isExplode: false),
"enum_query_double": (wrappedValue: enumQueryDouble?.asParameter(codableHelper: apiConfiguration.codableHelper), isExplode: false),
])
let localVariableNillableHeaders: [String: (any Sendable)?] = [
"Content-Type": "application/x-www-form-urlencoded",
"enum_header_string_array": enumHeaderStringArray?.encodeToQueryString(codableHelper: apiConfiguration.codableHelper),
"enum_header_string": enumHeaderString?.encodeToQueryString(codableHelper: apiConfiguration.codableHelper),
"enum_header_string_array": enumHeaderStringArray?.asParameter(codableHelper: apiConfiguration.codableHelper),
"enum_header_string": enumHeaderString?.asParameter(codableHelper: apiConfiguration.codableHelper),
]
let localVariableHeaderParameters = APIHelper.rejectNilHeaders(localVariableNillableHeaders)
@ -522,15 +522,15 @@ open class FakeAPI {
var localVariableUrlComponents = URLComponents(string: localVariableURLString)
localVariableUrlComponents?.queryItems = APIHelper.mapValuesToQueryItems([
"required_string_group": (wrappedValue: requiredStringGroup.encodeToQueryString(codableHelper: apiConfiguration.codableHelper), isExplode: false),
"required_int64_group": (wrappedValue: requiredInt64Group.encodeToQueryString(codableHelper: apiConfiguration.codableHelper), isExplode: false),
"string_group": (wrappedValue: stringGroup?.encodeToQueryString(codableHelper: apiConfiguration.codableHelper), isExplode: false),
"int64_group": (wrappedValue: int64Group?.encodeToQueryString(codableHelper: apiConfiguration.codableHelper), isExplode: false),
"required_string_group": (wrappedValue: requiredStringGroup.asParameter(codableHelper: apiConfiguration.codableHelper), isExplode: false),
"required_int64_group": (wrappedValue: requiredInt64Group.asParameter(codableHelper: apiConfiguration.codableHelper), isExplode: false),
"string_group": (wrappedValue: stringGroup?.asParameter(codableHelper: apiConfiguration.codableHelper), isExplode: false),
"int64_group": (wrappedValue: int64Group?.asParameter(codableHelper: apiConfiguration.codableHelper), isExplode: false),
])
let localVariableNillableHeaders: [String: (any Sendable)?] = [
"required_boolean_group": requiredBooleanGroup.encodeToQueryString(codableHelper: apiConfiguration.codableHelper),
"boolean_group": booleanGroup?.encodeToQueryString(codableHelper: apiConfiguration.codableHelper),
"required_boolean_group": requiredBooleanGroup.asParameter(codableHelper: apiConfiguration.codableHelper),
"boolean_group": booleanGroup?.asParameter(codableHelper: apiConfiguration.codableHelper),
]
let localVariableHeaderParameters = APIHelper.rejectNilHeaders(localVariableNillableHeaders)
@ -602,8 +602,8 @@ open class FakeAPI {
let localVariablePath = "/fake/jsonFormData"
let localVariableURLString = apiConfiguration.basePath + localVariablePath
let localVariableFormParams: [String: (any Sendable)?] = [
"param": param.encodeToQueryString(codableHelper: apiConfiguration.codableHelper),
"param2": param2.encodeToQueryString(codableHelper: apiConfiguration.codableHelper),
"param": param.asParameter(codableHelper: apiConfiguration.codableHelper),
"param2": param2.asParameter(codableHelper: apiConfiguration.codableHelper),
]
let localVariableNonNullParameters = APIHelper.rejectNil(localVariableFormParams)

View File

@ -87,7 +87,7 @@ open class PetAPI {
let localVariableUrlComponents = URLComponents(string: localVariableURLString)
let localVariableNillableHeaders: [String: (any Sendable)?] = [
"api_key": apiKey?.encodeToQueryString(codableHelper: apiConfiguration.codableHelper),
"api_key": apiKey?.asParameter(codableHelper: apiConfiguration.codableHelper),
]
let localVariableHeaderParameters = APIHelper.rejectNilHeaders(localVariableNillableHeaders)
@ -136,7 +136,7 @@ open class PetAPI {
var localVariableUrlComponents = URLComponents(string: localVariableURLString)
localVariableUrlComponents?.queryItems = APIHelper.mapValuesToQueryItems([
"status": (wrappedValue: status.encodeToQueryString(codableHelper: apiConfiguration.codableHelper), isExplode: false),
"status": (wrappedValue: status.asParameter(codableHelper: apiConfiguration.codableHelper), isExplode: false),
])
let localVariableNillableHeaders: [String: (any Sendable)?] = [
@ -182,7 +182,7 @@ open class PetAPI {
var localVariableUrlComponents = URLComponents(string: localVariableURLString)
localVariableUrlComponents?.queryItems = APIHelper.mapValuesToQueryItems([
"tags": (wrappedValue: tags.encodeToQueryString(codableHelper: apiConfiguration.codableHelper), isExplode: false),
"tags": (wrappedValue: tags.asParameter(codableHelper: apiConfiguration.codableHelper), isExplode: false),
])
let localVariableNillableHeaders: [String: (any Sendable)?] = [
@ -313,8 +313,8 @@ open class PetAPI {
localVariablePath = localVariablePath.replacingOccurrences(of: "{petId}", with: petIdPostEscape, options: .literal, range: nil)
let localVariableURLString = apiConfiguration.basePath + localVariablePath
let localVariableFormParams: [String: (any Sendable)?] = [
"name": name?.encodeToQueryString(codableHelper: apiConfiguration.codableHelper),
"status": status?.encodeToQueryString(codableHelper: apiConfiguration.codableHelper),
"name": name?.asParameter(codableHelper: apiConfiguration.codableHelper),
"status": status?.asParameter(codableHelper: apiConfiguration.codableHelper),
]
let localVariableNonNullParameters = APIHelper.rejectNil(localVariableFormParams)
@ -366,8 +366,8 @@ open class PetAPI {
localVariablePath = localVariablePath.replacingOccurrences(of: "{petId}", with: petIdPostEscape, options: .literal, range: nil)
let localVariableURLString = apiConfiguration.basePath + localVariablePath
let localVariableFormParams: [String: (any Sendable)?] = [
"additionalMetadata": additionalMetadata?.encodeToQueryString(codableHelper: apiConfiguration.codableHelper),
"file": file?.encodeToQueryString(codableHelper: apiConfiguration.codableHelper),
"additionalMetadata": additionalMetadata?.asParameter(codableHelper: apiConfiguration.codableHelper),
"file": file?.asParameter(codableHelper: apiConfiguration.codableHelper),
]
let localVariableNonNullParameters = APIHelper.rejectNil(localVariableFormParams)
@ -419,8 +419,8 @@ open class PetAPI {
localVariablePath = localVariablePath.replacingOccurrences(of: "{petId}", with: petIdPostEscape, options: .literal, range: nil)
let localVariableURLString = apiConfiguration.basePath + localVariablePath
let localVariableFormParams: [String: (any Sendable)?] = [
"additionalMetadata": additionalMetadata?.encodeToQueryString(codableHelper: apiConfiguration.codableHelper),
"requiredFile": requiredFile.encodeToQueryString(codableHelper: apiConfiguration.codableHelper),
"additionalMetadata": additionalMetadata?.asParameter(codableHelper: apiConfiguration.codableHelper),
"requiredFile": requiredFile.asParameter(codableHelper: apiConfiguration.codableHelper),
]
let localVariableNonNullParameters = APIHelper.rejectNil(localVariableFormParams)

View File

@ -231,8 +231,8 @@ open class UserAPI {
var localVariableUrlComponents = URLComponents(string: localVariableURLString)
localVariableUrlComponents?.queryItems = APIHelper.mapValuesToQueryItems([
"username": (wrappedValue: username.encodeToQueryString(codableHelper: apiConfiguration.codableHelper), isExplode: false),
"password": (wrappedValue: password.encodeToQueryString(codableHelper: apiConfiguration.codableHelper), isExplode: false),
"username": (wrappedValue: username.asParameter(codableHelper: apiConfiguration.codableHelper), isExplode: false),
"password": (wrappedValue: password.asParameter(codableHelper: apiConfiguration.codableHelper), isExplode: false),
])
let localVariableNillableHeaders: [String: (any Sendable)?] = [

View File

@ -9,78 +9,73 @@ import Foundation
import FoundationNetworking
#endif
extension QueryStringEncodable {
@_disfavoredOverload
func encodeToQueryString(codableHelper: CodableHelper) -> String { String(describing: self) }
extension Bool: ParameterConvertible {
func asParameter(codableHelper: CodableHelper) -> any Sendable { self }
}
extension Bool: QueryStringEncodable {
func encodeToQueryString(codableHelper: CodableHelper) -> String { String(describing: self) }
extension Float: ParameterConvertible {
func asParameter(codableHelper: CodableHelper) -> any Sendable { self }
}
extension Float: QueryStringEncodable {
func encodeToQueryString(codableHelper: CodableHelper) -> String { String(describing: self) }
extension Int: ParameterConvertible {
func asParameter(codableHelper: CodableHelper) -> any Sendable { self }
}
extension Int: QueryStringEncodable {
func encodeToQueryString(codableHelper: CodableHelper) -> String { String(describing: self) }
extension Int32: ParameterConvertible {
func asParameter(codableHelper: CodableHelper) -> any Sendable { self }
}
extension Int32: QueryStringEncodable {
func encodeToQueryString(codableHelper: CodableHelper) -> String { String(describing: self) }
extension Int64: ParameterConvertible {
func asParameter(codableHelper: CodableHelper) -> any Sendable { self }
}
extension Int64: QueryStringEncodable {
func encodeToQueryString(codableHelper: CodableHelper) -> String { String(describing: self) }
extension Double: ParameterConvertible {
func asParameter(codableHelper: CodableHelper) -> any Sendable { self }
}
extension Double: QueryStringEncodable {
func encodeToQueryString(codableHelper: CodableHelper) -> String { String(describing: self) }
extension Decimal: ParameterConvertible {
func asParameter(codableHelper: CodableHelper) -> any Sendable { self }
}
extension Decimal: QueryStringEncodable {
func encodeToQueryString(codableHelper: CodableHelper) -> String { String(describing: self) }
extension String: ParameterConvertible {
func asParameter(codableHelper: CodableHelper) -> any Sendable { self }
}
extension String: QueryStringEncodable {
func encodeToQueryString(codableHelper: CodableHelper) -> String { String(describing: self) }
extension URL: ParameterConvertible {
func asParameter(codableHelper: CodableHelper) -> any Sendable { self }
}
extension URL: QueryStringEncodable {
func encodeToQueryString(codableHelper: CodableHelper) -> String { String(describing: self) }
extension UUID: ParameterConvertible {
func asParameter(codableHelper: CodableHelper) -> any Sendable { self }
}
extension UUID: QueryStringEncodable {
func encodeToQueryString(codableHelper: CodableHelper) -> String { String(describing: self) }
extension RawRepresentable where RawValue: ParameterConvertible, RawValue: Sendable {
func asParameter(codableHelper: CodableHelper) -> any Sendable { return self.rawValue }
}
extension RawRepresentable where RawValue: QueryStringEncodable {
func encodeToQueryString(codableHelper: CodableHelper) -> String { String(describing: rawValue) }
}
private func encodeIfPossible<T>(_ object: T, codableHelper: CodableHelper) -> String {
if let encodableObject = object as? QueryStringEncodable {
return encodableObject.encodeToQueryString(codableHelper: codableHelper)
private func encodeIfPossible<T: Sendable>(_ object: T, codableHelper: CodableHelper) -> any Sendable {
if let encodableObject = object as? ParameterConvertible {
return encodableObject.asParameter(codableHelper: codableHelper)
} else {
return String(describing: object)
return object
}
}
extension Array {
func encodeToQueryString(codableHelper: CodableHelper) -> [String] {
extension Array where Element: Sendable {
func asParameter(codableHelper: CodableHelper) -> any Sendable {
return self.map { encodeIfPossible($0, codableHelper: codableHelper) }
}
}
extension Set {
func encodeToQueryString(codableHelper: CodableHelper) -> [String] {
return Array(self).encodeToQueryString(codableHelper: codableHelper)
extension Set where Element: Sendable {
func asParameter(codableHelper: CodableHelper) -> any Sendable {
return Array(self).asParameter(codableHelper: codableHelper)
}
}
extension Dictionary {
func encodeToQueryString(codableHelper: CodableHelper) -> [Key: String] {
var dictionary = [Key: String]()
extension Dictionary where Key: Sendable, Value: Sendable {
func asParameter(codableHelper: CodableHelper) -> any Sendable {
var dictionary = [Key: any Sendable]()
for (key, value) in self {
dictionary[key] = encodeIfPossible(value, codableHelper: codableHelper)
}
@ -88,24 +83,24 @@ extension Dictionary {
}
}
extension Data: QueryStringEncodable {
func encodeToQueryString(codableHelper: CodableHelper) -> String {
extension Data: ParameterConvertible {
func asParameter(codableHelper: CodableHelper) -> any Sendable {
return self.base64EncodedString(options: Data.Base64EncodingOptions())
}
}
extension Date: QueryStringEncodable {
func encodeToQueryString(codableHelper: CodableHelper) -> String {
extension Date: ParameterConvertible {
func asParameter(codableHelper: CodableHelper) -> any Sendable {
return codableHelper.dateFormatter.string(from: self)
}
}
extension QueryStringEncodable where Self: Encodable {
func encodeToQueryString(codableHelper: CodableHelper) -> String {
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.encodeToQueryString(codableHelper: codableHelper)
return data.asParameter(codableHelper: codableHelper)
}
}

View File

@ -9,8 +9,8 @@ import Foundation
import FoundationNetworking
#endif
protocol QueryStringEncodable {
func encodeToQueryString(codableHelper: CodableHelper) -> String
protocol ParameterConvertible {
func asParameter(codableHelper: CodableHelper) -> any Sendable
}
/// An enum where the last case value can be used as a default catch-all.

View File

@ -7,7 +7,7 @@
import Foundation
public struct AdditionalPropertiesClass: Sendable, Codable, QueryStringEncodable, Hashable {
public struct AdditionalPropertiesClass: Sendable, Codable, ParameterConvertible, Hashable {
public var mapString: [String: String]?
public var mapMapString: [String: [String: String]]?

View File

@ -7,7 +7,7 @@
import Foundation
public struct Animal: Sendable, Codable, QueryStringEncodable, Hashable {
public struct Animal: Sendable, Codable, ParameterConvertible, Hashable {
public var className: String
public var color: String? = "red"

View File

@ -7,7 +7,7 @@
import Foundation
public struct ApiResponse: Sendable, Codable, QueryStringEncodable, Hashable {
public struct ApiResponse: Sendable, Codable, ParameterConvertible, Hashable {
public var code: Int?
public var type: String?

Some files were not shown because too many files have changed in this diff Show More