forked from loafle/openapi-generator-original
Fix enum encodable (#4594)
This commit is contained in:
committed by
William Cheng
parent
df682aba99
commit
8cc7befbf3
@@ -235,7 +235,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()
|
||||
@@ -347,17 +347,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)
|
||||
@@ -482,8 +482,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)
|
||||
@@ -491,14 +491,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)
|
||||
|
||||
@@ -557,8 +557,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)
|
||||
|
||||
@@ -637,8 +637,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)
|
||||
|
||||
@@ -91,7 +91,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)
|
||||
|
||||
@@ -148,7 +148,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()
|
||||
@@ -195,7 +195,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()
|
||||
@@ -331,8 +331,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)
|
||||
@@ -387,8 +387,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)
|
||||
@@ -443,8 +443,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)
|
||||
|
||||
@@ -247,8 +247,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()
|
||||
|
||||
@@ -34,6 +34,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()
|
||||
@@ -83,6 +87,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