mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-12-10 01:36:15 +00:00
Fix enum encodable (#4594)
This commit is contained in:
committed by
William Cheng
parent
df682aba99
commit
8cc7befbf3
@@ -223,7 +223,7 @@ open class FakeAPI {
|
||||
|
||||
var url = URLComponents(string: URLString)
|
||||
url?.queryItems = APIHelper.mapValuesToQueryItems([
|
||||
"query": query
|
||||
"query": query.encodeToJSON()
|
||||
])
|
||||
|
||||
let requestBuilder: RequestBuilder<Void>.Type = PetstoreClientAPI.requestBuilderFactory.getNonDecodableBuilder()
|
||||
@@ -331,17 +331,17 @@ open class FakeAPI {
|
||||
"integer": integer?.encodeToJSON(),
|
||||
"int32": int32?.encodeToJSON(),
|
||||
"int64": int64?.encodeToJSON(),
|
||||
"number": number,
|
||||
"float": float,
|
||||
"double": double,
|
||||
"string": string,
|
||||
"pattern_without_delimiter": patternWithoutDelimiter,
|
||||
"byte": byte,
|
||||
"binary": binary,
|
||||
"number": number.encodeToJSON(),
|
||||
"float": float?.encodeToJSON(),
|
||||
"double": double.encodeToJSON(),
|
||||
"string": string?.encodeToJSON(),
|
||||
"pattern_without_delimiter": patternWithoutDelimiter.encodeToJSON(),
|
||||
"byte": byte.encodeToJSON(),
|
||||
"binary": binary?.encodeToJSON(),
|
||||
"date": date?.encodeToJSON(),
|
||||
"dateTime": dateTime?.encodeToJSON(),
|
||||
"password": password,
|
||||
"callback": callback
|
||||
"password": password?.encodeToJSON(),
|
||||
"callback": callback?.encodeToJSON()
|
||||
]
|
||||
|
||||
let nonNullParameters = APIHelper.rejectNil(formParams)
|
||||
@@ -464,8 +464,8 @@ open class FakeAPI {
|
||||
let path = "/fake"
|
||||
let URLString = PetstoreClientAPI.basePath + path
|
||||
let formParams: [String: Any?] = [
|
||||
"enum_form_string_array": enumFormStringArray,
|
||||
"enum_form_string": enumFormString?.rawValue
|
||||
"enum_form_string_array": enumFormStringArray?.encodeToJSON(),
|
||||
"enum_form_string": enumFormString?.encodeToJSON()
|
||||
]
|
||||
|
||||
let nonNullParameters = APIHelper.rejectNil(formParams)
|
||||
@@ -473,14 +473,14 @@ open class FakeAPI {
|
||||
|
||||
var url = URLComponents(string: URLString)
|
||||
url?.queryItems = APIHelper.mapValuesToQueryItems([
|
||||
"enum_query_string_array": enumQueryStringArray,
|
||||
"enum_query_string": enumQueryString?.rawValue,
|
||||
"enum_query_integer": enumQueryInteger?.rawValue,
|
||||
"enum_query_double": enumQueryDouble?.rawValue
|
||||
"enum_query_string_array": enumQueryStringArray?.encodeToJSON(),
|
||||
"enum_query_string": enumQueryString?.encodeToJSON(),
|
||||
"enum_query_integer": enumQueryInteger?.encodeToJSON(),
|
||||
"enum_query_double": enumQueryDouble?.encodeToJSON()
|
||||
])
|
||||
let nillableHeaders: [String: Any?] = [
|
||||
"enum_header_string_array": enumHeaderStringArray,
|
||||
"enum_header_string": enumHeaderString?.rawValue
|
||||
"enum_header_string_array": enumHeaderStringArray?.encodeToJSON(),
|
||||
"enum_header_string": enumHeaderString?.encodeToJSON()
|
||||
]
|
||||
let headerParameters = APIHelper.rejectNilHeaders(nillableHeaders)
|
||||
|
||||
@@ -537,8 +537,8 @@ open class FakeAPI {
|
||||
"int64_group": int64Group?.encodeToJSON()
|
||||
])
|
||||
let nillableHeaders: [String: Any?] = [
|
||||
"required_boolean_group": requiredBooleanGroup,
|
||||
"boolean_group": booleanGroup
|
||||
"required_boolean_group": requiredBooleanGroup.encodeToJSON(),
|
||||
"boolean_group": booleanGroup?.encodeToJSON()
|
||||
]
|
||||
let headerParameters = APIHelper.rejectNilHeaders(nillableHeaders)
|
||||
|
||||
@@ -613,8 +613,8 @@ open class FakeAPI {
|
||||
let path = "/fake/jsonFormData"
|
||||
let URLString = PetstoreClientAPI.basePath + path
|
||||
let formParams: [String: Any?] = [
|
||||
"param": param,
|
||||
"param2": param2
|
||||
"param": param.encodeToJSON(),
|
||||
"param2": param2.encodeToJSON()
|
||||
]
|
||||
|
||||
let nonNullParameters = APIHelper.rejectNil(formParams)
|
||||
|
||||
@@ -87,7 +87,7 @@ open class PetAPI {
|
||||
|
||||
let url = URLComponents(string: URLString)
|
||||
let nillableHeaders: [String: Any?] = [
|
||||
"api_key": apiKey
|
||||
"api_key": apiKey?.encodeToJSON()
|
||||
]
|
||||
let headerParameters = APIHelper.rejectNilHeaders(nillableHeaders)
|
||||
|
||||
@@ -142,7 +142,7 @@ open class PetAPI {
|
||||
|
||||
var url = URLComponents(string: URLString)
|
||||
url?.queryItems = APIHelper.mapValuesToQueryItems([
|
||||
"status": status
|
||||
"status": status.encodeToJSON()
|
||||
])
|
||||
|
||||
let requestBuilder: RequestBuilder<[Pet]>.Type = PetstoreClientAPI.requestBuilderFactory.getBuilder()
|
||||
@@ -187,7 +187,7 @@ open class PetAPI {
|
||||
|
||||
var url = URLComponents(string: URLString)
|
||||
url?.queryItems = APIHelper.mapValuesToQueryItems([
|
||||
"tags": tags
|
||||
"tags": tags.encodeToJSON()
|
||||
])
|
||||
|
||||
let requestBuilder: RequestBuilder<[Pet]>.Type = PetstoreClientAPI.requestBuilderFactory.getBuilder()
|
||||
@@ -317,8 +317,8 @@ open class PetAPI {
|
||||
path = path.replacingOccurrences(of: "{petId}", with: petIdPostEscape, options: .literal, range: nil)
|
||||
let URLString = PetstoreClientAPI.basePath + path
|
||||
let formParams: [String: Any?] = [
|
||||
"name": name,
|
||||
"status": status
|
||||
"name": name?.encodeToJSON(),
|
||||
"status": status?.encodeToJSON()
|
||||
]
|
||||
|
||||
let nonNullParameters = APIHelper.rejectNil(formParams)
|
||||
@@ -371,8 +371,8 @@ open class PetAPI {
|
||||
path = path.replacingOccurrences(of: "{petId}", with: petIdPostEscape, options: .literal, range: nil)
|
||||
let URLString = PetstoreClientAPI.basePath + path
|
||||
let formParams: [String: Any?] = [
|
||||
"additionalMetadata": additionalMetadata,
|
||||
"file": file
|
||||
"additionalMetadata": additionalMetadata?.encodeToJSON(),
|
||||
"file": file?.encodeToJSON()
|
||||
]
|
||||
|
||||
let nonNullParameters = APIHelper.rejectNil(formParams)
|
||||
@@ -425,8 +425,8 @@ open class PetAPI {
|
||||
path = path.replacingOccurrences(of: "{petId}", with: petIdPostEscape, options: .literal, range: nil)
|
||||
let URLString = PetstoreClientAPI.basePath + path
|
||||
let formParams: [String: Any?] = [
|
||||
"additionalMetadata": additionalMetadata,
|
||||
"requiredFile": requiredFile
|
||||
"additionalMetadata": additionalMetadata?.encodeToJSON(),
|
||||
"requiredFile": requiredFile.encodeToJSON()
|
||||
]
|
||||
|
||||
let nonNullParameters = APIHelper.rejectNil(formParams)
|
||||
|
||||
@@ -235,8 +235,8 @@ open class UserAPI {
|
||||
|
||||
var url = URLComponents(string: URLString)
|
||||
url?.queryItems = APIHelper.mapValuesToQueryItems([
|
||||
"username": username,
|
||||
"password": password
|
||||
"username": username.encodeToJSON(),
|
||||
"password": password.encodeToJSON()
|
||||
])
|
||||
|
||||
let requestBuilder: RequestBuilder<String>.Type = PetstoreClientAPI.requestBuilderFactory.getBuilder()
|
||||
|
||||
@@ -35,6 +35,10 @@ extension String: JSONEncodable {
|
||||
func encodeToJSON() -> Any { return self as Any }
|
||||
}
|
||||
|
||||
extension RawRepresentable where RawValue: JSONEncodable {
|
||||
func encodeToJSON() -> Any { return self.rawValue as Any }
|
||||
}
|
||||
|
||||
private func encodeIfPossible<T>(_ object: T) -> Any {
|
||||
if let encodableObject = object as? JSONEncodable {
|
||||
return encodableObject.encodeToJSON()
|
||||
@@ -84,6 +88,12 @@ extension Date: JSONEncodable {
|
||||
}
|
||||
}
|
||||
|
||||
extension URL: JSONEncodable {
|
||||
func encodeToJSON() -> Any {
|
||||
return self
|
||||
}
|
||||
}
|
||||
|
||||
extension UUID: JSONEncodable {
|
||||
func encodeToJSON() -> Any {
|
||||
return self.uuidString
|
||||
|
||||
Reference in New Issue
Block a user