forked from loafle/openapi-generator-original
WIP
This commit is contained in:
parent
a0ba71e3f2
commit
250d49c8e8
@ -31,12 +31,16 @@ ags="generate -t modules/openapi-generator/src/main/resources/swift5 -i modules/
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
|
||||
cd samples/client/petstore/swift5/promisekit
|
||||
|
||||
if type "xcodegen" > /dev/null 2>&1; then
|
||||
cd samples/client/petstore/swift5/promisekit
|
||||
xcodegen generate
|
||||
|
||||
if type "carthage" > /dev/null 2>&1; then
|
||||
carthage update --no-use-binaries --platform ios --cache-builds
|
||||
fi
|
||||
fi
|
||||
|
||||
if type "swiftlint" > /dev/null 2>&1; then
|
||||
cd samples/client/petstore/swift5/promisekit
|
||||
swiftlint autocorrect --quiet
|
||||
fi
|
||||
fi
|
@ -31,12 +31,16 @@ ags="generate -t modules/openapi-generator/src/main/resources/swift5 -i modules/
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
|
||||
cd samples/client/petstore/swift5/rxswift
|
||||
|
||||
if type "xcodegen" > /dev/null 2>&1; then
|
||||
cd samples/client/petstore/swift5/rxswift
|
||||
xcodegen generate
|
||||
|
||||
if type "carthage" > /dev/null 2>&1; then
|
||||
carthage update --no-use-binaries --platform ios --cache-builds
|
||||
fi
|
||||
fi
|
||||
|
||||
if type "swiftlint" > /dev/null 2>&1; then
|
||||
cd samples/client/petstore/swift5/promisekit
|
||||
swiftlint autocorrect --quiet
|
||||
fi
|
@ -31,12 +31,16 @@ ags="generate -t modules/openapi-generator/src/main/resources/swift5 -i modules/
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
|
||||
cd samples/client/petstore/swift5/unwrapRequired
|
||||
|
||||
if type "xcodegen" > /dev/null 2>&1; then
|
||||
cd samples/client/petstore/swift5/unwrapRequired
|
||||
xcodegen generate
|
||||
|
||||
if type "carthage" > /dev/null 2>&1; then
|
||||
carthage update --no-use-binaries --platform ios --cache-builds
|
||||
fi
|
||||
fi
|
||||
|
||||
if type "swiftlint" > /dev/null 2>&1; then
|
||||
cd samples/client/petstore/swift5/promisekit
|
||||
swiftlint autocorrect --quiet
|
||||
fi
|
@ -31,12 +31,16 @@ ags="generate -t modules/openapi-generator/src/main/resources/swift5 -i modules/
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
|
||||
cd samples/client/petstore/swift5/default
|
||||
|
||||
if type "xcodegen" > /dev/null 2>&1; then
|
||||
cd samples/client/petstore/swift5/default
|
||||
xcodegen generate
|
||||
|
||||
if type "carthage" > /dev/null 2>&1; then
|
||||
carthage update --no-use-binaries --platform ios --cache-builds
|
||||
fi
|
||||
fi
|
||||
|
||||
if type "swiftlint" > /dev/null 2>&1; then
|
||||
cd samples/client/petstore/swift5/promisekit
|
||||
swiftlint autocorrect --quiet
|
||||
fi
|
@ -31,12 +31,16 @@ ags="generate -t modules/openapi-generator/src/main/resources/swift5 -i modules/
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
|
||||
cd samples/client/test/swift5default
|
||||
|
||||
if type "xcodegen" > /dev/null 2>&1; then
|
||||
cd samples/client/test/swift5default
|
||||
xcodegen generate
|
||||
|
||||
if type "carthage" > /dev/null 2>&1; then
|
||||
carthage update --no-use-binaries --platform ios --cache-builds
|
||||
fi
|
||||
fi
|
||||
|
||||
if type "swiftlint" > /dev/null 2>&1; then
|
||||
cd samples/client/petstore/swift5/promisekit
|
||||
swiftlint autocorrect --quiet
|
||||
fi
|
@ -9,10 +9,10 @@ import Foundation
|
||||
public struct RequestBuilder<Response> {
|
||||
public let endpoint: String
|
||||
public let method: String
|
||||
public let parameters: [Parameters]
|
||||
public let parameters: Parameters?
|
||||
public let headers: [String : String]
|
||||
|
||||
public init(endpoint: String, method: String, parameters: [Parameters] = [], headers: [String : String] = [:]) {
|
||||
public init(endpoint: String, method: String, parameters: Parameters? = nil, headers: [String : String] = [:]) {
|
||||
self.endpoint = endpoint
|
||||
self.method = method
|
||||
self.parameters = parameters
|
||||
@ -20,24 +20,19 @@ public struct RequestBuilder<Response> {
|
||||
}
|
||||
}
|
||||
|
||||
public enum Parameters {
|
||||
case query([String: Any?])
|
||||
case form([String: String?])
|
||||
case json(AnyEncodable)
|
||||
public struct Parameters {
|
||||
var query: [String: Any?]? = nil
|
||||
var form: [String: String?]? = nil
|
||||
var body: AnyEncodable? = nil
|
||||
|
||||
public init(_ raw: [String: Any?]) {
|
||||
self = .query(raw)
|
||||
}
|
||||
|
||||
public init(_ raw: [String: String?]) {
|
||||
self = .form(raw)
|
||||
}
|
||||
|
||||
public init<T: Encodable>(_ raw: T) {
|
||||
self = .json(AnyEncodable(raw))
|
||||
public init(query: [String: Any?]? = nil, form: [String: String?]? = nil, body: AnyEncodable? = nil) {
|
||||
self.query = query
|
||||
self.form = form
|
||||
self.body = body
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public struct AnyEncodable: Encodable {
|
||||
var encode: (Encoder) throws -> Void
|
||||
|
||||
|
@ -58,32 +58,12 @@ public struct {{classname}} {
|
||||
let {{paramName}}Escaped = "\({{#isEnum}}{{paramName}}{{#isContainer}}{{{dataType}}}{{/isContainer}}{{^isContainer}}.rawValue{{/isContainer}}{{/isEnum}}{{^isEnum}}{{paramName}})".addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""{{/isEnum}}
|
||||
path = path.replacingOccurrences(of: "{{=<% %>=}}{<%baseName%>}<%={{ }}=%>", with: {{paramName}}Escaped, options: .literal, range: nil){{/pathParams}}
|
||||
{{#hasParams}}
|
||||
{{#hasFormParams}}var parameters: [Parameters] = []{{/hasFormParams}}
|
||||
{{^hasFormParams}}{{#hasQueryParams}}var parameters: [Parameters] = []{{/hasQueryParams}}{{/hasFormParams}}
|
||||
{{^hasQueryParams}}{{#hasBodyParam}}var parameters: [Parameters] = []{{/hasBodyParam}}{{/hasQueryParams}}
|
||||
|
||||
{{#bodyParam}}
|
||||
parameters.append(Parameters({{paramName}}))
|
||||
{{/bodyParam}}
|
||||
{{^bodyParam}}
|
||||
{{#hasFormParams}}
|
||||
let formParams: [String: String?] = [
|
||||
{{#formParams}}
|
||||
"{{baseName}}": {{paramName}}{{#isContainer}}{{^required}}?{{/required}}.description{{/isContainer}}{{^isContainer}}{{#isEnum}}{{^required}}?{{/required}}.rawValue{{/isEnum}}{{^isString}}{{^required}}?{{/required}}.description{{/isString}}{{/isContainer}}{{#hasMore}}, {{/hasMore}}
|
||||
{{/formParams}}
|
||||
]
|
||||
parameters.append(Parameters(formParams))
|
||||
{{/hasFormParams}}
|
||||
{{/bodyParam}}
|
||||
|
||||
{{#hasQueryParams}}
|
||||
let queryParams: [String: Any?] = [
|
||||
{{#queryParams}}
|
||||
"{{baseName}}": {{paramName}}{{#hasMore}}, {{/hasMore}}
|
||||
{{/queryParams}}
|
||||
]
|
||||
parameters.append(Parameters(queryParams)){{/hasQueryParams}}{{/hasParams}}
|
||||
return RequestBuilder<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Void{{/returnType}}>(endpoint: path, method: "{{httpMethod}}"{{#hasParams}}{{#hasFormParams}}, parameters: parameters{{/hasFormParams}}{{^hasFormParams}}{{#hasQueryParams}}, parameters: parameters{{/hasQueryParams}}{{/hasFormParams}}{{^hasQueryParams}}{{#hasBodyParam}}, parameters: parameters{{/hasBodyParam}}{{/hasQueryParams}}{{/hasParams}})
|
||||
let parameters = Parameters(
|
||||
{{#hasQueryParams}}query: [{{#queryParams}}"{{baseName}}": {{paramName}}{{#hasMore}}, {{/hasMore}}{{/queryParams}}]{{/hasQueryParams}}{{^hasQueryParams}}query: nil{{/hasQueryParams}},
|
||||
{{#hasFormParams}}form: [{{#formParams}}"{{baseName}}": {{paramName}}{{#isContainer}}{{^required}}?{{/required}}.description{{/isContainer}}{{^isContainer}}{{#isEnum}}{{^required}}?{{/required}}.rawValue{{/isEnum}}{{^isString}}{{^required}}?{{/required}}.description{{/isString}}{{/isContainer}}{{#hasMore}}, {{/hasMore}}{{/formParams}}]{{/hasFormParams}}{{^hasFormParams}}form: nil{{/hasFormParams}},
|
||||
{{#bodyParam}}body: AnyEncodable({{paramName}}){{/bodyParam}}{{^bodyParam}}body: nil{{/bodyParam}})
|
||||
{{/hasParams}}
|
||||
return RequestBuilder<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Void{{/returnType}}>(endpoint: path, method: "{{httpMethod}}"{{#hasParams}}, parameters: parameters{{/hasParams}})
|
||||
}
|
||||
|
||||
{{/operation}}
|
||||
|
@ -43,13 +43,12 @@ playground.xcworkspace
|
||||
# you should judge for yourself, the pros and cons are mentioned at:
|
||||
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
||||
#
|
||||
# Pods/
|
||||
Pods/
|
||||
|
||||
# Carthage
|
||||
#
|
||||
# Add this line if you want to avoid checking in source code from Carthage dependencies.
|
||||
# Carthage/Checkouts
|
||||
|
||||
Carthage/Checkouts
|
||||
Carthage/Build
|
||||
|
||||
# fastlane
|
||||
|
@ -43,13 +43,12 @@ playground.xcworkspace
|
||||
# you should judge for yourself, the pros and cons are mentioned at:
|
||||
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
||||
#
|
||||
# Pods/
|
||||
Pods/
|
||||
|
||||
# Carthage
|
||||
#
|
||||
# Add this line if you want to avoid checking in source code from Carthage dependencies.
|
||||
# Carthage/Checkouts
|
||||
|
||||
Carthage/Checkouts
|
||||
Carthage/Build
|
||||
|
||||
# fastlane
|
||||
|
@ -323,7 +323,10 @@
|
||||
INFOPLIST_FILE = Info.plist;
|
||||
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
|
||||
LD_RUNPATH_SEARCH_PATHS = (
|
||||
"$(inherited)",
|
||||
"@executable_path/Frameworks",
|
||||
);
|
||||
SDKROOT = iphoneos;
|
||||
SKIP_INSTALL = YES;
|
||||
SWIFT_VERSION = 5.0;
|
||||
@ -404,7 +407,10 @@
|
||||
INFOPLIST_FILE = Info.plist;
|
||||
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
|
||||
LD_RUNPATH_SEARCH_PATHS = (
|
||||
"$(inherited)",
|
||||
"@executable_path/Frameworks",
|
||||
);
|
||||
SDKROOT = iphoneos;
|
||||
SKIP_INSTALL = YES;
|
||||
SWIFT_VERSION = 5.0;
|
||||
|
@ -0,0 +1,39 @@
|
||||
//
|
||||
// APIClient.swift
|
||||
// PetstoreClient
|
||||
//
|
||||
// Created by dmatsudate on 2019/07/23.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import Alamofire
|
||||
|
||||
public class APIClient<Response> {
|
||||
|
||||
public let baseURL: URL
|
||||
public let headers: [AnyHashable: Any]
|
||||
|
||||
private let sessionManager: SessionManager
|
||||
private let queue = DispatchQueue(label: "com.open-api-generator.api-client", qos: .userInitiated)
|
||||
|
||||
public init(baseURL: URL, headers: [AnyHashable: Any] = [:]) {
|
||||
self.baseURL = baseURL
|
||||
self.headers = headers
|
||||
|
||||
let config: URLSessionConfiguration = .ephemeral
|
||||
config.httpAdditionalHeaders = headers
|
||||
self.sessionManager = SessionManager(configuration: config)
|
||||
}
|
||||
|
||||
func perform(request: RequestBuilder<Response>, completion: (Result<Response, Error>) -> Void) {
|
||||
queue.async { [weak self] in
|
||||
guard let self = self else { return }
|
||||
|
||||
self?.session
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -9,10 +9,10 @@ import Foundation
|
||||
public struct RequestBuilder<Response> {
|
||||
public let endpoint: String
|
||||
public let method: String
|
||||
public let parameters: [Parameters]
|
||||
public let parameters: Parameters?
|
||||
public let headers: [String: String]
|
||||
|
||||
public init(endpoint: String, method: String, parameters: [Parameters] = [], headers: [String: String] = [:]) {
|
||||
public init(endpoint: String, method: String, parameters: Parameters? = nil, headers: [String: String] = [:]) {
|
||||
self.endpoint = endpoint
|
||||
self.method = method
|
||||
self.parameters = parameters
|
||||
@ -20,21 +20,15 @@ public struct RequestBuilder<Response> {
|
||||
}
|
||||
}
|
||||
|
||||
public enum Parameters {
|
||||
case query([String: Any?])
|
||||
case form([String: String?])
|
||||
case json(AnyEncodable)
|
||||
public struct Parameters {
|
||||
var query: [String: Any?]?
|
||||
var form: [String: String?]?
|
||||
var body: AnyEncodable?
|
||||
|
||||
public init(_ raw: [String: Any?]) {
|
||||
self = .query(raw)
|
||||
}
|
||||
|
||||
public init(_ raw: [String: String?]) {
|
||||
self = .form(raw)
|
||||
}
|
||||
|
||||
public init<T: Encodable>(_ raw: T) {
|
||||
self = .json(AnyEncodable(raw))
|
||||
public init(query: [String: Any?]? = nil, form: [String: String?]? = nil, body: AnyEncodable? = nil) {
|
||||
self.query = query
|
||||
self.form = form
|
||||
self.body = body
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -17,11 +17,10 @@ public struct AnotherFakeAPI {
|
||||
*/
|
||||
public func call123testSpecialTags(body: Client) -> RequestBuilder<Client> {
|
||||
let path = "/another-fake/dummy"
|
||||
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
parameters.append(Parameters(body))
|
||||
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: nil,
|
||||
body: AnyEncodable(body))
|
||||
return RequestBuilder<Client>(endpoint: path, method: "PATCH", parameters: parameters)
|
||||
}
|
||||
|
||||
|
@ -16,11 +16,10 @@ public struct FakeAPI {
|
||||
*/
|
||||
public func fakeOuterBooleanSerialize(body: Bool? = nil) -> RequestBuilder<Bool> {
|
||||
let path = "/fake/outer/boolean"
|
||||
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
parameters.append(Parameters(body))
|
||||
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: nil,
|
||||
body: AnyEncodable(body))
|
||||
return RequestBuilder<Bool>(endpoint: path, method: "POST", parameters: parameters)
|
||||
}
|
||||
|
||||
@ -32,11 +31,10 @@ public struct FakeAPI {
|
||||
*/
|
||||
public func fakeOuterCompositeSerialize(body: OuterComposite? = nil) -> RequestBuilder<OuterComposite> {
|
||||
let path = "/fake/outer/composite"
|
||||
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
parameters.append(Parameters(body))
|
||||
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: nil,
|
||||
body: AnyEncodable(body))
|
||||
return RequestBuilder<OuterComposite>(endpoint: path, method: "POST", parameters: parameters)
|
||||
}
|
||||
|
||||
@ -48,11 +46,10 @@ public struct FakeAPI {
|
||||
*/
|
||||
public func fakeOuterNumberSerialize(body: Double? = nil) -> RequestBuilder<Double> {
|
||||
let path = "/fake/outer/number"
|
||||
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
parameters.append(Parameters(body))
|
||||
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: nil,
|
||||
body: AnyEncodable(body))
|
||||
return RequestBuilder<Double>(endpoint: path, method: "POST", parameters: parameters)
|
||||
}
|
||||
|
||||
@ -64,11 +61,10 @@ public struct FakeAPI {
|
||||
*/
|
||||
public func fakeOuterStringSerialize(body: String? = nil) -> RequestBuilder<String> {
|
||||
let path = "/fake/outer/string"
|
||||
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
parameters.append(Parameters(body))
|
||||
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: nil,
|
||||
body: AnyEncodable(body))
|
||||
return RequestBuilder<String>(endpoint: path, method: "POST", parameters: parameters)
|
||||
}
|
||||
|
||||
@ -80,11 +76,10 @@ public struct FakeAPI {
|
||||
*/
|
||||
public func testBodyWithFileSchema(body: FileSchemaTestClass) -> RequestBuilder<Void> {
|
||||
let path = "/fake/body-with-file-schema"
|
||||
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
parameters.append(Parameters(body))
|
||||
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: nil,
|
||||
body: AnyEncodable(body))
|
||||
return RequestBuilder<Void>(endpoint: path, method: "PUT", parameters: parameters)
|
||||
}
|
||||
|
||||
@ -96,15 +91,10 @@ public struct FakeAPI {
|
||||
*/
|
||||
public func testBodyWithQueryParams(query: String, body: User) -> RequestBuilder<Void> {
|
||||
let path = "/fake/body-with-query-params"
|
||||
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
parameters.append(Parameters(body))
|
||||
|
||||
let queryParams: [String: Any?] = [
|
||||
"query": query
|
||||
]
|
||||
parameters.append(Parameters(queryParams))
|
||||
let parameters = Parameters(
|
||||
query: ["query": query],
|
||||
form: nil,
|
||||
body: AnyEncodable(body))
|
||||
return RequestBuilder<Void>(endpoint: path, method: "PUT", parameters: parameters)
|
||||
}
|
||||
|
||||
@ -117,11 +107,10 @@ public struct FakeAPI {
|
||||
*/
|
||||
public func testClientModel(body: Client) -> RequestBuilder<Client> {
|
||||
let path = "/fake"
|
||||
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
parameters.append(Parameters(body))
|
||||
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: nil,
|
||||
body: AnyEncodable(body))
|
||||
return RequestBuilder<Client>(endpoint: path, method: "PATCH", parameters: parameters)
|
||||
}
|
||||
|
||||
@ -150,26 +139,10 @@ public struct FakeAPI {
|
||||
*/
|
||||
public func testEndpointParameters(number: Double, double: Double, patternWithoutDelimiter: String, byte: Data, integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, float: Float? = nil, string: String? = nil, binary: URL? = nil, date: Date? = nil, dateTime: Date? = nil, password: String? = nil, callback: String? = nil) -> RequestBuilder<Void> {
|
||||
let path = "/fake"
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
let formParams: [String: String?] = [
|
||||
"integer": integer?.description,
|
||||
"int32": int32?.description,
|
||||
"int64": int64?.description,
|
||||
"number": number.description,
|
||||
"float": float?.description,
|
||||
"double": double.description,
|
||||
"string": string,
|
||||
"pattern_without_delimiter": patternWithoutDelimiter,
|
||||
"byte": byte.description,
|
||||
"binary": binary?.description,
|
||||
"date": date?.description,
|
||||
"dateTime": dateTime?.description,
|
||||
"password": password,
|
||||
"callback": callback
|
||||
]
|
||||
parameters.append(Parameters(formParams))
|
||||
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: ["integer": integer?.description, "int32": int32?.description, "int64": int64?.description, "number": number.description, "float": float?.description, "double": double.description, "string": string, "pattern_without_delimiter": patternWithoutDelimiter, "byte": byte.description, "binary": binary?.description, "date": date?.description, "dateTime": dateTime?.description, "password": password, "callback": callback],
|
||||
body: nil)
|
||||
return RequestBuilder<Void>(endpoint: path, method: "POST", parameters: parameters)
|
||||
}
|
||||
|
||||
@ -256,21 +229,10 @@ public struct FakeAPI {
|
||||
*/
|
||||
public func testEnumParameters(enumHeaderStringArray: [String]? = nil, enumHeaderString: EnumHeaderString_testEnumParameters? = nil, enumQueryStringArray: [String]? = nil, enumQueryString: EnumQueryString_testEnumParameters? = nil, enumQueryInteger: EnumQueryInteger_testEnumParameters? = nil, enumQueryDouble: EnumQueryDouble_testEnumParameters? = nil, enumFormStringArray: [String]? = nil, enumFormString: EnumFormString_testEnumParameters? = nil) -> RequestBuilder<Void> {
|
||||
let path = "/fake"
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
let formParams: [String: String?] = [
|
||||
"enum_form_string_array": enumFormStringArray?.description,
|
||||
"enum_form_string": enumFormString?.rawValue
|
||||
]
|
||||
parameters.append(Parameters(formParams))
|
||||
|
||||
let queryParams: [String: Any?] = [
|
||||
"enum_query_string_array": enumQueryStringArray,
|
||||
"enum_query_string": enumQueryString,
|
||||
"enum_query_integer": enumQueryInteger,
|
||||
"enum_query_double": enumQueryDouble
|
||||
]
|
||||
parameters.append(Parameters(queryParams))
|
||||
let parameters = Parameters(
|
||||
query: ["enum_query_string_array": enumQueryStringArray, "enum_query_string": enumQueryString, "enum_query_integer": enumQueryInteger, "enum_query_double": enumQueryDouble],
|
||||
form: ["enum_form_string_array": enumFormStringArray?.description, "enum_form_string": enumFormString?.rawValue],
|
||||
body: nil)
|
||||
return RequestBuilder<Void>(endpoint: path, method: "GET", parameters: parameters)
|
||||
}
|
||||
|
||||
@ -288,16 +250,10 @@ public struct FakeAPI {
|
||||
*/
|
||||
public func testGroupParameters(requiredStringGroup: Int, requiredBooleanGroup: Bool, requiredInt64Group: Int64, stringGroup: Int? = nil, booleanGroup: Bool? = nil, int64Group: Int64? = nil) -> RequestBuilder<Void> {
|
||||
let path = "/fake"
|
||||
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
let queryParams: [String: Any?] = [
|
||||
"required_string_group": requiredStringGroup,
|
||||
"required_int64_group": requiredInt64Group,
|
||||
"string_group": stringGroup,
|
||||
"int64_group": int64Group
|
||||
]
|
||||
parameters.append(Parameters(queryParams))
|
||||
let parameters = Parameters(
|
||||
query: ["required_string_group": requiredStringGroup, "required_int64_group": requiredInt64Group, "string_group": stringGroup, "int64_group": int64Group],
|
||||
form: nil,
|
||||
body: nil)
|
||||
return RequestBuilder<Void>(endpoint: path, method: "DELETE", parameters: parameters)
|
||||
}
|
||||
|
||||
@ -309,11 +265,10 @@ public struct FakeAPI {
|
||||
*/
|
||||
public func testInlineAdditionalProperties(param: [String: String]) -> RequestBuilder<Void> {
|
||||
let path = "/fake/inline-additionalProperties"
|
||||
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
parameters.append(Parameters(param))
|
||||
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: nil,
|
||||
body: AnyEncodable(param))
|
||||
return RequestBuilder<Void>(endpoint: path, method: "POST", parameters: parameters)
|
||||
}
|
||||
|
||||
@ -326,14 +281,10 @@ public struct FakeAPI {
|
||||
*/
|
||||
public func testJsonFormData(param: String, param2: String) -> RequestBuilder<Void> {
|
||||
let path = "/fake/jsonFormData"
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
let formParams: [String: String?] = [
|
||||
"param": param,
|
||||
"param2": param2
|
||||
]
|
||||
parameters.append(Parameters(formParams))
|
||||
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: ["param": param, "param2": param2],
|
||||
body: nil)
|
||||
return RequestBuilder<Void>(endpoint: path, method: "GET", parameters: parameters)
|
||||
}
|
||||
|
||||
|
@ -20,11 +20,10 @@ public struct FakeClassnameTags123API {
|
||||
*/
|
||||
public func testClassname(body: Client) -> RequestBuilder<Client> {
|
||||
let path = "/fake_classname_test"
|
||||
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
parameters.append(Parameters(body))
|
||||
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: nil,
|
||||
body: AnyEncodable(body))
|
||||
return RequestBuilder<Client>(endpoint: path, method: "PATCH", parameters: parameters)
|
||||
}
|
||||
|
||||
|
@ -19,11 +19,10 @@ public struct PetAPI {
|
||||
*/
|
||||
public func addPet(body: Pet) -> RequestBuilder<Void> {
|
||||
let path = "/pet"
|
||||
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
parameters.append(Parameters(body))
|
||||
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: nil,
|
||||
body: AnyEncodable(body))
|
||||
return RequestBuilder<Void>(endpoint: path, method: "POST", parameters: parameters)
|
||||
}
|
||||
|
||||
@ -41,8 +40,11 @@ public struct PetAPI {
|
||||
var path = "/pet/{petId}"
|
||||
let petIdEscaped = "\(petId)".addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
|
||||
path = path.replacingOccurrences(of: "{petId}", with: petIdEscaped, options: .literal, range: nil)
|
||||
|
||||
return RequestBuilder<Void>(endpoint: path, method: "DELETE")
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: nil,
|
||||
body: nil)
|
||||
return RequestBuilder<Void>(endpoint: path, method: "DELETE", parameters: parameters)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -66,13 +68,10 @@ public struct PetAPI {
|
||||
*/
|
||||
public func findPetsByStatus(status: [String]) -> RequestBuilder<[Pet]> {
|
||||
let path = "/pet/findByStatus"
|
||||
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
let queryParams: [String: Any?] = [
|
||||
"status": status
|
||||
]
|
||||
parameters.append(Parameters(queryParams))
|
||||
let parameters = Parameters(
|
||||
query: ["status": status],
|
||||
form: nil,
|
||||
body: nil)
|
||||
return RequestBuilder<[Pet]>(endpoint: path, method: "GET", parameters: parameters)
|
||||
}
|
||||
|
||||
@ -88,13 +87,10 @@ public struct PetAPI {
|
||||
*/
|
||||
public func findPetsByTags(tags: [String]) -> RequestBuilder<[Pet]> {
|
||||
let path = "/pet/findByTags"
|
||||
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
let queryParams: [String: Any?] = [
|
||||
"tags": tags
|
||||
]
|
||||
parameters.append(Parameters(queryParams))
|
||||
let parameters = Parameters(
|
||||
query: ["tags": tags],
|
||||
form: nil,
|
||||
body: nil)
|
||||
return RequestBuilder<[Pet]>(endpoint: path, method: "GET", parameters: parameters)
|
||||
}
|
||||
|
||||
@ -112,8 +108,11 @@ public struct PetAPI {
|
||||
var path = "/pet/{petId}"
|
||||
let petIdEscaped = "\(petId)".addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
|
||||
path = path.replacingOccurrences(of: "{petId}", with: petIdEscaped, options: .literal, range: nil)
|
||||
|
||||
return RequestBuilder<Pet>(endpoint: path, method: "GET")
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: nil,
|
||||
body: nil)
|
||||
return RequestBuilder<Pet>(endpoint: path, method: "GET", parameters: parameters)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -127,11 +126,10 @@ public struct PetAPI {
|
||||
*/
|
||||
public func updatePet(body: Pet) -> RequestBuilder<Void> {
|
||||
let path = "/pet"
|
||||
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
parameters.append(Parameters(body))
|
||||
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: nil,
|
||||
body: AnyEncodable(body))
|
||||
return RequestBuilder<Void>(endpoint: path, method: "PUT", parameters: parameters)
|
||||
}
|
||||
|
||||
@ -150,14 +148,10 @@ public struct PetAPI {
|
||||
var path = "/pet/{petId}"
|
||||
let petIdEscaped = "\(petId)".addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
|
||||
path = path.replacingOccurrences(of: "{petId}", with: petIdEscaped, options: .literal, range: nil)
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
let formParams: [String: String?] = [
|
||||
"name": name,
|
||||
"status": status
|
||||
]
|
||||
parameters.append(Parameters(formParams))
|
||||
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: ["name": name, "status": status],
|
||||
body: nil)
|
||||
return RequestBuilder<Void>(endpoint: path, method: "POST", parameters: parameters)
|
||||
}
|
||||
|
||||
@ -176,14 +170,10 @@ public struct PetAPI {
|
||||
var path = "/pet/{petId}/uploadImage"
|
||||
let petIdEscaped = "\(petId)".addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
|
||||
path = path.replacingOccurrences(of: "{petId}", with: petIdEscaped, options: .literal, range: nil)
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
let formParams: [String: String?] = [
|
||||
"additionalMetadata": additionalMetadata,
|
||||
"file": file?.description
|
||||
]
|
||||
parameters.append(Parameters(formParams))
|
||||
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: ["additionalMetadata": additionalMetadata, "file": file?.description],
|
||||
body: nil)
|
||||
return RequestBuilder<ApiResponse>(endpoint: path, method: "POST", parameters: parameters)
|
||||
}
|
||||
|
||||
@ -202,14 +192,10 @@ public struct PetAPI {
|
||||
var path = "/fake/{petId}/uploadImageWithRequiredFile"
|
||||
let petIdEscaped = "\(petId)".addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
|
||||
path = path.replacingOccurrences(of: "{petId}", with: petIdEscaped, options: .literal, range: nil)
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
let formParams: [String: String?] = [
|
||||
"additionalMetadata": additionalMetadata,
|
||||
"requiredFile": requiredFile.description
|
||||
]
|
||||
parameters.append(Parameters(formParams))
|
||||
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: ["additionalMetadata": additionalMetadata, "requiredFile": requiredFile.description],
|
||||
body: nil)
|
||||
return RequestBuilder<ApiResponse>(endpoint: path, method: "POST", parameters: parameters)
|
||||
}
|
||||
|
||||
|
@ -19,8 +19,11 @@ public struct StoreAPI {
|
||||
var path = "/store/order/{order_id}"
|
||||
let orderIdEscaped = "\(orderId)".addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
|
||||
path = path.replacingOccurrences(of: "{order_id}", with: orderIdEscaped, options: .literal, range: nil)
|
||||
|
||||
return RequestBuilder<Void>(endpoint: path, method: "DELETE")
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: nil,
|
||||
body: nil)
|
||||
return RequestBuilder<Void>(endpoint: path, method: "DELETE", parameters: parameters)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -34,7 +37,6 @@ public struct StoreAPI {
|
||||
*/
|
||||
public func getInventory() -> RequestBuilder<[String: Int]> {
|
||||
let path = "/store/inventory"
|
||||
|
||||
return RequestBuilder<[String: Int]>(endpoint: path, method: "GET")
|
||||
}
|
||||
|
||||
@ -49,8 +51,11 @@ public struct StoreAPI {
|
||||
var path = "/store/order/{order_id}"
|
||||
let orderIdEscaped = "\(orderId)".addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
|
||||
path = path.replacingOccurrences(of: "{order_id}", with: orderIdEscaped, options: .literal, range: nil)
|
||||
|
||||
return RequestBuilder<Order>(endpoint: path, method: "GET")
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: nil,
|
||||
body: nil)
|
||||
return RequestBuilder<Order>(endpoint: path, method: "GET", parameters: parameters)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -61,11 +66,10 @@ public struct StoreAPI {
|
||||
*/
|
||||
public func placeOrder(body: Order) -> RequestBuilder<Order> {
|
||||
let path = "/store/order"
|
||||
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
parameters.append(Parameters(body))
|
||||
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: nil,
|
||||
body: AnyEncodable(body))
|
||||
return RequestBuilder<Order>(endpoint: path, method: "POST", parameters: parameters)
|
||||
}
|
||||
|
||||
|
@ -17,11 +17,10 @@ public struct UserAPI {
|
||||
*/
|
||||
public func createUser(body: User) -> RequestBuilder<Void> {
|
||||
let path = "/user"
|
||||
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
parameters.append(Parameters(body))
|
||||
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: nil,
|
||||
body: AnyEncodable(body))
|
||||
return RequestBuilder<Void>(endpoint: path, method: "POST", parameters: parameters)
|
||||
}
|
||||
|
||||
@ -33,11 +32,10 @@ public struct UserAPI {
|
||||
*/
|
||||
public func createUsersWithArrayInput(body: [User]) -> RequestBuilder<Void> {
|
||||
let path = "/user/createWithArray"
|
||||
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
parameters.append(Parameters(body))
|
||||
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: nil,
|
||||
body: AnyEncodable(body))
|
||||
return RequestBuilder<Void>(endpoint: path, method: "POST", parameters: parameters)
|
||||
}
|
||||
|
||||
@ -49,11 +47,10 @@ public struct UserAPI {
|
||||
*/
|
||||
public func createUsersWithListInput(body: [User]) -> RequestBuilder<Void> {
|
||||
let path = "/user/createWithList"
|
||||
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
parameters.append(Parameters(body))
|
||||
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: nil,
|
||||
body: AnyEncodable(body))
|
||||
return RequestBuilder<Void>(endpoint: path, method: "POST", parameters: parameters)
|
||||
}
|
||||
|
||||
@ -68,8 +65,11 @@ public struct UserAPI {
|
||||
var path = "/user/{username}"
|
||||
let usernameEscaped = "\(username)".addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
|
||||
path = path.replacingOccurrences(of: "{username}", with: usernameEscaped, options: .literal, range: nil)
|
||||
|
||||
return RequestBuilder<Void>(endpoint: path, method: "DELETE")
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: nil,
|
||||
body: nil)
|
||||
return RequestBuilder<Void>(endpoint: path, method: "DELETE", parameters: parameters)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -82,8 +82,11 @@ public struct UserAPI {
|
||||
var path = "/user/{username}"
|
||||
let usernameEscaped = "\(username)".addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
|
||||
path = path.replacingOccurrences(of: "{username}", with: usernameEscaped, options: .literal, range: nil)
|
||||
|
||||
return RequestBuilder<User>(endpoint: path, method: "GET")
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: nil,
|
||||
body: nil)
|
||||
return RequestBuilder<User>(endpoint: path, method: "GET", parameters: parameters)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -96,14 +99,10 @@ public struct UserAPI {
|
||||
*/
|
||||
public func loginUser(username: String, password: String) -> RequestBuilder<String> {
|
||||
let path = "/user/login"
|
||||
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
let queryParams: [String: Any?] = [
|
||||
"username": username,
|
||||
"password": password
|
||||
]
|
||||
parameters.append(Parameters(queryParams))
|
||||
let parameters = Parameters(
|
||||
query: ["username": username, "password": password],
|
||||
form: nil,
|
||||
body: nil)
|
||||
return RequestBuilder<String>(endpoint: path, method: "GET", parameters: parameters)
|
||||
}
|
||||
|
||||
@ -114,7 +113,6 @@ public struct UserAPI {
|
||||
*/
|
||||
public func logoutUser() -> RequestBuilder<Void> {
|
||||
let path = "/user/logout"
|
||||
|
||||
return RequestBuilder<Void>(endpoint: path, method: "GET")
|
||||
}
|
||||
|
||||
@ -130,11 +128,10 @@ public struct UserAPI {
|
||||
var path = "/user/{username}"
|
||||
let usernameEscaped = "\(username)".addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
|
||||
path = path.replacingOccurrences(of: "{username}", with: usernameEscaped, options: .literal, range: nil)
|
||||
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
parameters.append(Parameters(body))
|
||||
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: nil,
|
||||
body: AnyEncodable(body))
|
||||
return RequestBuilder<Void>(endpoint: path, method: "PUT", parameters: parameters)
|
||||
}
|
||||
|
||||
|
@ -43,13 +43,12 @@ playground.xcworkspace
|
||||
# you should judge for yourself, the pros and cons are mentioned at:
|
||||
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
||||
#
|
||||
# Pods/
|
||||
Pods/
|
||||
|
||||
# Carthage
|
||||
#
|
||||
# Add this line if you want to avoid checking in source code from Carthage dependencies.
|
||||
# Carthage/Checkouts
|
||||
|
||||
Carthage/Checkouts
|
||||
Carthage/Build
|
||||
|
||||
# fastlane
|
||||
|
@ -0,0 +1,2 @@
|
||||
github "Alamofire/Alamofire" "4.8.2"
|
||||
github "mxcl/PromiseKit" "6.10.0"
|
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>IDEDidComputeMac32BitWarning</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</plist>
|
@ -9,10 +9,10 @@ import Foundation
|
||||
public struct RequestBuilder<Response> {
|
||||
public let endpoint: String
|
||||
public let method: String
|
||||
public let parameters: [Parameters]
|
||||
public let parameters: Parameters?
|
||||
public let headers: [String: String]
|
||||
|
||||
public init(endpoint: String, method: String, parameters: [Parameters] = [], headers: [String: String] = [:]) {
|
||||
public init(endpoint: String, method: String, parameters: Parameters? = nil, headers: [String: String] = [:]) {
|
||||
self.endpoint = endpoint
|
||||
self.method = method
|
||||
self.parameters = parameters
|
||||
@ -20,21 +20,15 @@ public struct RequestBuilder<Response> {
|
||||
}
|
||||
}
|
||||
|
||||
public enum Parameters {
|
||||
case query([String: Any?])
|
||||
case form([String: String?])
|
||||
case json(AnyEncodable)
|
||||
public struct Parameters {
|
||||
var query: [String: Any?]?
|
||||
var form: [String: String?]?
|
||||
var body: AnyEncodable?
|
||||
|
||||
public init(_ raw: [String: Any?]) {
|
||||
self = .query(raw)
|
||||
}
|
||||
|
||||
public init(_ raw: [String: String?]) {
|
||||
self = .form(raw)
|
||||
}
|
||||
|
||||
public init<T: Encodable>(_ raw: T) {
|
||||
self = .json(AnyEncodable(raw))
|
||||
public init(query: [String: Any?]? = nil, form: [String: String?]? = nil, body: AnyEncodable? = nil) {
|
||||
self.query = query
|
||||
self.form = form
|
||||
self.body = body
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -17,11 +17,10 @@ public struct AnotherFakeAPI {
|
||||
*/
|
||||
public func call123testSpecialTags(body: Client) -> RequestBuilder<Client> {
|
||||
let path = "/another-fake/dummy"
|
||||
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
parameters.append(Parameters(body))
|
||||
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: nil,
|
||||
body: AnyEncodable(body))
|
||||
return RequestBuilder<Client>(endpoint: path, method: "PATCH", parameters: parameters)
|
||||
}
|
||||
|
||||
|
@ -16,11 +16,10 @@ public struct FakeAPI {
|
||||
*/
|
||||
public func fakeOuterBooleanSerialize(body: Bool? = nil) -> RequestBuilder<Bool> {
|
||||
let path = "/fake/outer/boolean"
|
||||
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
parameters.append(Parameters(body))
|
||||
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: nil,
|
||||
body: AnyEncodable(body))
|
||||
return RequestBuilder<Bool>(endpoint: path, method: "POST", parameters: parameters)
|
||||
}
|
||||
|
||||
@ -32,11 +31,10 @@ public struct FakeAPI {
|
||||
*/
|
||||
public func fakeOuterCompositeSerialize(body: OuterComposite? = nil) -> RequestBuilder<OuterComposite> {
|
||||
let path = "/fake/outer/composite"
|
||||
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
parameters.append(Parameters(body))
|
||||
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: nil,
|
||||
body: AnyEncodable(body))
|
||||
return RequestBuilder<OuterComposite>(endpoint: path, method: "POST", parameters: parameters)
|
||||
}
|
||||
|
||||
@ -48,11 +46,10 @@ public struct FakeAPI {
|
||||
*/
|
||||
public func fakeOuterNumberSerialize(body: Double? = nil) -> RequestBuilder<Double> {
|
||||
let path = "/fake/outer/number"
|
||||
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
parameters.append(Parameters(body))
|
||||
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: nil,
|
||||
body: AnyEncodable(body))
|
||||
return RequestBuilder<Double>(endpoint: path, method: "POST", parameters: parameters)
|
||||
}
|
||||
|
||||
@ -64,11 +61,10 @@ public struct FakeAPI {
|
||||
*/
|
||||
public func fakeOuterStringSerialize(body: String? = nil) -> RequestBuilder<String> {
|
||||
let path = "/fake/outer/string"
|
||||
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
parameters.append(Parameters(body))
|
||||
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: nil,
|
||||
body: AnyEncodable(body))
|
||||
return RequestBuilder<String>(endpoint: path, method: "POST", parameters: parameters)
|
||||
}
|
||||
|
||||
@ -80,11 +76,10 @@ public struct FakeAPI {
|
||||
*/
|
||||
public func testBodyWithFileSchema(body: FileSchemaTestClass) -> RequestBuilder<Void> {
|
||||
let path = "/fake/body-with-file-schema"
|
||||
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
parameters.append(Parameters(body))
|
||||
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: nil,
|
||||
body: AnyEncodable(body))
|
||||
return RequestBuilder<Void>(endpoint: path, method: "PUT", parameters: parameters)
|
||||
}
|
||||
|
||||
@ -96,15 +91,10 @@ public struct FakeAPI {
|
||||
*/
|
||||
public func testBodyWithQueryParams(query: String, body: User) -> RequestBuilder<Void> {
|
||||
let path = "/fake/body-with-query-params"
|
||||
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
parameters.append(Parameters(body))
|
||||
|
||||
let queryParams: [String: Any?] = [
|
||||
"query": query
|
||||
]
|
||||
parameters.append(Parameters(queryParams))
|
||||
let parameters = Parameters(
|
||||
query: ["query": query],
|
||||
form: nil,
|
||||
body: AnyEncodable(body))
|
||||
return RequestBuilder<Void>(endpoint: path, method: "PUT", parameters: parameters)
|
||||
}
|
||||
|
||||
@ -117,11 +107,10 @@ public struct FakeAPI {
|
||||
*/
|
||||
public func testClientModel(body: Client) -> RequestBuilder<Client> {
|
||||
let path = "/fake"
|
||||
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
parameters.append(Parameters(body))
|
||||
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: nil,
|
||||
body: AnyEncodable(body))
|
||||
return RequestBuilder<Client>(endpoint: path, method: "PATCH", parameters: parameters)
|
||||
}
|
||||
|
||||
@ -150,26 +139,10 @@ public struct FakeAPI {
|
||||
*/
|
||||
public func testEndpointParameters(number: Double, double: Double, patternWithoutDelimiter: String, byte: Data, integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, float: Float? = nil, string: String? = nil, binary: URL? = nil, date: Date? = nil, dateTime: Date? = nil, password: String? = nil, callback: String? = nil) -> RequestBuilder<Void> {
|
||||
let path = "/fake"
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
let formParams: [String: String?] = [
|
||||
"integer": integer?.description,
|
||||
"int32": int32?.description,
|
||||
"int64": int64?.description,
|
||||
"number": number.description,
|
||||
"float": float?.description,
|
||||
"double": double.description,
|
||||
"string": string,
|
||||
"pattern_without_delimiter": patternWithoutDelimiter,
|
||||
"byte": byte.description,
|
||||
"binary": binary?.description,
|
||||
"date": date?.description,
|
||||
"dateTime": dateTime?.description,
|
||||
"password": password,
|
||||
"callback": callback
|
||||
]
|
||||
parameters.append(Parameters(formParams))
|
||||
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: ["integer": integer?.description, "int32": int32?.description, "int64": int64?.description, "number": number.description, "float": float?.description, "double": double.description, "string": string, "pattern_without_delimiter": patternWithoutDelimiter, "byte": byte.description, "binary": binary?.description, "date": date?.description, "dateTime": dateTime?.description, "password": password, "callback": callback],
|
||||
body: nil)
|
||||
return RequestBuilder<Void>(endpoint: path, method: "POST", parameters: parameters)
|
||||
}
|
||||
|
||||
@ -256,21 +229,10 @@ public struct FakeAPI {
|
||||
*/
|
||||
public func testEnumParameters(enumHeaderStringArray: [String]? = nil, enumHeaderString: EnumHeaderString_testEnumParameters? = nil, enumQueryStringArray: [String]? = nil, enumQueryString: EnumQueryString_testEnumParameters? = nil, enumQueryInteger: EnumQueryInteger_testEnumParameters? = nil, enumQueryDouble: EnumQueryDouble_testEnumParameters? = nil, enumFormStringArray: [String]? = nil, enumFormString: EnumFormString_testEnumParameters? = nil) -> RequestBuilder<Void> {
|
||||
let path = "/fake"
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
let formParams: [String: String?] = [
|
||||
"enum_form_string_array": enumFormStringArray?.description,
|
||||
"enum_form_string": enumFormString?.rawValue
|
||||
]
|
||||
parameters.append(Parameters(formParams))
|
||||
|
||||
let queryParams: [String: Any?] = [
|
||||
"enum_query_string_array": enumQueryStringArray,
|
||||
"enum_query_string": enumQueryString,
|
||||
"enum_query_integer": enumQueryInteger,
|
||||
"enum_query_double": enumQueryDouble
|
||||
]
|
||||
parameters.append(Parameters(queryParams))
|
||||
let parameters = Parameters(
|
||||
query: ["enum_query_string_array": enumQueryStringArray, "enum_query_string": enumQueryString, "enum_query_integer": enumQueryInteger, "enum_query_double": enumQueryDouble],
|
||||
form: ["enum_form_string_array": enumFormStringArray?.description, "enum_form_string": enumFormString?.rawValue],
|
||||
body: nil)
|
||||
return RequestBuilder<Void>(endpoint: path, method: "GET", parameters: parameters)
|
||||
}
|
||||
|
||||
@ -288,16 +250,10 @@ public struct FakeAPI {
|
||||
*/
|
||||
public func testGroupParameters(requiredStringGroup: Int, requiredBooleanGroup: Bool, requiredInt64Group: Int64, stringGroup: Int? = nil, booleanGroup: Bool? = nil, int64Group: Int64? = nil) -> RequestBuilder<Void> {
|
||||
let path = "/fake"
|
||||
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
let queryParams: [String: Any?] = [
|
||||
"required_string_group": requiredStringGroup,
|
||||
"required_int64_group": requiredInt64Group,
|
||||
"string_group": stringGroup,
|
||||
"int64_group": int64Group
|
||||
]
|
||||
parameters.append(Parameters(queryParams))
|
||||
let parameters = Parameters(
|
||||
query: ["required_string_group": requiredStringGroup, "required_int64_group": requiredInt64Group, "string_group": stringGroup, "int64_group": int64Group],
|
||||
form: nil,
|
||||
body: nil)
|
||||
return RequestBuilder<Void>(endpoint: path, method: "DELETE", parameters: parameters)
|
||||
}
|
||||
|
||||
@ -309,11 +265,10 @@ public struct FakeAPI {
|
||||
*/
|
||||
public func testInlineAdditionalProperties(param: [String: String]) -> RequestBuilder<Void> {
|
||||
let path = "/fake/inline-additionalProperties"
|
||||
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
parameters.append(Parameters(param))
|
||||
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: nil,
|
||||
body: AnyEncodable(param))
|
||||
return RequestBuilder<Void>(endpoint: path, method: "POST", parameters: parameters)
|
||||
}
|
||||
|
||||
@ -326,14 +281,10 @@ public struct FakeAPI {
|
||||
*/
|
||||
public func testJsonFormData(param: String, param2: String) -> RequestBuilder<Void> {
|
||||
let path = "/fake/jsonFormData"
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
let formParams: [String: String?] = [
|
||||
"param": param,
|
||||
"param2": param2
|
||||
]
|
||||
parameters.append(Parameters(formParams))
|
||||
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: ["param": param, "param2": param2],
|
||||
body: nil)
|
||||
return RequestBuilder<Void>(endpoint: path, method: "GET", parameters: parameters)
|
||||
}
|
||||
|
||||
|
@ -20,11 +20,10 @@ public struct FakeClassnameTags123API {
|
||||
*/
|
||||
public func testClassname(body: Client) -> RequestBuilder<Client> {
|
||||
let path = "/fake_classname_test"
|
||||
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
parameters.append(Parameters(body))
|
||||
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: nil,
|
||||
body: AnyEncodable(body))
|
||||
return RequestBuilder<Client>(endpoint: path, method: "PATCH", parameters: parameters)
|
||||
}
|
||||
|
||||
|
@ -19,11 +19,10 @@ public struct PetAPI {
|
||||
*/
|
||||
public func addPet(body: Pet) -> RequestBuilder<Void> {
|
||||
let path = "/pet"
|
||||
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
parameters.append(Parameters(body))
|
||||
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: nil,
|
||||
body: AnyEncodable(body))
|
||||
return RequestBuilder<Void>(endpoint: path, method: "POST", parameters: parameters)
|
||||
}
|
||||
|
||||
@ -41,8 +40,11 @@ public struct PetAPI {
|
||||
var path = "/pet/{petId}"
|
||||
let petIdEscaped = "\(petId)".addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
|
||||
path = path.replacingOccurrences(of: "{petId}", with: petIdEscaped, options: .literal, range: nil)
|
||||
|
||||
return RequestBuilder<Void>(endpoint: path, method: "DELETE")
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: nil,
|
||||
body: nil)
|
||||
return RequestBuilder<Void>(endpoint: path, method: "DELETE", parameters: parameters)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -66,13 +68,10 @@ public struct PetAPI {
|
||||
*/
|
||||
public func findPetsByStatus(status: [String]) -> RequestBuilder<[Pet]> {
|
||||
let path = "/pet/findByStatus"
|
||||
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
let queryParams: [String: Any?] = [
|
||||
"status": status
|
||||
]
|
||||
parameters.append(Parameters(queryParams))
|
||||
let parameters = Parameters(
|
||||
query: ["status": status],
|
||||
form: nil,
|
||||
body: nil)
|
||||
return RequestBuilder<[Pet]>(endpoint: path, method: "GET", parameters: parameters)
|
||||
}
|
||||
|
||||
@ -88,13 +87,10 @@ public struct PetAPI {
|
||||
*/
|
||||
public func findPetsByTags(tags: [String]) -> RequestBuilder<[Pet]> {
|
||||
let path = "/pet/findByTags"
|
||||
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
let queryParams: [String: Any?] = [
|
||||
"tags": tags
|
||||
]
|
||||
parameters.append(Parameters(queryParams))
|
||||
let parameters = Parameters(
|
||||
query: ["tags": tags],
|
||||
form: nil,
|
||||
body: nil)
|
||||
return RequestBuilder<[Pet]>(endpoint: path, method: "GET", parameters: parameters)
|
||||
}
|
||||
|
||||
@ -112,8 +108,11 @@ public struct PetAPI {
|
||||
var path = "/pet/{petId}"
|
||||
let petIdEscaped = "\(petId)".addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
|
||||
path = path.replacingOccurrences(of: "{petId}", with: petIdEscaped, options: .literal, range: nil)
|
||||
|
||||
return RequestBuilder<Pet>(endpoint: path, method: "GET")
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: nil,
|
||||
body: nil)
|
||||
return RequestBuilder<Pet>(endpoint: path, method: "GET", parameters: parameters)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -127,11 +126,10 @@ public struct PetAPI {
|
||||
*/
|
||||
public func updatePet(body: Pet) -> RequestBuilder<Void> {
|
||||
let path = "/pet"
|
||||
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
parameters.append(Parameters(body))
|
||||
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: nil,
|
||||
body: AnyEncodable(body))
|
||||
return RequestBuilder<Void>(endpoint: path, method: "PUT", parameters: parameters)
|
||||
}
|
||||
|
||||
@ -150,14 +148,10 @@ public struct PetAPI {
|
||||
var path = "/pet/{petId}"
|
||||
let petIdEscaped = "\(petId)".addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
|
||||
path = path.replacingOccurrences(of: "{petId}", with: petIdEscaped, options: .literal, range: nil)
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
let formParams: [String: String?] = [
|
||||
"name": name,
|
||||
"status": status
|
||||
]
|
||||
parameters.append(Parameters(formParams))
|
||||
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: ["name": name, "status": status],
|
||||
body: nil)
|
||||
return RequestBuilder<Void>(endpoint: path, method: "POST", parameters: parameters)
|
||||
}
|
||||
|
||||
@ -176,14 +170,10 @@ public struct PetAPI {
|
||||
var path = "/pet/{petId}/uploadImage"
|
||||
let petIdEscaped = "\(petId)".addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
|
||||
path = path.replacingOccurrences(of: "{petId}", with: petIdEscaped, options: .literal, range: nil)
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
let formParams: [String: String?] = [
|
||||
"additionalMetadata": additionalMetadata,
|
||||
"file": file?.description
|
||||
]
|
||||
parameters.append(Parameters(formParams))
|
||||
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: ["additionalMetadata": additionalMetadata, "file": file?.description],
|
||||
body: nil)
|
||||
return RequestBuilder<ApiResponse>(endpoint: path, method: "POST", parameters: parameters)
|
||||
}
|
||||
|
||||
@ -202,14 +192,10 @@ public struct PetAPI {
|
||||
var path = "/fake/{petId}/uploadImageWithRequiredFile"
|
||||
let petIdEscaped = "\(petId)".addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
|
||||
path = path.replacingOccurrences(of: "{petId}", with: petIdEscaped, options: .literal, range: nil)
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
let formParams: [String: String?] = [
|
||||
"additionalMetadata": additionalMetadata,
|
||||
"requiredFile": requiredFile.description
|
||||
]
|
||||
parameters.append(Parameters(formParams))
|
||||
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: ["additionalMetadata": additionalMetadata, "requiredFile": requiredFile.description],
|
||||
body: nil)
|
||||
return RequestBuilder<ApiResponse>(endpoint: path, method: "POST", parameters: parameters)
|
||||
}
|
||||
|
||||
|
@ -19,8 +19,11 @@ public struct StoreAPI {
|
||||
var path = "/store/order/{order_id}"
|
||||
let orderIdEscaped = "\(orderId)".addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
|
||||
path = path.replacingOccurrences(of: "{order_id}", with: orderIdEscaped, options: .literal, range: nil)
|
||||
|
||||
return RequestBuilder<Void>(endpoint: path, method: "DELETE")
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: nil,
|
||||
body: nil)
|
||||
return RequestBuilder<Void>(endpoint: path, method: "DELETE", parameters: parameters)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -34,7 +37,6 @@ public struct StoreAPI {
|
||||
*/
|
||||
public func getInventory() -> RequestBuilder<[String: Int]> {
|
||||
let path = "/store/inventory"
|
||||
|
||||
return RequestBuilder<[String: Int]>(endpoint: path, method: "GET")
|
||||
}
|
||||
|
||||
@ -49,8 +51,11 @@ public struct StoreAPI {
|
||||
var path = "/store/order/{order_id}"
|
||||
let orderIdEscaped = "\(orderId)".addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
|
||||
path = path.replacingOccurrences(of: "{order_id}", with: orderIdEscaped, options: .literal, range: nil)
|
||||
|
||||
return RequestBuilder<Order>(endpoint: path, method: "GET")
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: nil,
|
||||
body: nil)
|
||||
return RequestBuilder<Order>(endpoint: path, method: "GET", parameters: parameters)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -61,11 +66,10 @@ public struct StoreAPI {
|
||||
*/
|
||||
public func placeOrder(body: Order) -> RequestBuilder<Order> {
|
||||
let path = "/store/order"
|
||||
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
parameters.append(Parameters(body))
|
||||
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: nil,
|
||||
body: AnyEncodable(body))
|
||||
return RequestBuilder<Order>(endpoint: path, method: "POST", parameters: parameters)
|
||||
}
|
||||
|
||||
|
@ -17,11 +17,10 @@ public struct UserAPI {
|
||||
*/
|
||||
public func createUser(body: User) -> RequestBuilder<Void> {
|
||||
let path = "/user"
|
||||
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
parameters.append(Parameters(body))
|
||||
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: nil,
|
||||
body: AnyEncodable(body))
|
||||
return RequestBuilder<Void>(endpoint: path, method: "POST", parameters: parameters)
|
||||
}
|
||||
|
||||
@ -33,11 +32,10 @@ public struct UserAPI {
|
||||
*/
|
||||
public func createUsersWithArrayInput(body: [User]) -> RequestBuilder<Void> {
|
||||
let path = "/user/createWithArray"
|
||||
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
parameters.append(Parameters(body))
|
||||
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: nil,
|
||||
body: AnyEncodable(body))
|
||||
return RequestBuilder<Void>(endpoint: path, method: "POST", parameters: parameters)
|
||||
}
|
||||
|
||||
@ -49,11 +47,10 @@ public struct UserAPI {
|
||||
*/
|
||||
public func createUsersWithListInput(body: [User]) -> RequestBuilder<Void> {
|
||||
let path = "/user/createWithList"
|
||||
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
parameters.append(Parameters(body))
|
||||
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: nil,
|
||||
body: AnyEncodable(body))
|
||||
return RequestBuilder<Void>(endpoint: path, method: "POST", parameters: parameters)
|
||||
}
|
||||
|
||||
@ -68,8 +65,11 @@ public struct UserAPI {
|
||||
var path = "/user/{username}"
|
||||
let usernameEscaped = "\(username)".addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
|
||||
path = path.replacingOccurrences(of: "{username}", with: usernameEscaped, options: .literal, range: nil)
|
||||
|
||||
return RequestBuilder<Void>(endpoint: path, method: "DELETE")
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: nil,
|
||||
body: nil)
|
||||
return RequestBuilder<Void>(endpoint: path, method: "DELETE", parameters: parameters)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -82,8 +82,11 @@ public struct UserAPI {
|
||||
var path = "/user/{username}"
|
||||
let usernameEscaped = "\(username)".addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
|
||||
path = path.replacingOccurrences(of: "{username}", with: usernameEscaped, options: .literal, range: nil)
|
||||
|
||||
return RequestBuilder<User>(endpoint: path, method: "GET")
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: nil,
|
||||
body: nil)
|
||||
return RequestBuilder<User>(endpoint: path, method: "GET", parameters: parameters)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -96,14 +99,10 @@ public struct UserAPI {
|
||||
*/
|
||||
public func loginUser(username: String, password: String) -> RequestBuilder<String> {
|
||||
let path = "/user/login"
|
||||
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
let queryParams: [String: Any?] = [
|
||||
"username": username,
|
||||
"password": password
|
||||
]
|
||||
parameters.append(Parameters(queryParams))
|
||||
let parameters = Parameters(
|
||||
query: ["username": username, "password": password],
|
||||
form: nil,
|
||||
body: nil)
|
||||
return RequestBuilder<String>(endpoint: path, method: "GET", parameters: parameters)
|
||||
}
|
||||
|
||||
@ -114,7 +113,6 @@ public struct UserAPI {
|
||||
*/
|
||||
public func logoutUser() -> RequestBuilder<Void> {
|
||||
let path = "/user/logout"
|
||||
|
||||
return RequestBuilder<Void>(endpoint: path, method: "GET")
|
||||
}
|
||||
|
||||
@ -130,11 +128,10 @@ public struct UserAPI {
|
||||
var path = "/user/{username}"
|
||||
let usernameEscaped = "\(username)".addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
|
||||
path = path.replacingOccurrences(of: "{username}", with: usernameEscaped, options: .literal, range: nil)
|
||||
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
parameters.append(Parameters(body))
|
||||
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: nil,
|
||||
body: AnyEncodable(body))
|
||||
return RequestBuilder<Void>(endpoint: path, method: "PUT", parameters: parameters)
|
||||
}
|
||||
|
||||
|
@ -43,13 +43,12 @@ playground.xcworkspace
|
||||
# you should judge for yourself, the pros and cons are mentioned at:
|
||||
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
||||
#
|
||||
# Pods/
|
||||
Pods/
|
||||
|
||||
# Carthage
|
||||
#
|
||||
# Add this line if you want to avoid checking in source code from Carthage dependencies.
|
||||
# Carthage/Checkouts
|
||||
|
||||
Carthage/Checkouts
|
||||
Carthage/Build
|
||||
|
||||
# fastlane
|
||||
|
2
samples/client/petstore/swift5/rxswift/Cartfile.resolved
Normal file
2
samples/client/petstore/swift5/rxswift/Cartfile.resolved
Normal file
@ -0,0 +1,2 @@
|
||||
github "Alamofire/Alamofire" "4.8.2"
|
||||
github "ReactiveX/RxSwift" "5.0.1"
|
@ -11,7 +11,6 @@
|
||||
081C0B80A989B1AAF2665121 /* MapTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7986861626C2B1CB49AD7000 /* MapTest.swift */; };
|
||||
0C1E4C682F2D0AF7D9E431EE /* Dog.swift in Sources */ = {isa = PBXBuildFile; fileRef = C6C3E1129526A353B963EFD7 /* Dog.swift */; };
|
||||
0E6932F1C55BA6880693C478 /* Order.swift in Sources */ = {isa = PBXBuildFile; fileRef = 27B2E9EF856E89FEAA359A3A /* Order.swift */; };
|
||||
1E6C7C7F271A802DF8099330 /* APIHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 897716962D472FE162B723CB /* APIHelper.swift */; };
|
||||
22FA6CA58E58550DE36AE750 /* JSONEncodableEncoding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9791B840B8D6EAA35343B00F /* JSONEncodableEncoding.swift */; };
|
||||
248F2F0F29E8FDAE9CAD64C5 /* AdditionalPropertiesClass.swift in Sources */ = {isa = PBXBuildFile; fileRef = 396DEF3156BA0D12D0FC5C3C /* AdditionalPropertiesClass.swift */; };
|
||||
269E3103C458C78EA5726EE2 /* Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8C298FC8929DCB369053F11 /* Extensions.swift */; };
|
||||
@ -34,7 +33,6 @@
|
||||
61322FC4325F1A4FF24ACA48 /* EnumArrays.swift in Sources */ = {isa = PBXBuildFile; fileRef = 10503995D9EFD031A2EFB576 /* EnumArrays.swift */; };
|
||||
64C48E3658CF53EBE8AF82F9 /* UserAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C8D5F382979854D47F18DB1 /* UserAPI.swift */; };
|
||||
6B638A04B34C82B2091D6EDD /* FormatTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3156CE41C001C80379B84BDB /* FormatTest.swift */; };
|
||||
6FBD978F4D1ED92E7071FFBB /* CodableHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02A6F6BB2152ACEE1416D44A /* CodableHelper.swift */; };
|
||||
72547ECFB451A509409311EE /* Configuration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 28A444949BBC254798C3B3DD /* Configuration.swift */; };
|
||||
72CE544C52BB33778D1B89B8 /* DogAllOf.swift in Sources */ = {isa = PBXBuildFile; fileRef = A21A69C8402A60E01116ABBD /* DogAllOf.swift */; };
|
||||
7441BBA84C31E06400338F89 /* ClassModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C30827D8EAF8EA684E7BCEA /* ClassModel.swift */; };
|
||||
@ -55,9 +53,9 @@
|
||||
B3E35FE2773D4A8BA15CFA88 /* Tag.swift in Sources */ = {isa = PBXBuildFile; fileRef = B2896F8BFD1AA2965C8A3015 /* Tag.swift */; };
|
||||
BB1F3C6D50B8F0A8CC4F1749 /* Capitalization.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7B38FA00A494D13F4C382A3 /* Capitalization.swift */; };
|
||||
BC097E527F96131FEA12D864 /* RxSwift.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 69DB3E1D94EB0566C0052331 /* RxSwift.framework */; };
|
||||
C8DC6AA6D89DC651EDBDF591 /* APIClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = D93CA8E7642E5DE260CAF0D5 /* APIClient.swift */; };
|
||||
CA9B9B19882EA044EAD0B359 /* AnotherFakeAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9DF24D2714B9C4CF14146E88 /* AnotherFakeAPI.swift */; };
|
||||
CB68ABDBAADAF6B8D7B93A5D /* StoreAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = A53274D99BBDE1B79BF3521C /* StoreAPI.swift */; };
|
||||
D3BAB7C7A607392CA838C580 /* Models.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8699F7966F748ED026A6FB4C /* Models.swift */; };
|
||||
D95A5F83AAA7D5C95A29AB83 /* Cat.swift in Sources */ = {isa = PBXBuildFile; fileRef = 212AA914B7F1793A4E32C119 /* Cat.swift */; };
|
||||
DDBD4C0FBA3CD6A4DA3DF376 /* FakeAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E00950725DC44436C5E238C /* FakeAPI.swift */; };
|
||||
DDF1D589267D56D9BED3C6E5 /* FileSchemaTestClass.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B3666552AA854DAF9C480A3 /* FileSchemaTestClass.swift */; };
|
||||
@ -67,7 +65,6 @@
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
02A6F6BB2152ACEE1416D44A /* CodableHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CodableHelper.swift; sourceTree = "<group>"; };
|
||||
10503995D9EFD031A2EFB576 /* EnumArrays.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EnumArrays.swift; sourceTree = "<group>"; };
|
||||
164AD6EC9C4CCF634D7C4590 /* PetstoreClient.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = PetstoreClient.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
19B65C66C97F082718DDD703 /* TypeHolderExample.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeHolderExample.swift; sourceTree = "<group>"; };
|
||||
@ -97,8 +94,6 @@
|
||||
7C8D5F382979854D47F18DB1 /* UserAPI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserAPI.swift; sourceTree = "<group>"; };
|
||||
82A2C3DC2235F0114C2B08E5 /* Model200Response.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Model200Response.swift; sourceTree = "<group>"; };
|
||||
84A201508DF2B697D65F2631 /* AlamofireImplementations.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlamofireImplementations.swift; sourceTree = "<group>"; };
|
||||
8699F7966F748ED026A6FB4C /* Models.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Models.swift; sourceTree = "<group>"; };
|
||||
897716962D472FE162B723CB /* APIHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = APIHelper.swift; sourceTree = "<group>"; };
|
||||
8D22BE01748F51106DE02332 /* AnimalFarm.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnimalFarm.swift; sourceTree = "<group>"; };
|
||||
95568E7C35F119EB4A12B498 /* Animal.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Animal.swift; sourceTree = "<group>"; };
|
||||
9791B840B8D6EAA35343B00F /* JSONEncodableEncoding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JSONEncodableEncoding.swift; sourceTree = "<group>"; };
|
||||
@ -119,6 +114,7 @@
|
||||
C15008AABC804EB6FB4CDAC6 /* OuterEnum.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OuterEnum.swift; sourceTree = "<group>"; };
|
||||
C6C3E1129526A353B963EFD7 /* Dog.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Dog.swift; sourceTree = "<group>"; };
|
||||
C81447828475F76C5CF4F08A /* Return.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Return.swift; sourceTree = "<group>"; };
|
||||
D93CA8E7642E5DE260CAF0D5 /* APIClient.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = APIClient.swift; sourceTree = "<group>"; };
|
||||
E5565A447062C7B8F695F451 /* User.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = User.swift; sourceTree = "<group>"; };
|
||||
EBC76F6D4D2AA8084B7EB50E /* TypeHolderDefault.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeHolderDefault.swift; sourceTree = "<group>"; };
|
||||
ECFEB4C6C257B3BB3CEA36D1 /* Pet.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Pet.swift; sourceTree = "<group>"; };
|
||||
@ -208,14 +204,11 @@
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
84A201508DF2B697D65F2631 /* AlamofireImplementations.swift */,
|
||||
897716962D472FE162B723CB /* APIHelper.swift */,
|
||||
37DF825B8F3BADA2B2537D17 /* APIs.swift */,
|
||||
02A6F6BB2152ACEE1416D44A /* CodableHelper.swift */,
|
||||
28A444949BBC254798C3B3DD /* Configuration.swift */,
|
||||
B8C298FC8929DCB369053F11 /* Extensions.swift */,
|
||||
9791B840B8D6EAA35343B00F /* JSONEncodableEncoding.swift */,
|
||||
35D710108A69DD8A5297F926 /* JSONEncodingHelper.swift */,
|
||||
8699F7966F748ED026A6FB4C /* Models.swift */,
|
||||
F956D0CCAE23BCFD1C7BDD5D /* APIs */,
|
||||
4FBDCF1330A9AB9122780DB3 /* Models */,
|
||||
);
|
||||
@ -256,9 +249,18 @@
|
||||
path = iOS;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
D629CEDD108B633D945E8F93 /* Alamofire */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
D93CA8E7642E5DE260CAF0D5 /* APIClient.swift */,
|
||||
);
|
||||
path = Alamofire;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
EF4C81BDD734856ED5023B77 /* Classes */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
D629CEDD108B633D945E8F93 /* Alamofire */,
|
||||
67BF3478113E6B4DF1C4E04F /* OpenAPIs */,
|
||||
);
|
||||
path = Classes;
|
||||
@ -325,7 +327,7 @@
|
||||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
1E6C7C7F271A802DF8099330 /* APIHelper.swift in Sources */,
|
||||
C8DC6AA6D89DC651EDBDF591 /* APIClient.swift in Sources */,
|
||||
40E3027D2E38D8329C6AB01F /* APIs.swift in Sources */,
|
||||
248F2F0F29E8FDAE9CAD64C5 /* AdditionalPropertiesClass.swift in Sources */,
|
||||
40E46046D2B16D1A672A08E3 /* AlamofireImplementations.swift in Sources */,
|
||||
@ -342,7 +344,6 @@
|
||||
E8A58C6414E88AF3EAE45B69 /* Category.swift in Sources */,
|
||||
7441BBA84C31E06400338F89 /* ClassModel.swift in Sources */,
|
||||
AD594BFB99E31A5E07579237 /* Client.swift in Sources */,
|
||||
6FBD978F4D1ED92E7071FFBB /* CodableHelper.swift in Sources */,
|
||||
72547ECFB451A509409311EE /* Configuration.swift in Sources */,
|
||||
0C1E4C682F2D0AF7D9E431EE /* Dog.swift in Sources */,
|
||||
72CE544C52BB33778D1B89B8 /* DogAllOf.swift in Sources */,
|
||||
@ -362,7 +363,6 @@
|
||||
081C0B80A989B1AAF2665121 /* MapTest.swift in Sources */,
|
||||
B301DB1B80F37C757550AA17 /* MixedPropertiesAndAdditionalPropertiesClass.swift in Sources */,
|
||||
9CF06ACDA32CB0C3E74E435C /* Model200Response.swift in Sources */,
|
||||
D3BAB7C7A607392CA838C580 /* Models.swift in Sources */,
|
||||
37DEADD6CD0496690725B8A7 /* Name.swift in Sources */,
|
||||
555DEA47352B42E49082922B /* NumberOnly.swift in Sources */,
|
||||
0E6932F1C55BA6880693C478 /* Order.swift in Sources */,
|
||||
@ -403,7 +403,10 @@
|
||||
INFOPLIST_FILE = Info.plist;
|
||||
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
|
||||
LD_RUNPATH_SEARCH_PATHS = (
|
||||
"$(inherited)",
|
||||
"@executable_path/Frameworks",
|
||||
);
|
||||
SDKROOT = iphoneos;
|
||||
SKIP_INSTALL = YES;
|
||||
SWIFT_VERSION = 5.0;
|
||||
@ -488,7 +491,10 @@
|
||||
INFOPLIST_FILE = Info.plist;
|
||||
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
|
||||
LD_RUNPATH_SEARCH_PATHS = (
|
||||
"$(inherited)",
|
||||
"@executable_path/Frameworks",
|
||||
);
|
||||
SDKROOT = iphoneos;
|
||||
SKIP_INSTALL = YES;
|
||||
SWIFT_VERSION = 5.0;
|
||||
|
@ -0,0 +1,80 @@
|
||||
//
|
||||
// APIClient.swift
|
||||
// PetstoreClient
|
||||
//
|
||||
// Created by dmatsudate on 2019/07/23.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import Alamofire
|
||||
|
||||
public class APIClient<Response> {
|
||||
|
||||
public let baseURL: URL
|
||||
public let headers: [AnyHashable: Any]
|
||||
|
||||
private let sessionManager: SessionManager
|
||||
private let queue = DispatchQueue(
|
||||
label: "com.openapi-generator.api-client",
|
||||
qos: .userInitiated,
|
||||
attributes: [.concurrent],
|
||||
autoreleaseFrequency: .inherit)
|
||||
|
||||
public init(baseURL: URL, headers: [AnyHashable: Any] = [:]) {
|
||||
self.baseURL = baseURL
|
||||
self.headers = headers
|
||||
|
||||
let config: URLSessionConfiguration = .ephemeral
|
||||
config.httpAdditionalHeaders = headers
|
||||
self.sessionManager = SessionManager(configuration: config)
|
||||
}
|
||||
|
||||
private func url(request: RequestBuilder<Response>) -> URL {
|
||||
return baseURL.appendingPathComponent(request.endpoint)
|
||||
}
|
||||
|
||||
func perform(request: RequestBuilder<Response>, completion: (Result<Response, Error>) -> Void) {
|
||||
queue.async { [weak self] in
|
||||
guard let self = self else { return }
|
||||
|
||||
let url = self.url(request: request)
|
||||
let method = Alamofire.HTTPMethod(rawValue: request.method)!
|
||||
let parameters: Alamofire.Parameters = {
|
||||
var parameters = Alamofire.Parameters()
|
||||
if let form = request.parameters?.form {
|
||||
parameters.merge(form.compactMapValues { $0 }, uniquingKeysWith: { $1 })
|
||||
}
|
||||
|
||||
if let query = request.parameters?.query {
|
||||
parameters.merge(query.compactMapValues { $0 }, uniquingKeysWith: { $1 })
|
||||
}
|
||||
return parameters
|
||||
}()
|
||||
|
||||
if let form = request.parameters?.form {
|
||||
self.sessionManager.upload(multipartFormData: { (formData) in
|
||||
form.compactMapValues { $0 }.forEach { key, value in
|
||||
if let file = URL(string: value) {
|
||||
formData.append(file, withName: key)
|
||||
} else {
|
||||
formData.append(value.data(using: .utf8)!, withName: key)
|
||||
}
|
||||
}
|
||||
|
||||
}, to: url, method: method, encodingCompletion: { encodingResult in
|
||||
switch encodingResult {
|
||||
case .success(let uploadRequest, _, _):
|
||||
|
||||
}
|
||||
})
|
||||
} else {
|
||||
let url =
|
||||
let alamofireRequest = self.sessionManager.request(url(request: request), method: method, parameters: <#T##Parameters?#>, encoding: <#T##ParameterEncoding#>, headers: <#T##HTTPHeaders?#>)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,70 +0,0 @@
|
||||
// APIHelper.swift
|
||||
//
|
||||
// Generated by openapi-generator
|
||||
// https://openapi-generator.tech
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
public struct APIHelper {
|
||||
public static func rejectNil(_ source: [String: Any?]) -> [String: Any]? {
|
||||
let destination = source.reduce(into: [String: Any]()) { (result, item) in
|
||||
if let value = item.value {
|
||||
result[item.key] = value
|
||||
}
|
||||
}
|
||||
|
||||
if destination.isEmpty {
|
||||
return nil
|
||||
}
|
||||
return destination
|
||||
}
|
||||
|
||||
public static func rejectNilHeaders(_ source: [String: Any?]) -> [String: String] {
|
||||
return source.reduce(into: [String: String]()) { (result, item) in
|
||||
if let collection = item.value as? Array<Any?> {
|
||||
result[item.key] = collection.filter({ $0 != nil }).map { "\($0!)" }.joined(separator: ",")
|
||||
} else if let value: Any = item.value {
|
||||
result[item.key] = "\(value)"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static func convertBoolToString(_ source: [String: Any]?) -> [String: Any]? {
|
||||
guard let source = source else {
|
||||
return nil
|
||||
}
|
||||
|
||||
return source.reduce(into: [String: Any](), { (result, item) in
|
||||
switch item.value {
|
||||
case let x as Bool:
|
||||
result[item.key] = x.description
|
||||
default:
|
||||
result[item.key] = item.value
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
public static func mapValueToPathItem(_ source: Any) -> Any {
|
||||
if let collection = source as? Array<Any?> {
|
||||
return collection.filter({ $0 != nil }).map({"\($0!)"}).joined(separator: ",")
|
||||
}
|
||||
return source
|
||||
}
|
||||
|
||||
public static func mapValuesToQueryItems(_ source: [String: Any?]) -> [URLQueryItem]? {
|
||||
let destination = source.filter({ $0.value != nil}).reduce(into: [URLQueryItem]()) { (result, item) in
|
||||
if let collection = item.value as? Array<Any?> {
|
||||
let value = collection.filter({ $0 != nil }).map({"\($0!)"}).joined(separator: ",")
|
||||
result.append(URLQueryItem(name: item.key, value: value))
|
||||
} else if let value = item.value {
|
||||
result.append(URLQueryItem(name: item.key, value: "\(value)"))
|
||||
}
|
||||
}
|
||||
|
||||
if destination.isEmpty {
|
||||
return nil
|
||||
}
|
||||
return destination
|
||||
}
|
||||
}
|
@ -9,10 +9,10 @@ import Foundation
|
||||
public struct RequestBuilder<Response> {
|
||||
public let endpoint: String
|
||||
public let method: String
|
||||
public let parameters: [Parameters]
|
||||
public let parameters: Parameters?
|
||||
public let headers: [String: String]
|
||||
|
||||
public init(endpoint: String, method: String, parameters: [Parameters] = [], headers: [String: String] = [:]) {
|
||||
public init(endpoint: String, method: String, parameters: Parameters? = nil, headers: [String: String] = [:]) {
|
||||
self.endpoint = endpoint
|
||||
self.method = method
|
||||
self.parameters = parameters
|
||||
@ -20,21 +20,15 @@ public struct RequestBuilder<Response> {
|
||||
}
|
||||
}
|
||||
|
||||
public enum Parameters {
|
||||
case query([String: Any?])
|
||||
case form([String: String?])
|
||||
case json(AnyEncodable)
|
||||
public struct Parameters {
|
||||
var query: [String: Any?]?
|
||||
var form: [String: String?]?
|
||||
var body: AnyEncodable?
|
||||
|
||||
public init(_ raw: [String: Any?]) {
|
||||
self = .query(raw)
|
||||
}
|
||||
|
||||
public init(_ raw: [String: String?]) {
|
||||
self = .form(raw)
|
||||
}
|
||||
|
||||
public init<T: Encodable>(_ raw: T) {
|
||||
self = .json(AnyEncodable(raw))
|
||||
public init(query: [String: Any?]? = nil, form: [String: String?]? = nil, body: AnyEncodable? = nil) {
|
||||
self.query = query
|
||||
self.form = form
|
||||
self.body = body
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -17,11 +17,10 @@ public struct AnotherFakeAPI {
|
||||
*/
|
||||
public func call123testSpecialTags(body: Client) -> RequestBuilder<Client> {
|
||||
let path = "/another-fake/dummy"
|
||||
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
parameters.append(Parameters(body))
|
||||
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: nil,
|
||||
body: AnyEncodable(body))
|
||||
return RequestBuilder<Client>(endpoint: path, method: "PATCH", parameters: parameters)
|
||||
}
|
||||
|
||||
|
@ -16,11 +16,10 @@ public struct FakeAPI {
|
||||
*/
|
||||
public func fakeOuterBooleanSerialize(body: Bool? = nil) -> RequestBuilder<Bool> {
|
||||
let path = "/fake/outer/boolean"
|
||||
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
parameters.append(Parameters(body))
|
||||
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: nil,
|
||||
body: AnyEncodable(body))
|
||||
return RequestBuilder<Bool>(endpoint: path, method: "POST", parameters: parameters)
|
||||
}
|
||||
|
||||
@ -32,11 +31,10 @@ public struct FakeAPI {
|
||||
*/
|
||||
public func fakeOuterCompositeSerialize(body: OuterComposite? = nil) -> RequestBuilder<OuterComposite> {
|
||||
let path = "/fake/outer/composite"
|
||||
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
parameters.append(Parameters(body))
|
||||
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: nil,
|
||||
body: AnyEncodable(body))
|
||||
return RequestBuilder<OuterComposite>(endpoint: path, method: "POST", parameters: parameters)
|
||||
}
|
||||
|
||||
@ -48,11 +46,10 @@ public struct FakeAPI {
|
||||
*/
|
||||
public func fakeOuterNumberSerialize(body: Double? = nil) -> RequestBuilder<Double> {
|
||||
let path = "/fake/outer/number"
|
||||
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
parameters.append(Parameters(body))
|
||||
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: nil,
|
||||
body: AnyEncodable(body))
|
||||
return RequestBuilder<Double>(endpoint: path, method: "POST", parameters: parameters)
|
||||
}
|
||||
|
||||
@ -64,11 +61,10 @@ public struct FakeAPI {
|
||||
*/
|
||||
public func fakeOuterStringSerialize(body: String? = nil) -> RequestBuilder<String> {
|
||||
let path = "/fake/outer/string"
|
||||
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
parameters.append(Parameters(body))
|
||||
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: nil,
|
||||
body: AnyEncodable(body))
|
||||
return RequestBuilder<String>(endpoint: path, method: "POST", parameters: parameters)
|
||||
}
|
||||
|
||||
@ -80,11 +76,10 @@ public struct FakeAPI {
|
||||
*/
|
||||
public func testBodyWithFileSchema(body: FileSchemaTestClass) -> RequestBuilder<Void> {
|
||||
let path = "/fake/body-with-file-schema"
|
||||
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
parameters.append(Parameters(body))
|
||||
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: nil,
|
||||
body: AnyEncodable(body))
|
||||
return RequestBuilder<Void>(endpoint: path, method: "PUT", parameters: parameters)
|
||||
}
|
||||
|
||||
@ -96,15 +91,10 @@ public struct FakeAPI {
|
||||
*/
|
||||
public func testBodyWithQueryParams(query: String, body: User) -> RequestBuilder<Void> {
|
||||
let path = "/fake/body-with-query-params"
|
||||
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
parameters.append(Parameters(body))
|
||||
|
||||
let queryParams: [String: Any?] = [
|
||||
"query": query
|
||||
]
|
||||
parameters.append(Parameters(queryParams))
|
||||
let parameters = Parameters(
|
||||
query: ["query": query],
|
||||
form: nil,
|
||||
body: AnyEncodable(body))
|
||||
return RequestBuilder<Void>(endpoint: path, method: "PUT", parameters: parameters)
|
||||
}
|
||||
|
||||
@ -117,11 +107,10 @@ public struct FakeAPI {
|
||||
*/
|
||||
public func testClientModel(body: Client) -> RequestBuilder<Client> {
|
||||
let path = "/fake"
|
||||
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
parameters.append(Parameters(body))
|
||||
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: nil,
|
||||
body: AnyEncodable(body))
|
||||
return RequestBuilder<Client>(endpoint: path, method: "PATCH", parameters: parameters)
|
||||
}
|
||||
|
||||
@ -150,26 +139,10 @@ public struct FakeAPI {
|
||||
*/
|
||||
public func testEndpointParameters(number: Double, double: Double, patternWithoutDelimiter: String, byte: Data, integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, float: Float? = nil, string: String? = nil, binary: URL? = nil, date: Date? = nil, dateTime: Date? = nil, password: String? = nil, callback: String? = nil) -> RequestBuilder<Void> {
|
||||
let path = "/fake"
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
let formParams: [String: String?] = [
|
||||
"integer": integer?.description,
|
||||
"int32": int32?.description,
|
||||
"int64": int64?.description,
|
||||
"number": number.description,
|
||||
"float": float?.description,
|
||||
"double": double.description,
|
||||
"string": string,
|
||||
"pattern_without_delimiter": patternWithoutDelimiter,
|
||||
"byte": byte.description,
|
||||
"binary": binary?.description,
|
||||
"date": date?.description,
|
||||
"dateTime": dateTime?.description,
|
||||
"password": password,
|
||||
"callback": callback
|
||||
]
|
||||
parameters.append(Parameters(formParams))
|
||||
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: ["integer": integer?.description, "int32": int32?.description, "int64": int64?.description, "number": number.description, "float": float?.description, "double": double.description, "string": string, "pattern_without_delimiter": patternWithoutDelimiter, "byte": byte.description, "binary": binary?.description, "date": date?.description, "dateTime": dateTime?.description, "password": password, "callback": callback],
|
||||
body: nil)
|
||||
return RequestBuilder<Void>(endpoint: path, method: "POST", parameters: parameters)
|
||||
}
|
||||
|
||||
@ -256,21 +229,10 @@ public struct FakeAPI {
|
||||
*/
|
||||
public func testEnumParameters(enumHeaderStringArray: [String]? = nil, enumHeaderString: EnumHeaderString_testEnumParameters? = nil, enumQueryStringArray: [String]? = nil, enumQueryString: EnumQueryString_testEnumParameters? = nil, enumQueryInteger: EnumQueryInteger_testEnumParameters? = nil, enumQueryDouble: EnumQueryDouble_testEnumParameters? = nil, enumFormStringArray: [String]? = nil, enumFormString: EnumFormString_testEnumParameters? = nil) -> RequestBuilder<Void> {
|
||||
let path = "/fake"
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
let formParams: [String: String?] = [
|
||||
"enum_form_string_array": enumFormStringArray?.description,
|
||||
"enum_form_string": enumFormString?.rawValue
|
||||
]
|
||||
parameters.append(Parameters(formParams))
|
||||
|
||||
let queryParams: [String: Any?] = [
|
||||
"enum_query_string_array": enumQueryStringArray,
|
||||
"enum_query_string": enumQueryString,
|
||||
"enum_query_integer": enumQueryInteger,
|
||||
"enum_query_double": enumQueryDouble
|
||||
]
|
||||
parameters.append(Parameters(queryParams))
|
||||
let parameters = Parameters(
|
||||
query: ["enum_query_string_array": enumQueryStringArray, "enum_query_string": enumQueryString, "enum_query_integer": enumQueryInteger, "enum_query_double": enumQueryDouble],
|
||||
form: ["enum_form_string_array": enumFormStringArray?.description, "enum_form_string": enumFormString?.rawValue],
|
||||
body: nil)
|
||||
return RequestBuilder<Void>(endpoint: path, method: "GET", parameters: parameters)
|
||||
}
|
||||
|
||||
@ -288,16 +250,10 @@ public struct FakeAPI {
|
||||
*/
|
||||
public func testGroupParameters(requiredStringGroup: Int, requiredBooleanGroup: Bool, requiredInt64Group: Int64, stringGroup: Int? = nil, booleanGroup: Bool? = nil, int64Group: Int64? = nil) -> RequestBuilder<Void> {
|
||||
let path = "/fake"
|
||||
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
let queryParams: [String: Any?] = [
|
||||
"required_string_group": requiredStringGroup,
|
||||
"required_int64_group": requiredInt64Group,
|
||||
"string_group": stringGroup,
|
||||
"int64_group": int64Group
|
||||
]
|
||||
parameters.append(Parameters(queryParams))
|
||||
let parameters = Parameters(
|
||||
query: ["required_string_group": requiredStringGroup, "required_int64_group": requiredInt64Group, "string_group": stringGroup, "int64_group": int64Group],
|
||||
form: nil,
|
||||
body: nil)
|
||||
return RequestBuilder<Void>(endpoint: path, method: "DELETE", parameters: parameters)
|
||||
}
|
||||
|
||||
@ -309,11 +265,10 @@ public struct FakeAPI {
|
||||
*/
|
||||
public func testInlineAdditionalProperties(param: [String: String]) -> RequestBuilder<Void> {
|
||||
let path = "/fake/inline-additionalProperties"
|
||||
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
parameters.append(Parameters(param))
|
||||
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: nil,
|
||||
body: AnyEncodable(param))
|
||||
return RequestBuilder<Void>(endpoint: path, method: "POST", parameters: parameters)
|
||||
}
|
||||
|
||||
@ -326,14 +281,10 @@ public struct FakeAPI {
|
||||
*/
|
||||
public func testJsonFormData(param: String, param2: String) -> RequestBuilder<Void> {
|
||||
let path = "/fake/jsonFormData"
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
let formParams: [String: String?] = [
|
||||
"param": param,
|
||||
"param2": param2
|
||||
]
|
||||
parameters.append(Parameters(formParams))
|
||||
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: ["param": param, "param2": param2],
|
||||
body: nil)
|
||||
return RequestBuilder<Void>(endpoint: path, method: "GET", parameters: parameters)
|
||||
}
|
||||
|
||||
|
@ -20,11 +20,10 @@ public struct FakeClassnameTags123API {
|
||||
*/
|
||||
public func testClassname(body: Client) -> RequestBuilder<Client> {
|
||||
let path = "/fake_classname_test"
|
||||
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
parameters.append(Parameters(body))
|
||||
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: nil,
|
||||
body: AnyEncodable(body))
|
||||
return RequestBuilder<Client>(endpoint: path, method: "PATCH", parameters: parameters)
|
||||
}
|
||||
|
||||
|
@ -19,11 +19,10 @@ public struct PetAPI {
|
||||
*/
|
||||
public func addPet(body: Pet) -> RequestBuilder<Void> {
|
||||
let path = "/pet"
|
||||
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
parameters.append(Parameters(body))
|
||||
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: nil,
|
||||
body: AnyEncodable(body))
|
||||
return RequestBuilder<Void>(endpoint: path, method: "POST", parameters: parameters)
|
||||
}
|
||||
|
||||
@ -41,8 +40,11 @@ public struct PetAPI {
|
||||
var path = "/pet/{petId}"
|
||||
let petIdEscaped = "\(petId)".addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
|
||||
path = path.replacingOccurrences(of: "{petId}", with: petIdEscaped, options: .literal, range: nil)
|
||||
|
||||
return RequestBuilder<Void>(endpoint: path, method: "DELETE")
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: nil,
|
||||
body: nil)
|
||||
return RequestBuilder<Void>(endpoint: path, method: "DELETE", parameters: parameters)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -66,13 +68,10 @@ public struct PetAPI {
|
||||
*/
|
||||
public func findPetsByStatus(status: [String]) -> RequestBuilder<[Pet]> {
|
||||
let path = "/pet/findByStatus"
|
||||
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
let queryParams: [String: Any?] = [
|
||||
"status": status
|
||||
]
|
||||
parameters.append(Parameters(queryParams))
|
||||
let parameters = Parameters(
|
||||
query: ["status": status],
|
||||
form: nil,
|
||||
body: nil)
|
||||
return RequestBuilder<[Pet]>(endpoint: path, method: "GET", parameters: parameters)
|
||||
}
|
||||
|
||||
@ -88,13 +87,10 @@ public struct PetAPI {
|
||||
*/
|
||||
public func findPetsByTags(tags: [String]) -> RequestBuilder<[Pet]> {
|
||||
let path = "/pet/findByTags"
|
||||
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
let queryParams: [String: Any?] = [
|
||||
"tags": tags
|
||||
]
|
||||
parameters.append(Parameters(queryParams))
|
||||
let parameters = Parameters(
|
||||
query: ["tags": tags],
|
||||
form: nil,
|
||||
body: nil)
|
||||
return RequestBuilder<[Pet]>(endpoint: path, method: "GET", parameters: parameters)
|
||||
}
|
||||
|
||||
@ -112,8 +108,11 @@ public struct PetAPI {
|
||||
var path = "/pet/{petId}"
|
||||
let petIdEscaped = "\(petId)".addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
|
||||
path = path.replacingOccurrences(of: "{petId}", with: petIdEscaped, options: .literal, range: nil)
|
||||
|
||||
return RequestBuilder<Pet>(endpoint: path, method: "GET")
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: nil,
|
||||
body: nil)
|
||||
return RequestBuilder<Pet>(endpoint: path, method: "GET", parameters: parameters)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -127,11 +126,10 @@ public struct PetAPI {
|
||||
*/
|
||||
public func updatePet(body: Pet) -> RequestBuilder<Void> {
|
||||
let path = "/pet"
|
||||
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
parameters.append(Parameters(body))
|
||||
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: nil,
|
||||
body: AnyEncodable(body))
|
||||
return RequestBuilder<Void>(endpoint: path, method: "PUT", parameters: parameters)
|
||||
}
|
||||
|
||||
@ -150,14 +148,10 @@ public struct PetAPI {
|
||||
var path = "/pet/{petId}"
|
||||
let petIdEscaped = "\(petId)".addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
|
||||
path = path.replacingOccurrences(of: "{petId}", with: petIdEscaped, options: .literal, range: nil)
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
let formParams: [String: String?] = [
|
||||
"name": name,
|
||||
"status": status
|
||||
]
|
||||
parameters.append(Parameters(formParams))
|
||||
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: ["name": name, "status": status],
|
||||
body: nil)
|
||||
return RequestBuilder<Void>(endpoint: path, method: "POST", parameters: parameters)
|
||||
}
|
||||
|
||||
@ -176,14 +170,10 @@ public struct PetAPI {
|
||||
var path = "/pet/{petId}/uploadImage"
|
||||
let petIdEscaped = "\(petId)".addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
|
||||
path = path.replacingOccurrences(of: "{petId}", with: petIdEscaped, options: .literal, range: nil)
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
let formParams: [String: String?] = [
|
||||
"additionalMetadata": additionalMetadata,
|
||||
"file": file?.description
|
||||
]
|
||||
parameters.append(Parameters(formParams))
|
||||
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: ["additionalMetadata": additionalMetadata, "file": file?.description],
|
||||
body: nil)
|
||||
return RequestBuilder<ApiResponse>(endpoint: path, method: "POST", parameters: parameters)
|
||||
}
|
||||
|
||||
@ -202,14 +192,10 @@ public struct PetAPI {
|
||||
var path = "/fake/{petId}/uploadImageWithRequiredFile"
|
||||
let petIdEscaped = "\(petId)".addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
|
||||
path = path.replacingOccurrences(of: "{petId}", with: petIdEscaped, options: .literal, range: nil)
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
let formParams: [String: String?] = [
|
||||
"additionalMetadata": additionalMetadata,
|
||||
"requiredFile": requiredFile.description
|
||||
]
|
||||
parameters.append(Parameters(formParams))
|
||||
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: ["additionalMetadata": additionalMetadata, "requiredFile": requiredFile.description],
|
||||
body: nil)
|
||||
return RequestBuilder<ApiResponse>(endpoint: path, method: "POST", parameters: parameters)
|
||||
}
|
||||
|
||||
|
@ -19,8 +19,11 @@ public struct StoreAPI {
|
||||
var path = "/store/order/{order_id}"
|
||||
let orderIdEscaped = "\(orderId)".addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
|
||||
path = path.replacingOccurrences(of: "{order_id}", with: orderIdEscaped, options: .literal, range: nil)
|
||||
|
||||
return RequestBuilder<Void>(endpoint: path, method: "DELETE")
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: nil,
|
||||
body: nil)
|
||||
return RequestBuilder<Void>(endpoint: path, method: "DELETE", parameters: parameters)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -34,7 +37,6 @@ public struct StoreAPI {
|
||||
*/
|
||||
public func getInventory() -> RequestBuilder<[String: Int]> {
|
||||
let path = "/store/inventory"
|
||||
|
||||
return RequestBuilder<[String: Int]>(endpoint: path, method: "GET")
|
||||
}
|
||||
|
||||
@ -49,8 +51,11 @@ public struct StoreAPI {
|
||||
var path = "/store/order/{order_id}"
|
||||
let orderIdEscaped = "\(orderId)".addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
|
||||
path = path.replacingOccurrences(of: "{order_id}", with: orderIdEscaped, options: .literal, range: nil)
|
||||
|
||||
return RequestBuilder<Order>(endpoint: path, method: "GET")
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: nil,
|
||||
body: nil)
|
||||
return RequestBuilder<Order>(endpoint: path, method: "GET", parameters: parameters)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -61,11 +66,10 @@ public struct StoreAPI {
|
||||
*/
|
||||
public func placeOrder(body: Order) -> RequestBuilder<Order> {
|
||||
let path = "/store/order"
|
||||
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
parameters.append(Parameters(body))
|
||||
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: nil,
|
||||
body: AnyEncodable(body))
|
||||
return RequestBuilder<Order>(endpoint: path, method: "POST", parameters: parameters)
|
||||
}
|
||||
|
||||
|
@ -17,11 +17,10 @@ public struct UserAPI {
|
||||
*/
|
||||
public func createUser(body: User) -> RequestBuilder<Void> {
|
||||
let path = "/user"
|
||||
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
parameters.append(Parameters(body))
|
||||
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: nil,
|
||||
body: AnyEncodable(body))
|
||||
return RequestBuilder<Void>(endpoint: path, method: "POST", parameters: parameters)
|
||||
}
|
||||
|
||||
@ -33,11 +32,10 @@ public struct UserAPI {
|
||||
*/
|
||||
public func createUsersWithArrayInput(body: [User]) -> RequestBuilder<Void> {
|
||||
let path = "/user/createWithArray"
|
||||
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
parameters.append(Parameters(body))
|
||||
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: nil,
|
||||
body: AnyEncodable(body))
|
||||
return RequestBuilder<Void>(endpoint: path, method: "POST", parameters: parameters)
|
||||
}
|
||||
|
||||
@ -49,11 +47,10 @@ public struct UserAPI {
|
||||
*/
|
||||
public func createUsersWithListInput(body: [User]) -> RequestBuilder<Void> {
|
||||
let path = "/user/createWithList"
|
||||
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
parameters.append(Parameters(body))
|
||||
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: nil,
|
||||
body: AnyEncodable(body))
|
||||
return RequestBuilder<Void>(endpoint: path, method: "POST", parameters: parameters)
|
||||
}
|
||||
|
||||
@ -68,8 +65,11 @@ public struct UserAPI {
|
||||
var path = "/user/{username}"
|
||||
let usernameEscaped = "\(username)".addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
|
||||
path = path.replacingOccurrences(of: "{username}", with: usernameEscaped, options: .literal, range: nil)
|
||||
|
||||
return RequestBuilder<Void>(endpoint: path, method: "DELETE")
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: nil,
|
||||
body: nil)
|
||||
return RequestBuilder<Void>(endpoint: path, method: "DELETE", parameters: parameters)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -82,8 +82,11 @@ public struct UserAPI {
|
||||
var path = "/user/{username}"
|
||||
let usernameEscaped = "\(username)".addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
|
||||
path = path.replacingOccurrences(of: "{username}", with: usernameEscaped, options: .literal, range: nil)
|
||||
|
||||
return RequestBuilder<User>(endpoint: path, method: "GET")
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: nil,
|
||||
body: nil)
|
||||
return RequestBuilder<User>(endpoint: path, method: "GET", parameters: parameters)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -96,14 +99,10 @@ public struct UserAPI {
|
||||
*/
|
||||
public func loginUser(username: String, password: String) -> RequestBuilder<String> {
|
||||
let path = "/user/login"
|
||||
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
let queryParams: [String: Any?] = [
|
||||
"username": username,
|
||||
"password": password
|
||||
]
|
||||
parameters.append(Parameters(queryParams))
|
||||
let parameters = Parameters(
|
||||
query: ["username": username, "password": password],
|
||||
form: nil,
|
||||
body: nil)
|
||||
return RequestBuilder<String>(endpoint: path, method: "GET", parameters: parameters)
|
||||
}
|
||||
|
||||
@ -114,7 +113,6 @@ public struct UserAPI {
|
||||
*/
|
||||
public func logoutUser() -> RequestBuilder<Void> {
|
||||
let path = "/user/logout"
|
||||
|
||||
return RequestBuilder<Void>(endpoint: path, method: "GET")
|
||||
}
|
||||
|
||||
@ -130,11 +128,10 @@ public struct UserAPI {
|
||||
var path = "/user/{username}"
|
||||
let usernameEscaped = "\(username)".addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
|
||||
path = path.replacingOccurrences(of: "{username}", with: usernameEscaped, options: .literal, range: nil)
|
||||
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
parameters.append(Parameters(body))
|
||||
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: nil,
|
||||
body: AnyEncodable(body))
|
||||
return RequestBuilder<Void>(endpoint: path, method: "PUT", parameters: parameters)
|
||||
}
|
||||
|
||||
|
@ -1,71 +0,0 @@
|
||||
//
|
||||
// CodableHelper.swift
|
||||
//
|
||||
// Generated by openapi-generator
|
||||
// https://openapi-generator.tech
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
public typealias EncodeResult = (data: Data?, error: Error?)
|
||||
|
||||
open class CodableHelper {
|
||||
|
||||
public static var dateformatter: DateFormatter?
|
||||
|
||||
open class func decode<T>(_ type: T.Type, from data: Data) -> (decodableObj: T?, error: Error?) where T: Decodable {
|
||||
var returnedDecodable: T?
|
||||
var returnedError: Error?
|
||||
|
||||
let decoder = JSONDecoder()
|
||||
if let df = self.dateformatter {
|
||||
decoder.dateDecodingStrategy = .formatted(df)
|
||||
} else {
|
||||
decoder.dataDecodingStrategy = .base64
|
||||
let formatter = DateFormatter()
|
||||
formatter.calendar = Calendar(identifier: .iso8601)
|
||||
formatter.locale = Locale(identifier: "en_US_POSIX")
|
||||
formatter.timeZone = TimeZone(secondsFromGMT: 0)
|
||||
formatter.dateFormat = Configuration.dateFormat
|
||||
decoder.dateDecodingStrategy = .formatted(formatter)
|
||||
}
|
||||
|
||||
do {
|
||||
returnedDecodable = try decoder.decode(type, from: data)
|
||||
} catch {
|
||||
returnedError = error
|
||||
}
|
||||
|
||||
return (returnedDecodable, returnedError)
|
||||
}
|
||||
|
||||
open class func encode<T>(_ value: T, prettyPrint: Bool = false) -> EncodeResult where T: Encodable {
|
||||
var returnedData: Data?
|
||||
var returnedError: Error?
|
||||
|
||||
let encoder = JSONEncoder()
|
||||
if prettyPrint {
|
||||
encoder.outputFormatting = .prettyPrinted
|
||||
}
|
||||
if let df = self.dateformatter {
|
||||
encoder.dateEncodingStrategy = .formatted(df)
|
||||
} else {
|
||||
encoder.dataEncodingStrategy = .base64
|
||||
let formatter = DateFormatter()
|
||||
formatter.calendar = Calendar(identifier: .iso8601)
|
||||
formatter.locale = Locale(identifier: "en_US_POSIX")
|
||||
formatter.timeZone = TimeZone(secondsFromGMT: 0)
|
||||
formatter.dateFormat = Configuration.dateFormat
|
||||
encoder.dateEncodingStrategy = .formatted(formatter)
|
||||
}
|
||||
|
||||
do {
|
||||
returnedData = try encoder.encode(value)
|
||||
} catch {
|
||||
returnedError = error
|
||||
}
|
||||
|
||||
return (returnedData, returnedError)
|
||||
}
|
||||
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
// Models.swift
|
||||
//
|
||||
// Generated by openapi-generator
|
||||
// https://openapi-generator.tech
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
protocol JSONEncodable {
|
||||
func encodeToJSON() -> Any
|
||||
}
|
||||
|
||||
public enum ErrorResponse: Error {
|
||||
case error(Int, Data?, Error)
|
||||
}
|
||||
|
||||
open class Response<T> {
|
||||
public let statusCode: Int
|
||||
public let header: [String: String]
|
||||
public let body: T?
|
||||
|
||||
public init(statusCode: Int, header: [String: String], body: T?) {
|
||||
self.statusCode = statusCode
|
||||
self.header = header
|
||||
self.body = body
|
||||
}
|
||||
|
||||
public convenience init(response: HTTPURLResponse, body: T?) {
|
||||
let rawHeader = response.allHeaderFields
|
||||
var header = [String: String]()
|
||||
for case let (key, value) as (String, String) in rawHeader {
|
||||
header[key] = value
|
||||
}
|
||||
self.init(statusCode: response.statusCode, header: header, body: body)
|
||||
}
|
||||
}
|
@ -43,13 +43,12 @@ playground.xcworkspace
|
||||
# you should judge for yourself, the pros and cons are mentioned at:
|
||||
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
||||
#
|
||||
# Pods/
|
||||
Pods/
|
||||
|
||||
# Carthage
|
||||
#
|
||||
# Add this line if you want to avoid checking in source code from Carthage dependencies.
|
||||
# Carthage/Checkouts
|
||||
|
||||
Carthage/Checkouts
|
||||
Carthage/Build
|
||||
|
||||
# fastlane
|
||||
|
@ -9,10 +9,10 @@ import Foundation
|
||||
public struct RequestBuilder<Response> {
|
||||
public let endpoint: String
|
||||
public let method: String
|
||||
public let parameters: [Parameters]
|
||||
public let parameters: Parameters?
|
||||
public let headers: [String: String]
|
||||
|
||||
public init(endpoint: String, method: String, parameters: [Parameters] = [], headers: [String: String] = [:]) {
|
||||
public init(endpoint: String, method: String, parameters: Parameters? = nil, headers: [String: String] = [:]) {
|
||||
self.endpoint = endpoint
|
||||
self.method = method
|
||||
self.parameters = parameters
|
||||
@ -20,21 +20,15 @@ public struct RequestBuilder<Response> {
|
||||
}
|
||||
}
|
||||
|
||||
public enum Parameters {
|
||||
case query([String: Any?])
|
||||
case form([String: String?])
|
||||
case json(AnyEncodable)
|
||||
public struct Parameters {
|
||||
var query: [String: Any?]?
|
||||
var form: [String: String?]?
|
||||
var body: AnyEncodable?
|
||||
|
||||
public init(_ raw: [String: Any?]) {
|
||||
self = .query(raw)
|
||||
}
|
||||
|
||||
public init(_ raw: [String: String?]) {
|
||||
self = .form(raw)
|
||||
}
|
||||
|
||||
public init<T: Encodable>(_ raw: T) {
|
||||
self = .json(AnyEncodable(raw))
|
||||
public init(query: [String: Any?]? = nil, form: [String: String?]? = nil, body: AnyEncodable? = nil) {
|
||||
self.query = query
|
||||
self.form = form
|
||||
self.body = body
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -17,11 +17,10 @@ public struct AnotherFakeAPI {
|
||||
*/
|
||||
public func call123testSpecialTags(body: Client) -> RequestBuilder<Client> {
|
||||
let path = "/another-fake/dummy"
|
||||
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
parameters.append(Parameters(body))
|
||||
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: nil,
|
||||
body: AnyEncodable(body))
|
||||
return RequestBuilder<Client>(endpoint: path, method: "PATCH", parameters: parameters)
|
||||
}
|
||||
|
||||
|
@ -16,11 +16,10 @@ public struct FakeAPI {
|
||||
*/
|
||||
public func fakeOuterBooleanSerialize(body: Bool? = nil) -> RequestBuilder<Bool> {
|
||||
let path = "/fake/outer/boolean"
|
||||
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
parameters.append(Parameters(body))
|
||||
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: nil,
|
||||
body: AnyEncodable(body))
|
||||
return RequestBuilder<Bool>(endpoint: path, method: "POST", parameters: parameters)
|
||||
}
|
||||
|
||||
@ -32,11 +31,10 @@ public struct FakeAPI {
|
||||
*/
|
||||
public func fakeOuterCompositeSerialize(body: OuterComposite? = nil) -> RequestBuilder<OuterComposite> {
|
||||
let path = "/fake/outer/composite"
|
||||
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
parameters.append(Parameters(body))
|
||||
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: nil,
|
||||
body: AnyEncodable(body))
|
||||
return RequestBuilder<OuterComposite>(endpoint: path, method: "POST", parameters: parameters)
|
||||
}
|
||||
|
||||
@ -48,11 +46,10 @@ public struct FakeAPI {
|
||||
*/
|
||||
public func fakeOuterNumberSerialize(body: Double? = nil) -> RequestBuilder<Double> {
|
||||
let path = "/fake/outer/number"
|
||||
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
parameters.append(Parameters(body))
|
||||
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: nil,
|
||||
body: AnyEncodable(body))
|
||||
return RequestBuilder<Double>(endpoint: path, method: "POST", parameters: parameters)
|
||||
}
|
||||
|
||||
@ -64,11 +61,10 @@ public struct FakeAPI {
|
||||
*/
|
||||
public func fakeOuterStringSerialize(body: String? = nil) -> RequestBuilder<String> {
|
||||
let path = "/fake/outer/string"
|
||||
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
parameters.append(Parameters(body))
|
||||
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: nil,
|
||||
body: AnyEncodable(body))
|
||||
return RequestBuilder<String>(endpoint: path, method: "POST", parameters: parameters)
|
||||
}
|
||||
|
||||
@ -80,11 +76,10 @@ public struct FakeAPI {
|
||||
*/
|
||||
public func testBodyWithFileSchema(body: FileSchemaTestClass) -> RequestBuilder<Void> {
|
||||
let path = "/fake/body-with-file-schema"
|
||||
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
parameters.append(Parameters(body))
|
||||
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: nil,
|
||||
body: AnyEncodable(body))
|
||||
return RequestBuilder<Void>(endpoint: path, method: "PUT", parameters: parameters)
|
||||
}
|
||||
|
||||
@ -96,15 +91,10 @@ public struct FakeAPI {
|
||||
*/
|
||||
public func testBodyWithQueryParams(query: String, body: User) -> RequestBuilder<Void> {
|
||||
let path = "/fake/body-with-query-params"
|
||||
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
parameters.append(Parameters(body))
|
||||
|
||||
let queryParams: [String: Any?] = [
|
||||
"query": query
|
||||
]
|
||||
parameters.append(Parameters(queryParams))
|
||||
let parameters = Parameters(
|
||||
query: ["query": query],
|
||||
form: nil,
|
||||
body: AnyEncodable(body))
|
||||
return RequestBuilder<Void>(endpoint: path, method: "PUT", parameters: parameters)
|
||||
}
|
||||
|
||||
@ -117,11 +107,10 @@ public struct FakeAPI {
|
||||
*/
|
||||
public func testClientModel(body: Client) -> RequestBuilder<Client> {
|
||||
let path = "/fake"
|
||||
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
parameters.append(Parameters(body))
|
||||
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: nil,
|
||||
body: AnyEncodable(body))
|
||||
return RequestBuilder<Client>(endpoint: path, method: "PATCH", parameters: parameters)
|
||||
}
|
||||
|
||||
@ -150,26 +139,10 @@ public struct FakeAPI {
|
||||
*/
|
||||
public func testEndpointParameters(number: Double, double: Double, patternWithoutDelimiter: String, byte: Data, integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, float: Float? = nil, string: String? = nil, binary: URL? = nil, date: Date? = nil, dateTime: Date? = nil, password: String? = nil, callback: String? = nil) -> RequestBuilder<Void> {
|
||||
let path = "/fake"
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
let formParams: [String: String?] = [
|
||||
"integer": integer?.description,
|
||||
"int32": int32?.description,
|
||||
"int64": int64?.description,
|
||||
"number": number.description,
|
||||
"float": float?.description,
|
||||
"double": double.description,
|
||||
"string": string,
|
||||
"pattern_without_delimiter": patternWithoutDelimiter,
|
||||
"byte": byte.description,
|
||||
"binary": binary?.description,
|
||||
"date": date?.description,
|
||||
"dateTime": dateTime?.description,
|
||||
"password": password,
|
||||
"callback": callback
|
||||
]
|
||||
parameters.append(Parameters(formParams))
|
||||
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: ["integer": integer?.description, "int32": int32?.description, "int64": int64?.description, "number": number.description, "float": float?.description, "double": double.description, "string": string, "pattern_without_delimiter": patternWithoutDelimiter, "byte": byte.description, "binary": binary?.description, "date": date?.description, "dateTime": dateTime?.description, "password": password, "callback": callback],
|
||||
body: nil)
|
||||
return RequestBuilder<Void>(endpoint: path, method: "POST", parameters: parameters)
|
||||
}
|
||||
|
||||
@ -256,21 +229,10 @@ public struct FakeAPI {
|
||||
*/
|
||||
public func testEnumParameters(enumHeaderStringArray: [String]? = nil, enumHeaderString: EnumHeaderString_testEnumParameters? = nil, enumQueryStringArray: [String]? = nil, enumQueryString: EnumQueryString_testEnumParameters? = nil, enumQueryInteger: EnumQueryInteger_testEnumParameters? = nil, enumQueryDouble: EnumQueryDouble_testEnumParameters? = nil, enumFormStringArray: [String]? = nil, enumFormString: EnumFormString_testEnumParameters? = nil) -> RequestBuilder<Void> {
|
||||
let path = "/fake"
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
let formParams: [String: String?] = [
|
||||
"enum_form_string_array": enumFormStringArray?.description,
|
||||
"enum_form_string": enumFormString?.rawValue
|
||||
]
|
||||
parameters.append(Parameters(formParams))
|
||||
|
||||
let queryParams: [String: Any?] = [
|
||||
"enum_query_string_array": enumQueryStringArray,
|
||||
"enum_query_string": enumQueryString,
|
||||
"enum_query_integer": enumQueryInteger,
|
||||
"enum_query_double": enumQueryDouble
|
||||
]
|
||||
parameters.append(Parameters(queryParams))
|
||||
let parameters = Parameters(
|
||||
query: ["enum_query_string_array": enumQueryStringArray, "enum_query_string": enumQueryString, "enum_query_integer": enumQueryInteger, "enum_query_double": enumQueryDouble],
|
||||
form: ["enum_form_string_array": enumFormStringArray?.description, "enum_form_string": enumFormString?.rawValue],
|
||||
body: nil)
|
||||
return RequestBuilder<Void>(endpoint: path, method: "GET", parameters: parameters)
|
||||
}
|
||||
|
||||
@ -288,16 +250,10 @@ public struct FakeAPI {
|
||||
*/
|
||||
public func testGroupParameters(requiredStringGroup: Int, requiredBooleanGroup: Bool, requiredInt64Group: Int64, stringGroup: Int? = nil, booleanGroup: Bool? = nil, int64Group: Int64? = nil) -> RequestBuilder<Void> {
|
||||
let path = "/fake"
|
||||
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
let queryParams: [String: Any?] = [
|
||||
"required_string_group": requiredStringGroup,
|
||||
"required_int64_group": requiredInt64Group,
|
||||
"string_group": stringGroup,
|
||||
"int64_group": int64Group
|
||||
]
|
||||
parameters.append(Parameters(queryParams))
|
||||
let parameters = Parameters(
|
||||
query: ["required_string_group": requiredStringGroup, "required_int64_group": requiredInt64Group, "string_group": stringGroup, "int64_group": int64Group],
|
||||
form: nil,
|
||||
body: nil)
|
||||
return RequestBuilder<Void>(endpoint: path, method: "DELETE", parameters: parameters)
|
||||
}
|
||||
|
||||
@ -309,11 +265,10 @@ public struct FakeAPI {
|
||||
*/
|
||||
public func testInlineAdditionalProperties(param: [String: String]) -> RequestBuilder<Void> {
|
||||
let path = "/fake/inline-additionalProperties"
|
||||
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
parameters.append(Parameters(param))
|
||||
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: nil,
|
||||
body: AnyEncodable(param))
|
||||
return RequestBuilder<Void>(endpoint: path, method: "POST", parameters: parameters)
|
||||
}
|
||||
|
||||
@ -326,14 +281,10 @@ public struct FakeAPI {
|
||||
*/
|
||||
public func testJsonFormData(param: String, param2: String) -> RequestBuilder<Void> {
|
||||
let path = "/fake/jsonFormData"
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
let formParams: [String: String?] = [
|
||||
"param": param,
|
||||
"param2": param2
|
||||
]
|
||||
parameters.append(Parameters(formParams))
|
||||
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: ["param": param, "param2": param2],
|
||||
body: nil)
|
||||
return RequestBuilder<Void>(endpoint: path, method: "GET", parameters: parameters)
|
||||
}
|
||||
|
||||
|
@ -20,11 +20,10 @@ public struct FakeClassnameTags123API {
|
||||
*/
|
||||
public func testClassname(body: Client) -> RequestBuilder<Client> {
|
||||
let path = "/fake_classname_test"
|
||||
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
parameters.append(Parameters(body))
|
||||
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: nil,
|
||||
body: AnyEncodable(body))
|
||||
return RequestBuilder<Client>(endpoint: path, method: "PATCH", parameters: parameters)
|
||||
}
|
||||
|
||||
|
@ -19,11 +19,10 @@ public struct PetAPI {
|
||||
*/
|
||||
public func addPet(body: Pet) -> RequestBuilder<Void> {
|
||||
let path = "/pet"
|
||||
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
parameters.append(Parameters(body))
|
||||
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: nil,
|
||||
body: AnyEncodable(body))
|
||||
return RequestBuilder<Void>(endpoint: path, method: "POST", parameters: parameters)
|
||||
}
|
||||
|
||||
@ -41,8 +40,11 @@ public struct PetAPI {
|
||||
var path = "/pet/{petId}"
|
||||
let petIdEscaped = "\(petId)".addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
|
||||
path = path.replacingOccurrences(of: "{petId}", with: petIdEscaped, options: .literal, range: nil)
|
||||
|
||||
return RequestBuilder<Void>(endpoint: path, method: "DELETE")
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: nil,
|
||||
body: nil)
|
||||
return RequestBuilder<Void>(endpoint: path, method: "DELETE", parameters: parameters)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -66,13 +68,10 @@ public struct PetAPI {
|
||||
*/
|
||||
public func findPetsByStatus(status: [String]) -> RequestBuilder<[Pet]> {
|
||||
let path = "/pet/findByStatus"
|
||||
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
let queryParams: [String: Any?] = [
|
||||
"status": status
|
||||
]
|
||||
parameters.append(Parameters(queryParams))
|
||||
let parameters = Parameters(
|
||||
query: ["status": status],
|
||||
form: nil,
|
||||
body: nil)
|
||||
return RequestBuilder<[Pet]>(endpoint: path, method: "GET", parameters: parameters)
|
||||
}
|
||||
|
||||
@ -88,13 +87,10 @@ public struct PetAPI {
|
||||
*/
|
||||
public func findPetsByTags(tags: [String]) -> RequestBuilder<[Pet]> {
|
||||
let path = "/pet/findByTags"
|
||||
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
let queryParams: [String: Any?] = [
|
||||
"tags": tags
|
||||
]
|
||||
parameters.append(Parameters(queryParams))
|
||||
let parameters = Parameters(
|
||||
query: ["tags": tags],
|
||||
form: nil,
|
||||
body: nil)
|
||||
return RequestBuilder<[Pet]>(endpoint: path, method: "GET", parameters: parameters)
|
||||
}
|
||||
|
||||
@ -112,8 +108,11 @@ public struct PetAPI {
|
||||
var path = "/pet/{petId}"
|
||||
let petIdEscaped = "\(petId)".addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
|
||||
path = path.replacingOccurrences(of: "{petId}", with: petIdEscaped, options: .literal, range: nil)
|
||||
|
||||
return RequestBuilder<Pet>(endpoint: path, method: "GET")
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: nil,
|
||||
body: nil)
|
||||
return RequestBuilder<Pet>(endpoint: path, method: "GET", parameters: parameters)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -127,11 +126,10 @@ public struct PetAPI {
|
||||
*/
|
||||
public func updatePet(body: Pet) -> RequestBuilder<Void> {
|
||||
let path = "/pet"
|
||||
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
parameters.append(Parameters(body))
|
||||
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: nil,
|
||||
body: AnyEncodable(body))
|
||||
return RequestBuilder<Void>(endpoint: path, method: "PUT", parameters: parameters)
|
||||
}
|
||||
|
||||
@ -150,14 +148,10 @@ public struct PetAPI {
|
||||
var path = "/pet/{petId}"
|
||||
let petIdEscaped = "\(petId)".addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
|
||||
path = path.replacingOccurrences(of: "{petId}", with: petIdEscaped, options: .literal, range: nil)
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
let formParams: [String: String?] = [
|
||||
"name": name,
|
||||
"status": status
|
||||
]
|
||||
parameters.append(Parameters(formParams))
|
||||
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: ["name": name, "status": status],
|
||||
body: nil)
|
||||
return RequestBuilder<Void>(endpoint: path, method: "POST", parameters: parameters)
|
||||
}
|
||||
|
||||
@ -176,14 +170,10 @@ public struct PetAPI {
|
||||
var path = "/pet/{petId}/uploadImage"
|
||||
let petIdEscaped = "\(petId)".addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
|
||||
path = path.replacingOccurrences(of: "{petId}", with: petIdEscaped, options: .literal, range: nil)
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
let formParams: [String: String?] = [
|
||||
"additionalMetadata": additionalMetadata,
|
||||
"file": file?.description
|
||||
]
|
||||
parameters.append(Parameters(formParams))
|
||||
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: ["additionalMetadata": additionalMetadata, "file": file?.description],
|
||||
body: nil)
|
||||
return RequestBuilder<ApiResponse>(endpoint: path, method: "POST", parameters: parameters)
|
||||
}
|
||||
|
||||
@ -202,14 +192,10 @@ public struct PetAPI {
|
||||
var path = "/fake/{petId}/uploadImageWithRequiredFile"
|
||||
let petIdEscaped = "\(petId)".addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
|
||||
path = path.replacingOccurrences(of: "{petId}", with: petIdEscaped, options: .literal, range: nil)
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
let formParams: [String: String?] = [
|
||||
"additionalMetadata": additionalMetadata,
|
||||
"requiredFile": requiredFile.description
|
||||
]
|
||||
parameters.append(Parameters(formParams))
|
||||
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: ["additionalMetadata": additionalMetadata, "requiredFile": requiredFile.description],
|
||||
body: nil)
|
||||
return RequestBuilder<ApiResponse>(endpoint: path, method: "POST", parameters: parameters)
|
||||
}
|
||||
|
||||
|
@ -19,8 +19,11 @@ public struct StoreAPI {
|
||||
var path = "/store/order/{order_id}"
|
||||
let orderIdEscaped = "\(orderId)".addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
|
||||
path = path.replacingOccurrences(of: "{order_id}", with: orderIdEscaped, options: .literal, range: nil)
|
||||
|
||||
return RequestBuilder<Void>(endpoint: path, method: "DELETE")
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: nil,
|
||||
body: nil)
|
||||
return RequestBuilder<Void>(endpoint: path, method: "DELETE", parameters: parameters)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -34,7 +37,6 @@ public struct StoreAPI {
|
||||
*/
|
||||
public func getInventory() -> RequestBuilder<[String: Int]> {
|
||||
let path = "/store/inventory"
|
||||
|
||||
return RequestBuilder<[String: Int]>(endpoint: path, method: "GET")
|
||||
}
|
||||
|
||||
@ -49,8 +51,11 @@ public struct StoreAPI {
|
||||
var path = "/store/order/{order_id}"
|
||||
let orderIdEscaped = "\(orderId)".addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
|
||||
path = path.replacingOccurrences(of: "{order_id}", with: orderIdEscaped, options: .literal, range: nil)
|
||||
|
||||
return RequestBuilder<Order>(endpoint: path, method: "GET")
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: nil,
|
||||
body: nil)
|
||||
return RequestBuilder<Order>(endpoint: path, method: "GET", parameters: parameters)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -61,11 +66,10 @@ public struct StoreAPI {
|
||||
*/
|
||||
public func placeOrder(body: Order) -> RequestBuilder<Order> {
|
||||
let path = "/store/order"
|
||||
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
parameters.append(Parameters(body))
|
||||
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: nil,
|
||||
body: AnyEncodable(body))
|
||||
return RequestBuilder<Order>(endpoint: path, method: "POST", parameters: parameters)
|
||||
}
|
||||
|
||||
|
@ -17,11 +17,10 @@ public struct UserAPI {
|
||||
*/
|
||||
public func createUser(body: User) -> RequestBuilder<Void> {
|
||||
let path = "/user"
|
||||
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
parameters.append(Parameters(body))
|
||||
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: nil,
|
||||
body: AnyEncodable(body))
|
||||
return RequestBuilder<Void>(endpoint: path, method: "POST", parameters: parameters)
|
||||
}
|
||||
|
||||
@ -33,11 +32,10 @@ public struct UserAPI {
|
||||
*/
|
||||
public func createUsersWithArrayInput(body: [User]) -> RequestBuilder<Void> {
|
||||
let path = "/user/createWithArray"
|
||||
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
parameters.append(Parameters(body))
|
||||
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: nil,
|
||||
body: AnyEncodable(body))
|
||||
return RequestBuilder<Void>(endpoint: path, method: "POST", parameters: parameters)
|
||||
}
|
||||
|
||||
@ -49,11 +47,10 @@ public struct UserAPI {
|
||||
*/
|
||||
public func createUsersWithListInput(body: [User]) -> RequestBuilder<Void> {
|
||||
let path = "/user/createWithList"
|
||||
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
parameters.append(Parameters(body))
|
||||
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: nil,
|
||||
body: AnyEncodable(body))
|
||||
return RequestBuilder<Void>(endpoint: path, method: "POST", parameters: parameters)
|
||||
}
|
||||
|
||||
@ -68,8 +65,11 @@ public struct UserAPI {
|
||||
var path = "/user/{username}"
|
||||
let usernameEscaped = "\(username)".addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
|
||||
path = path.replacingOccurrences(of: "{username}", with: usernameEscaped, options: .literal, range: nil)
|
||||
|
||||
return RequestBuilder<Void>(endpoint: path, method: "DELETE")
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: nil,
|
||||
body: nil)
|
||||
return RequestBuilder<Void>(endpoint: path, method: "DELETE", parameters: parameters)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -82,8 +82,11 @@ public struct UserAPI {
|
||||
var path = "/user/{username}"
|
||||
let usernameEscaped = "\(username)".addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
|
||||
path = path.replacingOccurrences(of: "{username}", with: usernameEscaped, options: .literal, range: nil)
|
||||
|
||||
return RequestBuilder<User>(endpoint: path, method: "GET")
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: nil,
|
||||
body: nil)
|
||||
return RequestBuilder<User>(endpoint: path, method: "GET", parameters: parameters)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -96,14 +99,10 @@ public struct UserAPI {
|
||||
*/
|
||||
public func loginUser(username: String, password: String) -> RequestBuilder<String> {
|
||||
let path = "/user/login"
|
||||
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
let queryParams: [String: Any?] = [
|
||||
"username": username,
|
||||
"password": password
|
||||
]
|
||||
parameters.append(Parameters(queryParams))
|
||||
let parameters = Parameters(
|
||||
query: ["username": username, "password": password],
|
||||
form: nil,
|
||||
body: nil)
|
||||
return RequestBuilder<String>(endpoint: path, method: "GET", parameters: parameters)
|
||||
}
|
||||
|
||||
@ -114,7 +113,6 @@ public struct UserAPI {
|
||||
*/
|
||||
public func logoutUser() -> RequestBuilder<Void> {
|
||||
let path = "/user/logout"
|
||||
|
||||
return RequestBuilder<Void>(endpoint: path, method: "GET")
|
||||
}
|
||||
|
||||
@ -130,11 +128,10 @@ public struct UserAPI {
|
||||
var path = "/user/{username}"
|
||||
let usernameEscaped = "\(username)".addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
|
||||
path = path.replacingOccurrences(of: "{username}", with: usernameEscaped, options: .literal, range: nil)
|
||||
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
parameters.append(Parameters(body))
|
||||
|
||||
let parameters = Parameters(
|
||||
query: nil,
|
||||
form: nil,
|
||||
body: AnyEncodable(body))
|
||||
return RequestBuilder<Void>(endpoint: path, method: "PUT", parameters: parameters)
|
||||
}
|
||||
|
||||
|
5
samples/client/test/swift5default/.gitignore
vendored
5
samples/client/test/swift5default/.gitignore
vendored
@ -43,13 +43,12 @@ playground.xcworkspace
|
||||
# you should judge for yourself, the pros and cons are mentioned at:
|
||||
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
||||
#
|
||||
# Pods/
|
||||
Pods/
|
||||
|
||||
# Carthage
|
||||
#
|
||||
# Add this line if you want to avoid checking in source code from Carthage dependencies.
|
||||
# Carthage/Checkouts
|
||||
|
||||
Carthage/Checkouts
|
||||
Carthage/Build
|
||||
|
||||
# fastlane
|
||||
|
@ -9,10 +9,10 @@ import Foundation
|
||||
public struct RequestBuilder<Response> {
|
||||
public let endpoint: String
|
||||
public let method: String
|
||||
public let parameters: [Parameters]
|
||||
public let parameters: Parameters?
|
||||
public let headers: [String: String]
|
||||
|
||||
public init(endpoint: String, method: String, parameters: [Parameters] = [], headers: [String: String] = [:]) {
|
||||
public init(endpoint: String, method: String, parameters: Parameters? = nil, headers: [String: String] = [:]) {
|
||||
self.endpoint = endpoint
|
||||
self.method = method
|
||||
self.parameters = parameters
|
||||
@ -20,21 +20,15 @@ public struct RequestBuilder<Response> {
|
||||
}
|
||||
}
|
||||
|
||||
public enum Parameters {
|
||||
case query([String: Any?])
|
||||
case form([String: String?])
|
||||
case json(AnyEncodable)
|
||||
public struct Parameters {
|
||||
var query: [String: Any?]?
|
||||
var form: [String: String?]?
|
||||
var body: AnyEncodable?
|
||||
|
||||
public init(_ raw: [String: Any?]) {
|
||||
self = .query(raw)
|
||||
}
|
||||
|
||||
public init(_ raw: [String: String?]) {
|
||||
self = .form(raw)
|
||||
}
|
||||
|
||||
public init<T: Encodable>(_ raw: T) {
|
||||
self = .json(AnyEncodable(raw))
|
||||
public init(query: [String: Any?]? = nil, form: [String: String?]? = nil, body: AnyEncodable? = nil) {
|
||||
self.query = query
|
||||
self.form = form
|
||||
self.body = body
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -17,13 +17,10 @@ public struct Swift4TestAPI {
|
||||
*/
|
||||
public func getAllModels(clientId: String) -> RequestBuilder<GetAllModelsResult> {
|
||||
let path = "/allModels"
|
||||
|
||||
var parameters: [Parameters] = []
|
||||
|
||||
let queryParams: [String: Any?] = [
|
||||
"client_id": clientId
|
||||
]
|
||||
parameters.append(Parameters(queryParams))
|
||||
let parameters = Parameters(
|
||||
query: ["client_id": clientId],
|
||||
form: nil,
|
||||
body: nil)
|
||||
return RequestBuilder<GetAllModelsResult>(endpoint: path, method: "GET", parameters: parameters)
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user