forked from loafle/openapi-generator-original
Swift3: properly percent-escape path parameters (#6705)
* Add addiitional files from upstream * Remove mis-added files * Swift3: Properly percent-escape path parameters This change fixes the following issue: https://github.com/swagger-api/swagger-codegen/issues/6400 The problem was that path parameters were not properly percent-escaped before being placed into the URL path. This leads to creation of an invalid URL, which then fails. So therefore, in the API template where path parameters are handled, we propertly percent escape them, using the characters which are allowed in URL paths. In addition to this template change, then this PR includes the following changes: 1. Resulting changes in all generated code due to the above template change. 2. I added the objcCompatible run to the swift3-petstore-all.sh so that I could re-generated all of the generated code with a single script. 3. I added a unit test in UserAPITests.swift which verifies that paths are properly escaped. 4. In order to make the unit test work, then I needed access to RequestBuilder<T>.URLString to verify that the path was properly escaped. However, RequestBuilder<T>.URLString had "internal" access control so it was inaccessible from the unit test. So therefore, I made four contants in RequestBuilder<T> to be public. This should not harm anything, since they are constants ("let's") and cannot be changed from the outside of the class after initialization. 5. There were also some stray changes which look like they were caused by having not run bin/swift3-petstore-all.sh in a while.
This commit is contained in:
parent
bc302f7151
commit
95ef1bf62e
@ -42,3 +42,7 @@ java $JAVA_OPTS -jar $executable $ags
|
||||
ags="$@ generate -t modules/swagger-codegen/src/main/resources/swift3 -i modules/swagger-codegen/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -l swift3 -c ./bin/swift3-petstore-unwraprequired.json -o samples/client/petstore/swift3/unwraprequired"
|
||||
echo "#### Petstore Swift API client (unwraprequired) ####"
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
|
||||
ags="$@ generate -t modules/swagger-codegen/src/main/resources/swift3 -i modules/swagger-codegen/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -l swift3 -c ./bin/swift3-petstore-objcCompatible.json -o samples/client/petstore/swift3/objcCompatible"
|
||||
echo "#### Petstore Swift API client (objcCompatible) ####"
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
|
@ -32,10 +32,10 @@ open class APIBase {
|
||||
open class RequestBuilder<T> {
|
||||
var credential: URLCredential?
|
||||
var headers: [String:String]
|
||||
let parameters: Any?
|
||||
let isBody: Bool
|
||||
let method: String
|
||||
let URLString: String
|
||||
public let parameters: Any?
|
||||
public let isBody: Bool
|
||||
public let method: String
|
||||
public let URLString: String
|
||||
|
||||
/// Optional block to obtain a reference to the request's progress instance when available.
|
||||
public var onProgressReady: ((Progress) -> ())?
|
||||
|
@ -120,7 +120,9 @@ open class {{classname}}: APIBase {
|
||||
*/
|
||||
open class func {{operationId}}WithRequestBuilder({{#allParams}}{{paramName}}: {{#isEnum}}{{#isContainer}}{{{dataType}}}{{/isContainer}}{{^isContainer}}{{{datatypeWithEnum}}}_{{operationId}}{{/isContainer}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}{{^required}}? = nil{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) -> RequestBuilder<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Void{{/returnType}}> {
|
||||
{{^pathParams}}let{{/pathParams}}{{#pathParams}}{{^secondaryParam}}var{{/secondaryParam}}{{/pathParams}} path = "{{{path}}}"{{#pathParams}}
|
||||
path = path.replacingOccurrences(of: "{{=<% %>=}}{<%baseName%>}<%={{ }}=%>", with: "\({{paramName}}{{#isEnum}}{{#isContainer}}{{{dataType}}}{{/isContainer}}{{^isContainer}}.rawValue{{/isContainer}}{{/isEnum}})", options: .literal, range: nil){{/pathParams}}
|
||||
let {{paramName}}PreEscape = "\({{paramName}}{{#isEnum}}{{#isContainer}}{{{dataType}}}{{/isContainer}}{{^isContainer}}.rawValue{{/isContainer}}{{/isEnum}})"
|
||||
let {{paramName}}PostEscape = {{paramName}}PreEscape.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
|
||||
path = path.replacingOccurrences(of: "{{=<% %>=}}{<%baseName%>}<%={{ }}=%>", with: {{paramName}}PostEscape, options: .literal, range: nil){{/pathParams}}
|
||||
let URLString = {{projectName}}API.basePath + path
|
||||
{{#bodyParam}}
|
||||
let parameters = {{paramName}}{{^required}}?{{/required}}.encodeToJSON()
|
||||
|
@ -32,10 +32,10 @@ open class APIBase {
|
||||
open class RequestBuilder<T> {
|
||||
var credential: URLCredential?
|
||||
var headers: [String:String]
|
||||
let parameters: Any?
|
||||
let isBody: Bool
|
||||
let method: String
|
||||
let URLString: String
|
||||
public let parameters: Any?
|
||||
public let isBody: Bool
|
||||
public let method: String
|
||||
public let URLString: String
|
||||
|
||||
/// Optional block to obtain a reference to the request's progress instance when available.
|
||||
public var onProgressReady: ((Progress) -> ())?
|
||||
|
@ -1,5 +1,5 @@
|
||||
//
|
||||
// AnotherFakeAPI.swift
|
||||
// AnotherfakeAPI.swift
|
||||
//
|
||||
// Generated by swagger-codegen
|
||||
// https://github.com/swagger-api/swagger-codegen
|
||||
@ -9,7 +9,7 @@ import Foundation
|
||||
import Alamofire
|
||||
|
||||
|
||||
open class AnotherFakeAPI: APIBase {
|
||||
open class AnotherfakeAPI: APIBase {
|
||||
/**
|
||||
To test special tags
|
||||
- parameter body: (body) client model
|
||||
|
@ -37,7 +37,7 @@ open class Fake_classname_tags123API: APIBase {
|
||||
open class func testClassnameWithRequestBuilder(body: Client) -> RequestBuilder<Client> {
|
||||
let path = "/fake_classname_test"
|
||||
let URLString = PetstoreClientAPI.basePath + path
|
||||
let parameters = body.encodeToJSON() as? [String:AnyObject]
|
||||
let parameters = body.encodeToJSON()
|
||||
|
||||
let url = NSURLComponents(string: URLString)
|
||||
|
||||
|
@ -70,7 +70,9 @@ open class PetAPI: APIBase {
|
||||
*/
|
||||
open class func deletePetWithRequestBuilder(petId: Int64, apiKey: String? = nil) -> RequestBuilder<Void> {
|
||||
var path = "/pet/{petId}"
|
||||
path = path.replacingOccurrences(of: "{petId}", with: "\(petId)", options: .literal, range: nil)
|
||||
let petIdPreEscape = "\(petId)"
|
||||
let petIdPostEscape = petIdPreEscape.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
|
||||
path = path.replacingOccurrences(of: "{petId}", with: petIdPostEscape, options: .literal, range: nil)
|
||||
let URLString = PetstoreClientAPI.basePath + path
|
||||
let parameters: [String:Any]? = nil
|
||||
|
||||
@ -412,7 +414,9 @@ open class PetAPI: APIBase {
|
||||
*/
|
||||
open class func getPetByIdWithRequestBuilder(petId: Int64) -> RequestBuilder<Pet> {
|
||||
var path = "/pet/{petId}"
|
||||
path = path.replacingOccurrences(of: "{petId}", with: "\(petId)", options: .literal, range: nil)
|
||||
let petIdPreEscape = "\(petId)"
|
||||
let petIdPostEscape = petIdPreEscape.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
|
||||
path = path.replacingOccurrences(of: "{petId}", with: petIdPostEscape, options: .literal, range: nil)
|
||||
let URLString = PetstoreClientAPI.basePath + path
|
||||
let parameters: [String:Any]? = nil
|
||||
|
||||
@ -485,7 +489,9 @@ open class PetAPI: APIBase {
|
||||
*/
|
||||
open class func updatePetWithFormWithRequestBuilder(petId: Int64, name: String? = nil, status: String? = nil) -> RequestBuilder<Void> {
|
||||
var path = "/pet/{petId}"
|
||||
path = path.replacingOccurrences(of: "{petId}", with: "\(petId)", options: .literal, range: nil)
|
||||
let petIdPreEscape = "\(petId)"
|
||||
let petIdPostEscape = petIdPreEscape.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
|
||||
path = path.replacingOccurrences(of: "{petId}", with: petIdPostEscape, options: .literal, range: nil)
|
||||
let URLString = PetstoreClientAPI.basePath + path
|
||||
let formParams: [String:Any?] = [
|
||||
"name": name,
|
||||
@ -535,7 +541,9 @@ open class PetAPI: APIBase {
|
||||
*/
|
||||
open class func uploadFileWithRequestBuilder(petId: Int64, additionalMetadata: String? = nil, file: URL? = nil) -> RequestBuilder<ApiResponse> {
|
||||
var path = "/pet/{petId}/uploadImage"
|
||||
path = path.replacingOccurrences(of: "{petId}", with: "\(petId)", options: .literal, range: nil)
|
||||
let petIdPreEscape = "\(petId)"
|
||||
let petIdPostEscape = petIdPreEscape.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
|
||||
path = path.replacingOccurrences(of: "{petId}", with: petIdPostEscape, options: .literal, range: nil)
|
||||
let URLString = PetstoreClientAPI.basePath + path
|
||||
let formParams: [String:Any?] = [
|
||||
"additionalMetadata": additionalMetadata,
|
||||
|
@ -32,7 +32,9 @@ open class StoreAPI: APIBase {
|
||||
*/
|
||||
open class func deleteOrderWithRequestBuilder(orderId: String) -> RequestBuilder<Void> {
|
||||
var path = "/store/order/{order_id}"
|
||||
path = path.replacingOccurrences(of: "{order_id}", with: "\(orderId)", options: .literal, range: nil)
|
||||
let orderIdPreEscape = "\(orderId)"
|
||||
let orderIdPostEscape = orderIdPreEscape.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
|
||||
path = path.replacingOccurrences(of: "{order_id}", with: orderIdPostEscape, options: .literal, range: nil)
|
||||
let URLString = PetstoreClientAPI.basePath + path
|
||||
let parameters: [String:Any]? = nil
|
||||
|
||||
@ -130,7 +132,9 @@ open class StoreAPI: APIBase {
|
||||
*/
|
||||
open class func getOrderByIdWithRequestBuilder(orderId: Int64) -> RequestBuilder<Order> {
|
||||
var path = "/store/order/{order_id}"
|
||||
path = path.replacingOccurrences(of: "{order_id}", with: "\(orderId)", options: .literal, range: nil)
|
||||
let orderIdPreEscape = "\(orderId)"
|
||||
let orderIdPostEscape = orderIdPreEscape.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
|
||||
path = path.replacingOccurrences(of: "{order_id}", with: orderIdPostEscape, options: .literal, range: nil)
|
||||
let URLString = PetstoreClientAPI.basePath + path
|
||||
let parameters: [String:Any]? = nil
|
||||
|
||||
|
@ -128,7 +128,9 @@ open class UserAPI: APIBase {
|
||||
*/
|
||||
open class func deleteUserWithRequestBuilder(username: String) -> RequestBuilder<Void> {
|
||||
var path = "/user/{username}"
|
||||
path = path.replacingOccurrences(of: "{username}", with: "\(username)", options: .literal, range: nil)
|
||||
let usernamePreEscape = "\(username)"
|
||||
let usernamePostEscape = usernamePreEscape.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
|
||||
path = path.replacingOccurrences(of: "{username}", with: usernamePostEscape, options: .literal, range: nil)
|
||||
let URLString = PetstoreClientAPI.basePath + path
|
||||
let parameters: [String:Any]? = nil
|
||||
|
||||
@ -199,7 +201,9 @@ open class UserAPI: APIBase {
|
||||
*/
|
||||
open class func getUserByNameWithRequestBuilder(username: String) -> RequestBuilder<User> {
|
||||
var path = "/user/{username}"
|
||||
path = path.replacingOccurrences(of: "{username}", with: "\(username)", options: .literal, range: nil)
|
||||
let usernamePreEscape = "\(username)"
|
||||
let usernamePostEscape = usernamePreEscape.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
|
||||
path = path.replacingOccurrences(of: "{username}", with: usernamePostEscape, options: .literal, range: nil)
|
||||
let URLString = PetstoreClientAPI.basePath + path
|
||||
let parameters: [String:Any]? = nil
|
||||
|
||||
@ -306,7 +310,9 @@ open class UserAPI: APIBase {
|
||||
*/
|
||||
open class func updateUserWithRequestBuilder(username: String, body: User) -> RequestBuilder<Void> {
|
||||
var path = "/user/{username}"
|
||||
path = path.replacingOccurrences(of: "{username}", with: "\(username)", options: .literal, range: nil)
|
||||
let usernamePreEscape = "\(username)"
|
||||
let usernamePostEscape = usernamePreEscape.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
|
||||
path = path.replacingOccurrences(of: "{username}", with: usernamePostEscape, options: .literal, range: nil)
|
||||
let URLString = PetstoreClientAPI.basePath + path
|
||||
let parameters = body.encodeToJSON()
|
||||
|
||||
|
@ -151,4 +151,14 @@ class UserAPITests: XCTestCase {
|
||||
self.waitForExpectations(timeout: testTimeout, handler: nil)
|
||||
}
|
||||
|
||||
func testPathParamsAreEscaped() {
|
||||
// The path for this operation is /user/{userId}. In order to make a usable path,
|
||||
// then we must make sure that {userId} is percent-escaped when it is substituted
|
||||
// into the path. So we intentionally introduce a path with spaces.
|
||||
let userRequestBuilder = UserAPI.getUserByNameWithRequestBuilder(username: "User Name With Spaces")
|
||||
let urlContainsSpace = userRequestBuilder.URLString.contains(" ")
|
||||
|
||||
XCTAssert(!urlContainsSpace, "Expected URL to be escaped, but it was not.")
|
||||
}
|
||||
|
||||
}
|
||||
|
63
samples/client/petstore/swift3/objcCompatible/.gitignore
vendored
Normal file
63
samples/client/petstore/swift3/objcCompatible/.gitignore
vendored
Normal file
@ -0,0 +1,63 @@
|
||||
# Xcode
|
||||
#
|
||||
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
|
||||
|
||||
## Build generated
|
||||
build/
|
||||
DerivedData
|
||||
|
||||
## Various settings
|
||||
*.pbxuser
|
||||
!default.pbxuser
|
||||
*.mode1v3
|
||||
!default.mode1v3
|
||||
*.mode2v3
|
||||
!default.mode2v3
|
||||
*.perspectivev3
|
||||
!default.perspectivev3
|
||||
xcuserdata
|
||||
|
||||
## Other
|
||||
*.xccheckout
|
||||
*.moved-aside
|
||||
*.xcuserstate
|
||||
*.xcscmblueprint
|
||||
|
||||
## Obj-C/Swift specific
|
||||
*.hmap
|
||||
*.ipa
|
||||
|
||||
## Playgrounds
|
||||
timeline.xctimeline
|
||||
playground.xcworkspace
|
||||
|
||||
# Swift Package Manager
|
||||
#
|
||||
# Add this line if you want to avoid checking in source code from Swift Package Manager dependencies.
|
||||
# Packages/
|
||||
.build/
|
||||
|
||||
# CocoaPods
|
||||
#
|
||||
# We recommend against adding the Pods directory to your .gitignore. However
|
||||
# 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/
|
||||
|
||||
# Carthage
|
||||
#
|
||||
# Add this line if you want to avoid checking in source code from Carthage dependencies.
|
||||
# Carthage/Checkouts
|
||||
|
||||
Carthage/Build
|
||||
|
||||
# fastlane
|
||||
#
|
||||
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
|
||||
# screenshots whenever they are needed.
|
||||
# For more information about the recommended setup visit:
|
||||
# https://github.com/fastlane/fastlane/blob/master/docs/Gitignore.md
|
||||
|
||||
fastlane/report.xml
|
||||
fastlane/screenshots
|
@ -0,0 +1,23 @@
|
||||
# Swagger Codegen Ignore
|
||||
# Generated by swagger-codegen https://github.com/swagger-api/swagger-codegen
|
||||
|
||||
# Use this file to prevent files from being overwritten by the generator.
|
||||
# The patterns follow closely to .gitignore or .dockerignore.
|
||||
|
||||
# As an example, the C# client generator defines ApiClient.cs.
|
||||
# You can make changes and tell Swagger Codgen to ignore just this file by uncommenting the following line:
|
||||
#ApiClient.cs
|
||||
|
||||
# You can match any string of characters against a directory, file or extension with a single asterisk (*):
|
||||
#foo/*/qux
|
||||
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux
|
||||
|
||||
# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
|
||||
#foo/**/qux
|
||||
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux
|
||||
|
||||
# You can also negate patterns with an exclamation (!).
|
||||
# For example, you can ignore all files in a docs folder with the file extension .md:
|
||||
#docs/*.md
|
||||
# Then explicitly reverse the ignore rule for a single file:
|
||||
#!docs/README.md
|
@ -0,0 +1 @@
|
||||
2.3.0-SNAPSHOT
|
1
samples/client/petstore/swift3/objcCompatible/Cartfile
Normal file
1
samples/client/petstore/swift3/objcCompatible/Cartfile
Normal file
@ -0,0 +1 @@
|
||||
github "Alamofire/Alamofire" >= 3.1.0
|
@ -0,0 +1,13 @@
|
||||
Pod::Spec.new do |s|
|
||||
s.name = 'PetstoreClient'
|
||||
s.ios.deployment_target = '9.0'
|
||||
s.osx.deployment_target = '10.11'
|
||||
s.version = '0.0.1'
|
||||
s.source = { :git => 'git@github.com:swagger-api/swagger-mustache.git', :tag => 'v1.0.0' }
|
||||
s.authors = ''
|
||||
s.license = 'Proprietary'
|
||||
s.homepage = 'https://github.com/swagger-api/swagger-codegen'
|
||||
s.summary = 'PetstoreClient'
|
||||
s.source_files = 'PetstoreClient/Classes/**/*.swift'
|
||||
s.dependency 'Alamofire', '~> 4.5.0'
|
||||
end
|
@ -0,0 +1,75 @@
|
||||
// APIHelper.swift
|
||||
//
|
||||
// Generated by swagger-codegen
|
||||
// https://github.com/swagger-api/swagger-codegen
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
class APIHelper {
|
||||
static func rejectNil(_ source: [String:Any?]) -> [String:Any]? {
|
||||
var destination = [String:Any]()
|
||||
for (key, nillableValue) in source {
|
||||
if let value: Any = nillableValue {
|
||||
destination[key] = value
|
||||
}
|
||||
}
|
||||
|
||||
if destination.isEmpty {
|
||||
return nil
|
||||
}
|
||||
return destination
|
||||
}
|
||||
|
||||
static func rejectNilHeaders(_ source: [String:Any?]) -> [String:String] {
|
||||
var destination = [String:String]()
|
||||
for (key, nillableValue) in source {
|
||||
if let value: Any = nillableValue {
|
||||
destination[key] = "\(value)"
|
||||
}
|
||||
}
|
||||
return destination
|
||||
}
|
||||
|
||||
static func convertBoolToString(_ source: [String: Any]?) -> [String:Any]? {
|
||||
guard let source = source else {
|
||||
return nil
|
||||
}
|
||||
var destination = [String:Any]()
|
||||
let theTrue = NSNumber(value: true as Bool)
|
||||
let theFalse = NSNumber(value: false as Bool)
|
||||
for (key, value) in source {
|
||||
switch value {
|
||||
case let x where x as? NSNumber === theTrue || x as? NSNumber === theFalse:
|
||||
destination[key] = "\(value as! Bool)" as Any?
|
||||
default:
|
||||
destination[key] = value
|
||||
}
|
||||
}
|
||||
return destination
|
||||
}
|
||||
|
||||
static func mapValuesToQueryItems(values: [String:Any?]) -> [URLQueryItem]? {
|
||||
let returnValues = values
|
||||
.filter { $0.1 != nil }
|
||||
.map { (item: (_key: String, _value: Any?)) -> [URLQueryItem] in
|
||||
if let value = item._value as? Array<String> {
|
||||
return value.map { (v) -> URLQueryItem in
|
||||
URLQueryItem(
|
||||
name: item._key,
|
||||
value: v
|
||||
)
|
||||
}
|
||||
} else {
|
||||
return [URLQueryItem(
|
||||
name: item._key,
|
||||
value: "\(item._value!)"
|
||||
)]
|
||||
}
|
||||
}
|
||||
.flatMap { $0 }
|
||||
|
||||
if returnValues.isEmpty { return nil }
|
||||
return returnValues
|
||||
}
|
||||
}
|
@ -0,0 +1,77 @@
|
||||
// APIs.swift
|
||||
//
|
||||
// Generated by swagger-codegen
|
||||
// https://github.com/swagger-api/swagger-codegen
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
open class PetstoreClientAPI {
|
||||
open static var basePath = "http://petstore.swagger.io:80/v2"
|
||||
open static var credential: URLCredential?
|
||||
open static var customHeaders: [String:String] = [:]
|
||||
open static var requestBuilderFactory: RequestBuilderFactory = AlamofireRequestBuilderFactory()
|
||||
}
|
||||
|
||||
open class APIBase {
|
||||
func toParameters(_ encodable: JSONEncodable?) -> [String: Any]? {
|
||||
let encoded: Any? = encodable?.encodeToJSON()
|
||||
|
||||
if encoded! is [Any] {
|
||||
var dictionary = [String:Any]()
|
||||
for (index, item) in (encoded as! [Any]).enumerated() {
|
||||
dictionary["\(index)"] = item
|
||||
}
|
||||
return dictionary
|
||||
} else {
|
||||
return encoded as? [String:Any]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
open class RequestBuilder<T> {
|
||||
var credential: URLCredential?
|
||||
var headers: [String:String]
|
||||
public let parameters: Any?
|
||||
public let isBody: Bool
|
||||
public let method: String
|
||||
public let URLString: String
|
||||
|
||||
/// Optional block to obtain a reference to the request's progress instance when available.
|
||||
public var onProgressReady: ((Progress) -> ())?
|
||||
|
||||
required public init(method: String, URLString: String, parameters: Any?, isBody: Bool, headers: [String:String] = [:]) {
|
||||
self.method = method
|
||||
self.URLString = URLString
|
||||
self.parameters = parameters
|
||||
self.isBody = isBody
|
||||
self.headers = headers
|
||||
|
||||
addHeaders(PetstoreClientAPI.customHeaders)
|
||||
}
|
||||
|
||||
open func addHeaders(_ aHeaders:[String:String]) {
|
||||
for (header, value) in aHeaders {
|
||||
addHeader(name: header, value: value)
|
||||
}
|
||||
}
|
||||
|
||||
open func execute(_ completion: @escaping (_ response: Response<T>?, _ error: ErrorResponse?) -> Void) { }
|
||||
|
||||
@discardableResult public func addHeader(name: String, value: String) -> Self {
|
||||
if !value.isEmpty {
|
||||
headers[name] = value
|
||||
}
|
||||
return self
|
||||
}
|
||||
|
||||
open func addCredential() -> Self {
|
||||
self.credential = PetstoreClientAPI.credential
|
||||
return self
|
||||
}
|
||||
}
|
||||
|
||||
public protocol RequestBuilderFactory {
|
||||
func getBuilder<T>() -> RequestBuilder<T>.Type
|
||||
}
|
||||
|
@ -0,0 +1,48 @@
|
||||
//
|
||||
// AnotherfakeAPI.swift
|
||||
//
|
||||
// Generated by swagger-codegen
|
||||
// https://github.com/swagger-api/swagger-codegen
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import Alamofire
|
||||
|
||||
|
||||
open class AnotherfakeAPI: APIBase {
|
||||
/**
|
||||
To test special tags
|
||||
- parameter body: (body) client model
|
||||
- parameter completion: completion handler to receive the data and the error objects
|
||||
*/
|
||||
open class func testSpecialTags(body: Client, completion: @escaping ((_ data: Client?, _ error: ErrorResponse?) -> Void)) {
|
||||
testSpecialTagsWithRequestBuilder(body: body).execute { (response, error) -> Void in
|
||||
completion(response?.body, error)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
To test special tags
|
||||
- PATCH /another-fake/dummy
|
||||
- To test special tags
|
||||
|
||||
- examples: [{contentType=application/json, example={
|
||||
"client" : "client"
|
||||
}}]
|
||||
- parameter body: (body) client model
|
||||
- returns: RequestBuilder<Client>
|
||||
*/
|
||||
open class func testSpecialTagsWithRequestBuilder(body: Client) -> RequestBuilder<Client> {
|
||||
let path = "/another-fake/dummy"
|
||||
let URLString = PetstoreClientAPI.basePath + path
|
||||
let parameters = body.encodeToJSON()
|
||||
|
||||
let url = NSURLComponents(string: URLString)
|
||||
|
||||
let requestBuilder: RequestBuilder<Client>.Type = PetstoreClientAPI.requestBuilderFactory.getBuilder()
|
||||
|
||||
return requestBuilder.init(method: "PATCH", URLString: (url?.string ?? URLString), parameters: parameters, isBody: true)
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,424 @@
|
||||
//
|
||||
// FakeAPI.swift
|
||||
//
|
||||
// Generated by swagger-codegen
|
||||
// https://github.com/swagger-api/swagger-codegen
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import Alamofire
|
||||
|
||||
|
||||
open class FakeAPI: APIBase {
|
||||
/**
|
||||
- parameter body: (body) Input boolean as post body (optional)
|
||||
- parameter completion: completion handler to receive the data and the error objects
|
||||
*/
|
||||
open class func fakeOuterBooleanSerialize(body: OuterBoolean? = nil, completion: @escaping ((_ data: OuterBoolean?, _ error: ErrorResponse?) -> Void)) {
|
||||
fakeOuterBooleanSerializeWithRequestBuilder(body: body).execute { (response, error) -> Void in
|
||||
completion(response?.body, error)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
- POST /fake/outer/boolean
|
||||
- Test serialization of outer boolean types
|
||||
|
||||
- examples: [{contentType=application/json, example={ }}]
|
||||
- parameter body: (body) Input boolean as post body (optional)
|
||||
- returns: RequestBuilder<OuterBoolean>
|
||||
*/
|
||||
open class func fakeOuterBooleanSerializeWithRequestBuilder(body: OuterBoolean? = nil) -> RequestBuilder<OuterBoolean> {
|
||||
let path = "/fake/outer/boolean"
|
||||
let URLString = PetstoreClientAPI.basePath + path
|
||||
let parameters = body?.encodeToJSON()
|
||||
|
||||
let url = NSURLComponents(string: URLString)
|
||||
|
||||
let requestBuilder: RequestBuilder<OuterBoolean>.Type = PetstoreClientAPI.requestBuilderFactory.getBuilder()
|
||||
|
||||
return requestBuilder.init(method: "POST", URLString: (url?.string ?? URLString), parameters: parameters, isBody: true)
|
||||
}
|
||||
|
||||
/**
|
||||
- parameter body: (body) Input composite as post body (optional)
|
||||
- parameter completion: completion handler to receive the data and the error objects
|
||||
*/
|
||||
open class func fakeOuterCompositeSerialize(body: OuterComposite? = nil, completion: @escaping ((_ data: OuterComposite?, _ error: ErrorResponse?) -> Void)) {
|
||||
fakeOuterCompositeSerializeWithRequestBuilder(body: body).execute { (response, error) -> Void in
|
||||
completion(response?.body, error)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
- POST /fake/outer/composite
|
||||
- Test serialization of object with outer number type
|
||||
|
||||
- examples: [{contentType=application/json, example={
|
||||
"my_string" : { },
|
||||
"my_number" : { },
|
||||
"my_boolean" : { }
|
||||
}}]
|
||||
- parameter body: (body) Input composite as post body (optional)
|
||||
- returns: RequestBuilder<OuterComposite>
|
||||
*/
|
||||
open class func fakeOuterCompositeSerializeWithRequestBuilder(body: OuterComposite? = nil) -> RequestBuilder<OuterComposite> {
|
||||
let path = "/fake/outer/composite"
|
||||
let URLString = PetstoreClientAPI.basePath + path
|
||||
let parameters = body?.encodeToJSON()
|
||||
|
||||
let url = NSURLComponents(string: URLString)
|
||||
|
||||
let requestBuilder: RequestBuilder<OuterComposite>.Type = PetstoreClientAPI.requestBuilderFactory.getBuilder()
|
||||
|
||||
return requestBuilder.init(method: "POST", URLString: (url?.string ?? URLString), parameters: parameters, isBody: true)
|
||||
}
|
||||
|
||||
/**
|
||||
- parameter body: (body) Input number as post body (optional)
|
||||
- parameter completion: completion handler to receive the data and the error objects
|
||||
*/
|
||||
open class func fakeOuterNumberSerialize(body: OuterNumber? = nil, completion: @escaping ((_ data: OuterNumber?, _ error: ErrorResponse?) -> Void)) {
|
||||
fakeOuterNumberSerializeWithRequestBuilder(body: body).execute { (response, error) -> Void in
|
||||
completion(response?.body, error)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
- POST /fake/outer/number
|
||||
- Test serialization of outer number types
|
||||
|
||||
- examples: [{contentType=application/json, example={ }}]
|
||||
- parameter body: (body) Input number as post body (optional)
|
||||
- returns: RequestBuilder<OuterNumber>
|
||||
*/
|
||||
open class func fakeOuterNumberSerializeWithRequestBuilder(body: OuterNumber? = nil) -> RequestBuilder<OuterNumber> {
|
||||
let path = "/fake/outer/number"
|
||||
let URLString = PetstoreClientAPI.basePath + path
|
||||
let parameters = body?.encodeToJSON()
|
||||
|
||||
let url = NSURLComponents(string: URLString)
|
||||
|
||||
let requestBuilder: RequestBuilder<OuterNumber>.Type = PetstoreClientAPI.requestBuilderFactory.getBuilder()
|
||||
|
||||
return requestBuilder.init(method: "POST", URLString: (url?.string ?? URLString), parameters: parameters, isBody: true)
|
||||
}
|
||||
|
||||
/**
|
||||
- parameter body: (body) Input string as post body (optional)
|
||||
- parameter completion: completion handler to receive the data and the error objects
|
||||
*/
|
||||
open class func fakeOuterStringSerialize(body: OuterString? = nil, completion: @escaping ((_ data: OuterString?, _ error: ErrorResponse?) -> Void)) {
|
||||
fakeOuterStringSerializeWithRequestBuilder(body: body).execute { (response, error) -> Void in
|
||||
completion(response?.body, error)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
- POST /fake/outer/string
|
||||
- Test serialization of outer string types
|
||||
|
||||
- examples: [{contentType=application/json, example={ }}]
|
||||
- parameter body: (body) Input string as post body (optional)
|
||||
- returns: RequestBuilder<OuterString>
|
||||
*/
|
||||
open class func fakeOuterStringSerializeWithRequestBuilder(body: OuterString? = nil) -> RequestBuilder<OuterString> {
|
||||
let path = "/fake/outer/string"
|
||||
let URLString = PetstoreClientAPI.basePath + path
|
||||
let parameters = body?.encodeToJSON()
|
||||
|
||||
let url = NSURLComponents(string: URLString)
|
||||
|
||||
let requestBuilder: RequestBuilder<OuterString>.Type = PetstoreClientAPI.requestBuilderFactory.getBuilder()
|
||||
|
||||
return requestBuilder.init(method: "POST", URLString: (url?.string ?? URLString), parameters: parameters, isBody: true)
|
||||
}
|
||||
|
||||
/**
|
||||
To test \"client\" model
|
||||
- parameter body: (body) client model
|
||||
- parameter completion: completion handler to receive the data and the error objects
|
||||
*/
|
||||
open class func testClientModel(body: Client, completion: @escaping ((_ data: Client?, _ error: ErrorResponse?) -> Void)) {
|
||||
testClientModelWithRequestBuilder(body: body).execute { (response, error) -> Void in
|
||||
completion(response?.body, error)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
To test \"client\" model
|
||||
- PATCH /fake
|
||||
- To test \"client\" model
|
||||
|
||||
- examples: [{contentType=application/json, example={
|
||||
"client" : "client"
|
||||
}}]
|
||||
- parameter body: (body) client model
|
||||
- returns: RequestBuilder<Client>
|
||||
*/
|
||||
open class func testClientModelWithRequestBuilder(body: Client) -> RequestBuilder<Client> {
|
||||
let path = "/fake"
|
||||
let URLString = PetstoreClientAPI.basePath + path
|
||||
let parameters = body.encodeToJSON()
|
||||
|
||||
let url = NSURLComponents(string: URLString)
|
||||
|
||||
let requestBuilder: RequestBuilder<Client>.Type = PetstoreClientAPI.requestBuilderFactory.getBuilder()
|
||||
|
||||
return requestBuilder.init(method: "PATCH", URLString: (url?.string ?? URLString), parameters: parameters, isBody: true)
|
||||
}
|
||||
|
||||
/**
|
||||
Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트
|
||||
- parameter number: (form) None
|
||||
- parameter double: (form) None
|
||||
- parameter patternWithoutDelimiter: (form) None
|
||||
- parameter byte: (form) None
|
||||
- parameter integer: (form) None (optional)
|
||||
- parameter int32: (form) None (optional)
|
||||
- parameter int64: (form) None (optional)
|
||||
- parameter float: (form) None (optional)
|
||||
- parameter string: (form) None (optional)
|
||||
- parameter binary: (form) None (optional)
|
||||
- parameter date: (form) None (optional)
|
||||
- parameter dateTime: (form) None (optional)
|
||||
- parameter password: (form) None (optional)
|
||||
- parameter callback: (form) None (optional)
|
||||
- parameter completion: completion handler to receive the data and the error objects
|
||||
*/
|
||||
open class func testEndpointParameters(number: Double, double: Double, patternWithoutDelimiter: String, byte: Data, integer: Int32? = nil, int32: Int32? = nil, int64: Int64? = nil, float: Float? = nil, string: String? = nil, binary: Data? = nil, date: ISOFullDate? = nil, dateTime: Date? = nil, password: String? = nil, callback: String? = nil, completion: @escaping ((_ error: ErrorResponse?) -> Void)) {
|
||||
testEndpointParametersWithRequestBuilder(number: number, double: double, patternWithoutDelimiter: patternWithoutDelimiter, byte: byte, integer: integer, int32: int32, int64: int64, float: float, string: string, binary: binary, date: date, dateTime: dateTime, password: password, callback: callback).execute { (response, error) -> Void in
|
||||
completion(error)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트
|
||||
- POST /fake
|
||||
- Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트
|
||||
- BASIC:
|
||||
- type: basic
|
||||
- name: http_basic_test
|
||||
- parameter number: (form) None
|
||||
- parameter double: (form) None
|
||||
- parameter patternWithoutDelimiter: (form) None
|
||||
- parameter byte: (form) None
|
||||
- parameter integer: (form) None (optional)
|
||||
- parameter int32: (form) None (optional)
|
||||
- parameter int64: (form) None (optional)
|
||||
- parameter float: (form) None (optional)
|
||||
- parameter string: (form) None (optional)
|
||||
- parameter binary: (form) None (optional)
|
||||
- parameter date: (form) None (optional)
|
||||
- parameter dateTime: (form) None (optional)
|
||||
- parameter password: (form) None (optional)
|
||||
- parameter callback: (form) None (optional)
|
||||
- returns: RequestBuilder<Void>
|
||||
*/
|
||||
open class func testEndpointParametersWithRequestBuilder(number: Double, double: Double, patternWithoutDelimiter: String, byte: Data, integer: Int32? = nil, int32: Int32? = nil, int64: Int64? = nil, float: Float? = nil, string: String? = nil, binary: Data? = nil, date: ISOFullDate? = nil, dateTime: Date? = nil, password: String? = nil, callback: String? = nil) -> RequestBuilder<Void> {
|
||||
let path = "/fake"
|
||||
let URLString = PetstoreClientAPI.basePath + path
|
||||
let formParams: [String:Any?] = [
|
||||
"integer": integer?.encodeToJSON(),
|
||||
"int32": int32?.encodeToJSON(),
|
||||
"int64": int64?.encodeToJSON(),
|
||||
"number": number,
|
||||
"float": float,
|
||||
"double": double,
|
||||
"string": string,
|
||||
"pattern_without_delimiter": patternWithoutDelimiter,
|
||||
"byte": byte,
|
||||
"binary": binary,
|
||||
"date": date?.encodeToJSON(),
|
||||
"dateTime": dateTime?.encodeToJSON(),
|
||||
"password": password,
|
||||
"callback": callback
|
||||
]
|
||||
|
||||
let nonNullParameters = APIHelper.rejectNil(formParams)
|
||||
let parameters = APIHelper.convertBoolToString(nonNullParameters)
|
||||
|
||||
let url = NSURLComponents(string: URLString)
|
||||
|
||||
let requestBuilder: RequestBuilder<Void>.Type = PetstoreClientAPI.requestBuilderFactory.getBuilder()
|
||||
|
||||
return requestBuilder.init(method: "POST", URLString: (url?.string ?? URLString), parameters: parameters, isBody: false)
|
||||
}
|
||||
|
||||
/**
|
||||
* enum for parameter enumFormStringArray
|
||||
*/
|
||||
public enum EnumFormStringArray_testEnumParameters: String {
|
||||
case greaterThan = ">"
|
||||
case dollar = "$"
|
||||
}
|
||||
|
||||
/**
|
||||
* enum for parameter enumFormString
|
||||
*/
|
||||
public enum EnumFormString_testEnumParameters: String {
|
||||
case abc = "_abc"
|
||||
case efg = "-efg"
|
||||
case xyz = "(xyz)"
|
||||
}
|
||||
|
||||
/**
|
||||
* enum for parameter enumHeaderStringArray
|
||||
*/
|
||||
public enum EnumHeaderStringArray_testEnumParameters: String {
|
||||
case greaterThan = ">"
|
||||
case dollar = "$"
|
||||
}
|
||||
|
||||
/**
|
||||
* enum for parameter enumHeaderString
|
||||
*/
|
||||
public enum EnumHeaderString_testEnumParameters: String {
|
||||
case abc = "_abc"
|
||||
case efg = "-efg"
|
||||
case xyz = "(xyz)"
|
||||
}
|
||||
|
||||
/**
|
||||
* enum for parameter enumQueryStringArray
|
||||
*/
|
||||
public enum EnumQueryStringArray_testEnumParameters: String {
|
||||
case greaterThan = ">"
|
||||
case dollar = "$"
|
||||
}
|
||||
|
||||
/**
|
||||
* enum for parameter enumQueryString
|
||||
*/
|
||||
public enum EnumQueryString_testEnumParameters: String {
|
||||
case abc = "_abc"
|
||||
case efg = "-efg"
|
||||
case xyz = "(xyz)"
|
||||
}
|
||||
|
||||
/**
|
||||
* enum for parameter enumQueryInteger
|
||||
*/
|
||||
public enum EnumQueryInteger_testEnumParameters: Int32 {
|
||||
case _1 = 1
|
||||
case number2 = -2
|
||||
}
|
||||
|
||||
/**
|
||||
* enum for parameter enumQueryDouble
|
||||
*/
|
||||
public enum EnumQueryDouble_testEnumParameters: Double {
|
||||
case _11 = 1.1
|
||||
case number12 = -1.2
|
||||
}
|
||||
|
||||
/**
|
||||
To test enum parameters
|
||||
- parameter enumFormStringArray: (form) Form parameter enum test (string array) (optional)
|
||||
- parameter enumFormString: (form) Form parameter enum test (string) (optional, default to -efg)
|
||||
- parameter enumHeaderStringArray: (header) Header parameter enum test (string array) (optional)
|
||||
- parameter enumHeaderString: (header) Header parameter enum test (string) (optional, default to -efg)
|
||||
- parameter enumQueryStringArray: (query) Query parameter enum test (string array) (optional)
|
||||
- parameter enumQueryString: (query) Query parameter enum test (string) (optional, default to -efg)
|
||||
- parameter enumQueryInteger: (query) Query parameter enum test (double) (optional)
|
||||
- parameter enumQueryDouble: (form) Query parameter enum test (double) (optional)
|
||||
- parameter completion: completion handler to receive the data and the error objects
|
||||
*/
|
||||
open class func testEnumParameters(enumFormStringArray: [String]? = nil, enumFormString: EnumFormString_testEnumParameters? = nil, enumHeaderStringArray: [String]? = nil, enumHeaderString: EnumHeaderString_testEnumParameters? = nil, enumQueryStringArray: [String]? = nil, enumQueryString: EnumQueryString_testEnumParameters? = nil, enumQueryInteger: EnumQueryInteger_testEnumParameters? = nil, enumQueryDouble: EnumQueryDouble_testEnumParameters? = nil, completion: @escaping ((_ error: ErrorResponse?) -> Void)) {
|
||||
testEnumParametersWithRequestBuilder(enumFormStringArray: enumFormStringArray, enumFormString: enumFormString, enumHeaderStringArray: enumHeaderStringArray, enumHeaderString: enumHeaderString, enumQueryStringArray: enumQueryStringArray, enumQueryString: enumQueryString, enumQueryInteger: enumQueryInteger, enumQueryDouble: enumQueryDouble).execute { (response, error) -> Void in
|
||||
completion(error)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
To test enum parameters
|
||||
- GET /fake
|
||||
- To test enum parameters
|
||||
|
||||
- parameter enumFormStringArray: (form) Form parameter enum test (string array) (optional)
|
||||
- parameter enumFormString: (form) Form parameter enum test (string) (optional, default to -efg)
|
||||
- parameter enumHeaderStringArray: (header) Header parameter enum test (string array) (optional)
|
||||
- parameter enumHeaderString: (header) Header parameter enum test (string) (optional, default to -efg)
|
||||
- parameter enumQueryStringArray: (query) Query parameter enum test (string array) (optional)
|
||||
- parameter enumQueryString: (query) Query parameter enum test (string) (optional, default to -efg)
|
||||
- parameter enumQueryInteger: (query) Query parameter enum test (double) (optional)
|
||||
- parameter enumQueryDouble: (form) Query parameter enum test (double) (optional)
|
||||
- returns: RequestBuilder<Void>
|
||||
*/
|
||||
open class func testEnumParametersWithRequestBuilder(enumFormStringArray: [String]? = nil, enumFormString: EnumFormString_testEnumParameters? = nil, enumHeaderStringArray: [String]? = nil, enumHeaderString: EnumHeaderString_testEnumParameters? = nil, enumQueryStringArray: [String]? = nil, enumQueryString: EnumQueryString_testEnumParameters? = nil, enumQueryInteger: EnumQueryInteger_testEnumParameters? = nil, enumQueryDouble: EnumQueryDouble_testEnumParameters? = nil) -> RequestBuilder<Void> {
|
||||
let path = "/fake"
|
||||
let URLString = PetstoreClientAPI.basePath + path
|
||||
let formParams: [String:Any?] = [
|
||||
"enum_form_string_array": enumFormStringArray,
|
||||
"enum_form_string": enumFormString?.rawValue,
|
||||
"enum_query_double": enumQueryDouble?.rawValue
|
||||
]
|
||||
|
||||
let nonNullParameters = APIHelper.rejectNil(formParams)
|
||||
let parameters = APIHelper.convertBoolToString(nonNullParameters)
|
||||
|
||||
let url = NSURLComponents(string: URLString)
|
||||
url?.queryItems = APIHelper.mapValuesToQueryItems(values:[
|
||||
"enum_query_string_array": enumQueryStringArray,
|
||||
"enum_query_string": enumQueryString?.rawValue,
|
||||
"enum_query_integer": enumQueryInteger?.rawValue
|
||||
])
|
||||
let nillableHeaders: [String: Any?] = [
|
||||
"enum_header_string_array": enumHeaderStringArray,
|
||||
"enum_header_string": enumHeaderString?.rawValue
|
||||
]
|
||||
let headerParameters = APIHelper.rejectNilHeaders(nillableHeaders)
|
||||
|
||||
let requestBuilder: RequestBuilder<Void>.Type = PetstoreClientAPI.requestBuilderFactory.getBuilder()
|
||||
|
||||
return requestBuilder.init(method: "GET", URLString: (url?.string ?? URLString), parameters: parameters, isBody: false, headers: headerParameters)
|
||||
}
|
||||
|
||||
/**
|
||||
test json serialization of form data
|
||||
- parameter param: (form) field1
|
||||
- parameter param2: (form) field2
|
||||
- parameter completion: completion handler to receive the data and the error objects
|
||||
*/
|
||||
open class func testJsonFormData(param: String, param2: String, completion: @escaping ((_ error: ErrorResponse?) -> Void)) {
|
||||
testJsonFormDataWithRequestBuilder(param: param, param2: param2).execute { (response, error) -> Void in
|
||||
completion(error)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
test json serialization of form data
|
||||
- GET /fake/jsonFormData
|
||||
-
|
||||
|
||||
- parameter param: (form) field1
|
||||
- parameter param2: (form) field2
|
||||
- returns: RequestBuilder<Void>
|
||||
*/
|
||||
open class func testJsonFormDataWithRequestBuilder(param: String, param2: String) -> RequestBuilder<Void> {
|
||||
let path = "/fake/jsonFormData"
|
||||
let URLString = PetstoreClientAPI.basePath + path
|
||||
let formParams: [String:Any?] = [
|
||||
"param": param,
|
||||
"param2": param2
|
||||
]
|
||||
|
||||
let nonNullParameters = APIHelper.rejectNil(formParams)
|
||||
let parameters = APIHelper.convertBoolToString(nonNullParameters)
|
||||
|
||||
let url = NSURLComponents(string: URLString)
|
||||
|
||||
let requestBuilder: RequestBuilder<Void>.Type = PetstoreClientAPI.requestBuilderFactory.getBuilder()
|
||||
|
||||
return requestBuilder.init(method: "GET", URLString: (url?.string ?? URLString), parameters: parameters, isBody: false)
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
//
|
||||
// Fake_classname_tags123API.swift
|
||||
//
|
||||
// Generated by swagger-codegen
|
||||
// https://github.com/swagger-api/swagger-codegen
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import Alamofire
|
||||
|
||||
|
||||
open class Fake_classname_tags123API: APIBase {
|
||||
/**
|
||||
To test class name in snake case
|
||||
- parameter body: (body) client model
|
||||
- parameter completion: completion handler to receive the data and the error objects
|
||||
*/
|
||||
open class func testClassname(body: Client, completion: @escaping ((_ data: Client?, _ error: ErrorResponse?) -> Void)) {
|
||||
testClassnameWithRequestBuilder(body: body).execute { (response, error) -> Void in
|
||||
completion(response?.body, error)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
To test class name in snake case
|
||||
- PATCH /fake_classname_test
|
||||
- API Key:
|
||||
- type: apiKey api_key_query (QUERY)
|
||||
- name: api_key_query
|
||||
- examples: [{contentType=application/json, example={
|
||||
"client" : "client"
|
||||
}}]
|
||||
- parameter body: (body) client model
|
||||
- returns: RequestBuilder<Client>
|
||||
*/
|
||||
open class func testClassnameWithRequestBuilder(body: Client) -> RequestBuilder<Client> {
|
||||
let path = "/fake_classname_test"
|
||||
let URLString = PetstoreClientAPI.basePath + path
|
||||
let parameters = body.encodeToJSON()
|
||||
|
||||
let url = NSURLComponents(string: URLString)
|
||||
|
||||
let requestBuilder: RequestBuilder<Client>.Type = PetstoreClientAPI.requestBuilderFactory.getBuilder()
|
||||
|
||||
return requestBuilder.init(method: "PATCH", URLString: (url?.string ?? URLString), parameters: parameters, isBody: true)
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,563 @@
|
||||
//
|
||||
// PetAPI.swift
|
||||
//
|
||||
// Generated by swagger-codegen
|
||||
// https://github.com/swagger-api/swagger-codegen
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import Alamofire
|
||||
|
||||
|
||||
open class PetAPI: APIBase {
|
||||
/**
|
||||
Add a new pet to the store
|
||||
- parameter body: (body) Pet object that needs to be added to the store
|
||||
- parameter completion: completion handler to receive the data and the error objects
|
||||
*/
|
||||
open class func addPet(body: Pet, completion: @escaping ((_ error: ErrorResponse?) -> Void)) {
|
||||
addPetWithRequestBuilder(body: body).execute { (response, error) -> Void in
|
||||
completion(error)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Add a new pet to the store
|
||||
- POST /pet
|
||||
-
|
||||
- OAuth:
|
||||
- type: oauth2
|
||||
- name: petstore_auth
|
||||
- parameter body: (body) Pet object that needs to be added to the store
|
||||
- returns: RequestBuilder<Void>
|
||||
*/
|
||||
open class func addPetWithRequestBuilder(body: Pet) -> RequestBuilder<Void> {
|
||||
let path = "/pet"
|
||||
let URLString = PetstoreClientAPI.basePath + path
|
||||
let parameters = body.encodeToJSON()
|
||||
|
||||
let url = NSURLComponents(string: URLString)
|
||||
|
||||
let requestBuilder: RequestBuilder<Void>.Type = PetstoreClientAPI.requestBuilderFactory.getBuilder()
|
||||
|
||||
return requestBuilder.init(method: "POST", URLString: (url?.string ?? URLString), parameters: parameters, isBody: true)
|
||||
}
|
||||
|
||||
/**
|
||||
Deletes a pet
|
||||
- parameter petId: (path) Pet id to delete
|
||||
- parameter apiKey: (header) (optional)
|
||||
- parameter completion: completion handler to receive the data and the error objects
|
||||
*/
|
||||
open class func deletePet(petId: Int64, apiKey: String? = nil, completion: @escaping ((_ error: ErrorResponse?) -> Void)) {
|
||||
deletePetWithRequestBuilder(petId: petId, apiKey: apiKey).execute { (response, error) -> Void in
|
||||
completion(error)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Deletes a pet
|
||||
- DELETE /pet/{petId}
|
||||
-
|
||||
- OAuth:
|
||||
- type: oauth2
|
||||
- name: petstore_auth
|
||||
- parameter petId: (path) Pet id to delete
|
||||
- parameter apiKey: (header) (optional)
|
||||
- returns: RequestBuilder<Void>
|
||||
*/
|
||||
open class func deletePetWithRequestBuilder(petId: Int64, apiKey: String? = nil) -> RequestBuilder<Void> {
|
||||
var path = "/pet/{petId}"
|
||||
let petIdPreEscape = "\(petId)"
|
||||
let petIdPostEscape = petIdPreEscape.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
|
||||
path = path.replacingOccurrences(of: "{petId}", with: petIdPostEscape, options: .literal, range: nil)
|
||||
let URLString = PetstoreClientAPI.basePath + path
|
||||
let parameters: [String:Any]? = nil
|
||||
|
||||
let url = NSURLComponents(string: URLString)
|
||||
let nillableHeaders: [String: Any?] = [
|
||||
"api_key": apiKey
|
||||
]
|
||||
let headerParameters = APIHelper.rejectNilHeaders(nillableHeaders)
|
||||
|
||||
let requestBuilder: RequestBuilder<Void>.Type = PetstoreClientAPI.requestBuilderFactory.getBuilder()
|
||||
|
||||
return requestBuilder.init(method: "DELETE", URLString: (url?.string ?? URLString), parameters: parameters, isBody: false, headers: headerParameters)
|
||||
}
|
||||
|
||||
/**
|
||||
* enum for parameter status
|
||||
*/
|
||||
public enum Status_findPetsByStatus: String {
|
||||
case available = "available"
|
||||
case pending = "pending"
|
||||
case sold = "sold"
|
||||
}
|
||||
|
||||
/**
|
||||
Finds Pets by status
|
||||
- parameter status: (query) Status values that need to be considered for filter
|
||||
- parameter completion: completion handler to receive the data and the error objects
|
||||
*/
|
||||
open class func findPetsByStatus(status: [String], completion: @escaping ((_ data: [Pet]?, _ error: ErrorResponse?) -> Void)) {
|
||||
findPetsByStatusWithRequestBuilder(status: status).execute { (response, error) -> Void in
|
||||
completion(response?.body, error)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Finds Pets by status
|
||||
- GET /pet/findByStatus
|
||||
- Multiple status values can be provided with comma separated strings
|
||||
- OAuth:
|
||||
- type: oauth2
|
||||
- name: petstore_auth
|
||||
- examples: [{contentType=application/xml, example=<Pet>
|
||||
<id>123456789</id>
|
||||
<name>doggie</name>
|
||||
<photoUrls>
|
||||
<photoUrls>aeiou</photoUrls>
|
||||
</photoUrls>
|
||||
<tags>
|
||||
</tags>
|
||||
<status>aeiou</status>
|
||||
</Pet>}, {contentType=application/json, example=[ {
|
||||
"photoUrls" : [ "photoUrls", "photoUrls" ],
|
||||
"name" : "doggie",
|
||||
"id" : 0,
|
||||
"category" : {
|
||||
"name" : "name",
|
||||
"id" : 6
|
||||
},
|
||||
"tags" : [ {
|
||||
"name" : "name",
|
||||
"id" : 1
|
||||
}, {
|
||||
"name" : "name",
|
||||
"id" : 1
|
||||
} ],
|
||||
"status" : "available"
|
||||
}, {
|
||||
"photoUrls" : [ "photoUrls", "photoUrls" ],
|
||||
"name" : "doggie",
|
||||
"id" : 0,
|
||||
"category" : {
|
||||
"name" : "name",
|
||||
"id" : 6
|
||||
},
|
||||
"tags" : [ {
|
||||
"name" : "name",
|
||||
"id" : 1
|
||||
}, {
|
||||
"name" : "name",
|
||||
"id" : 1
|
||||
} ],
|
||||
"status" : "available"
|
||||
} ]}]
|
||||
- examples: [{contentType=application/xml, example=<Pet>
|
||||
<id>123456789</id>
|
||||
<name>doggie</name>
|
||||
<photoUrls>
|
||||
<photoUrls>aeiou</photoUrls>
|
||||
</photoUrls>
|
||||
<tags>
|
||||
</tags>
|
||||
<status>aeiou</status>
|
||||
</Pet>}, {contentType=application/json, example=[ {
|
||||
"photoUrls" : [ "photoUrls", "photoUrls" ],
|
||||
"name" : "doggie",
|
||||
"id" : 0,
|
||||
"category" : {
|
||||
"name" : "name",
|
||||
"id" : 6
|
||||
},
|
||||
"tags" : [ {
|
||||
"name" : "name",
|
||||
"id" : 1
|
||||
}, {
|
||||
"name" : "name",
|
||||
"id" : 1
|
||||
} ],
|
||||
"status" : "available"
|
||||
}, {
|
||||
"photoUrls" : [ "photoUrls", "photoUrls" ],
|
||||
"name" : "doggie",
|
||||
"id" : 0,
|
||||
"category" : {
|
||||
"name" : "name",
|
||||
"id" : 6
|
||||
},
|
||||
"tags" : [ {
|
||||
"name" : "name",
|
||||
"id" : 1
|
||||
}, {
|
||||
"name" : "name",
|
||||
"id" : 1
|
||||
} ],
|
||||
"status" : "available"
|
||||
} ]}]
|
||||
- parameter status: (query) Status values that need to be considered for filter
|
||||
- returns: RequestBuilder<[Pet]>
|
||||
*/
|
||||
open class func findPetsByStatusWithRequestBuilder(status: [String]) -> RequestBuilder<[Pet]> {
|
||||
let path = "/pet/findByStatus"
|
||||
let URLString = PetstoreClientAPI.basePath + path
|
||||
let parameters: [String:Any]? = nil
|
||||
|
||||
let url = NSURLComponents(string: URLString)
|
||||
url?.queryItems = APIHelper.mapValuesToQueryItems(values:[
|
||||
"status": status
|
||||
])
|
||||
|
||||
let requestBuilder: RequestBuilder<[Pet]>.Type = PetstoreClientAPI.requestBuilderFactory.getBuilder()
|
||||
|
||||
return requestBuilder.init(method: "GET", URLString: (url?.string ?? URLString), parameters: parameters, isBody: false)
|
||||
}
|
||||
|
||||
/**
|
||||
Finds Pets by tags
|
||||
- parameter tags: (query) Tags to filter by
|
||||
- parameter completion: completion handler to receive the data and the error objects
|
||||
*/
|
||||
open class func findPetsByTags(tags: [String], completion: @escaping ((_ data: [Pet]?, _ error: ErrorResponse?) -> Void)) {
|
||||
findPetsByTagsWithRequestBuilder(tags: tags).execute { (response, error) -> Void in
|
||||
completion(response?.body, error)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Finds Pets by tags
|
||||
- GET /pet/findByTags
|
||||
- Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
|
||||
- OAuth:
|
||||
- type: oauth2
|
||||
- name: petstore_auth
|
||||
- examples: [{contentType=application/xml, example=<Pet>
|
||||
<id>123456789</id>
|
||||
<name>doggie</name>
|
||||
<photoUrls>
|
||||
<photoUrls>aeiou</photoUrls>
|
||||
</photoUrls>
|
||||
<tags>
|
||||
</tags>
|
||||
<status>aeiou</status>
|
||||
</Pet>}, {contentType=application/json, example=[ {
|
||||
"photoUrls" : [ "photoUrls", "photoUrls" ],
|
||||
"name" : "doggie",
|
||||
"id" : 0,
|
||||
"category" : {
|
||||
"name" : "name",
|
||||
"id" : 6
|
||||
},
|
||||
"tags" : [ {
|
||||
"name" : "name",
|
||||
"id" : 1
|
||||
}, {
|
||||
"name" : "name",
|
||||
"id" : 1
|
||||
} ],
|
||||
"status" : "available"
|
||||
}, {
|
||||
"photoUrls" : [ "photoUrls", "photoUrls" ],
|
||||
"name" : "doggie",
|
||||
"id" : 0,
|
||||
"category" : {
|
||||
"name" : "name",
|
||||
"id" : 6
|
||||
},
|
||||
"tags" : [ {
|
||||
"name" : "name",
|
||||
"id" : 1
|
||||
}, {
|
||||
"name" : "name",
|
||||
"id" : 1
|
||||
} ],
|
||||
"status" : "available"
|
||||
} ]}]
|
||||
- examples: [{contentType=application/xml, example=<Pet>
|
||||
<id>123456789</id>
|
||||
<name>doggie</name>
|
||||
<photoUrls>
|
||||
<photoUrls>aeiou</photoUrls>
|
||||
</photoUrls>
|
||||
<tags>
|
||||
</tags>
|
||||
<status>aeiou</status>
|
||||
</Pet>}, {contentType=application/json, example=[ {
|
||||
"photoUrls" : [ "photoUrls", "photoUrls" ],
|
||||
"name" : "doggie",
|
||||
"id" : 0,
|
||||
"category" : {
|
||||
"name" : "name",
|
||||
"id" : 6
|
||||
},
|
||||
"tags" : [ {
|
||||
"name" : "name",
|
||||
"id" : 1
|
||||
}, {
|
||||
"name" : "name",
|
||||
"id" : 1
|
||||
} ],
|
||||
"status" : "available"
|
||||
}, {
|
||||
"photoUrls" : [ "photoUrls", "photoUrls" ],
|
||||
"name" : "doggie",
|
||||
"id" : 0,
|
||||
"category" : {
|
||||
"name" : "name",
|
||||
"id" : 6
|
||||
},
|
||||
"tags" : [ {
|
||||
"name" : "name",
|
||||
"id" : 1
|
||||
}, {
|
||||
"name" : "name",
|
||||
"id" : 1
|
||||
} ],
|
||||
"status" : "available"
|
||||
} ]}]
|
||||
- parameter tags: (query) Tags to filter by
|
||||
- returns: RequestBuilder<[Pet]>
|
||||
*/
|
||||
open class func findPetsByTagsWithRequestBuilder(tags: [String]) -> RequestBuilder<[Pet]> {
|
||||
let path = "/pet/findByTags"
|
||||
let URLString = PetstoreClientAPI.basePath + path
|
||||
let parameters: [String:Any]? = nil
|
||||
|
||||
let url = NSURLComponents(string: URLString)
|
||||
url?.queryItems = APIHelper.mapValuesToQueryItems(values:[
|
||||
"tags": tags
|
||||
])
|
||||
|
||||
let requestBuilder: RequestBuilder<[Pet]>.Type = PetstoreClientAPI.requestBuilderFactory.getBuilder()
|
||||
|
||||
return requestBuilder.init(method: "GET", URLString: (url?.string ?? URLString), parameters: parameters, isBody: false)
|
||||
}
|
||||
|
||||
/**
|
||||
Find pet by ID
|
||||
- parameter petId: (path) ID of pet to return
|
||||
- parameter completion: completion handler to receive the data and the error objects
|
||||
*/
|
||||
open class func getPetById(petId: Int64, completion: @escaping ((_ data: Pet?, _ error: ErrorResponse?) -> Void)) {
|
||||
getPetByIdWithRequestBuilder(petId: petId).execute { (response, error) -> Void in
|
||||
completion(response?.body, error)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Find pet by ID
|
||||
- GET /pet/{petId}
|
||||
- Returns a single pet
|
||||
- API Key:
|
||||
- type: apiKey api_key
|
||||
- name: api_key
|
||||
- examples: [{contentType=application/xml, example=<Pet>
|
||||
<id>123456789</id>
|
||||
<name>doggie</name>
|
||||
<photoUrls>
|
||||
<photoUrls>aeiou</photoUrls>
|
||||
</photoUrls>
|
||||
<tags>
|
||||
</tags>
|
||||
<status>aeiou</status>
|
||||
</Pet>}, {contentType=application/json, example={
|
||||
"photoUrls" : [ "photoUrls", "photoUrls" ],
|
||||
"name" : "doggie",
|
||||
"id" : 0,
|
||||
"category" : {
|
||||
"name" : "name",
|
||||
"id" : 6
|
||||
},
|
||||
"tags" : [ {
|
||||
"name" : "name",
|
||||
"id" : 1
|
||||
}, {
|
||||
"name" : "name",
|
||||
"id" : 1
|
||||
} ],
|
||||
"status" : "available"
|
||||
}}]
|
||||
- examples: [{contentType=application/xml, example=<Pet>
|
||||
<id>123456789</id>
|
||||
<name>doggie</name>
|
||||
<photoUrls>
|
||||
<photoUrls>aeiou</photoUrls>
|
||||
</photoUrls>
|
||||
<tags>
|
||||
</tags>
|
||||
<status>aeiou</status>
|
||||
</Pet>}, {contentType=application/json, example={
|
||||
"photoUrls" : [ "photoUrls", "photoUrls" ],
|
||||
"name" : "doggie",
|
||||
"id" : 0,
|
||||
"category" : {
|
||||
"name" : "name",
|
||||
"id" : 6
|
||||
},
|
||||
"tags" : [ {
|
||||
"name" : "name",
|
||||
"id" : 1
|
||||
}, {
|
||||
"name" : "name",
|
||||
"id" : 1
|
||||
} ],
|
||||
"status" : "available"
|
||||
}}]
|
||||
- parameter petId: (path) ID of pet to return
|
||||
- returns: RequestBuilder<Pet>
|
||||
*/
|
||||
open class func getPetByIdWithRequestBuilder(petId: Int64) -> RequestBuilder<Pet> {
|
||||
var path = "/pet/{petId}"
|
||||
let petIdPreEscape = "\(petId)"
|
||||
let petIdPostEscape = petIdPreEscape.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
|
||||
path = path.replacingOccurrences(of: "{petId}", with: petIdPostEscape, options: .literal, range: nil)
|
||||
let URLString = PetstoreClientAPI.basePath + path
|
||||
let parameters: [String:Any]? = nil
|
||||
|
||||
let url = NSURLComponents(string: URLString)
|
||||
|
||||
let requestBuilder: RequestBuilder<Pet>.Type = PetstoreClientAPI.requestBuilderFactory.getBuilder()
|
||||
|
||||
return requestBuilder.init(method: "GET", URLString: (url?.string ?? URLString), parameters: parameters, isBody: false)
|
||||
}
|
||||
|
||||
/**
|
||||
Update an existing pet
|
||||
- parameter body: (body) Pet object that needs to be added to the store
|
||||
- parameter completion: completion handler to receive the data and the error objects
|
||||
*/
|
||||
open class func updatePet(body: Pet, completion: @escaping ((_ error: ErrorResponse?) -> Void)) {
|
||||
updatePetWithRequestBuilder(body: body).execute { (response, error) -> Void in
|
||||
completion(error)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Update an existing pet
|
||||
- PUT /pet
|
||||
-
|
||||
- OAuth:
|
||||
- type: oauth2
|
||||
- name: petstore_auth
|
||||
- parameter body: (body) Pet object that needs to be added to the store
|
||||
- returns: RequestBuilder<Void>
|
||||
*/
|
||||
open class func updatePetWithRequestBuilder(body: Pet) -> RequestBuilder<Void> {
|
||||
let path = "/pet"
|
||||
let URLString = PetstoreClientAPI.basePath + path
|
||||
let parameters = body.encodeToJSON()
|
||||
|
||||
let url = NSURLComponents(string: URLString)
|
||||
|
||||
let requestBuilder: RequestBuilder<Void>.Type = PetstoreClientAPI.requestBuilderFactory.getBuilder()
|
||||
|
||||
return requestBuilder.init(method: "PUT", URLString: (url?.string ?? URLString), parameters: parameters, isBody: true)
|
||||
}
|
||||
|
||||
/**
|
||||
Updates a pet in the store with form data
|
||||
- parameter petId: (path) ID of pet that needs to be updated
|
||||
- parameter name: (form) Updated name of the pet (optional)
|
||||
- parameter status: (form) Updated status of the pet (optional)
|
||||
- parameter completion: completion handler to receive the data and the error objects
|
||||
*/
|
||||
open class func updatePetWithForm(petId: Int64, name: String? = nil, status: String? = nil, completion: @escaping ((_ error: ErrorResponse?) -> Void)) {
|
||||
updatePetWithFormWithRequestBuilder(petId: petId, name: name, status: status).execute { (response, error) -> Void in
|
||||
completion(error)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Updates a pet in the store with form data
|
||||
- POST /pet/{petId}
|
||||
-
|
||||
- OAuth:
|
||||
- type: oauth2
|
||||
- name: petstore_auth
|
||||
- parameter petId: (path) ID of pet that needs to be updated
|
||||
- parameter name: (form) Updated name of the pet (optional)
|
||||
- parameter status: (form) Updated status of the pet (optional)
|
||||
- returns: RequestBuilder<Void>
|
||||
*/
|
||||
open class func updatePetWithFormWithRequestBuilder(petId: Int64, name: String? = nil, status: String? = nil) -> RequestBuilder<Void> {
|
||||
var path = "/pet/{petId}"
|
||||
let petIdPreEscape = "\(petId)"
|
||||
let petIdPostEscape = petIdPreEscape.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
|
||||
path = path.replacingOccurrences(of: "{petId}", with: petIdPostEscape, options: .literal, range: nil)
|
||||
let URLString = PetstoreClientAPI.basePath + path
|
||||
let formParams: [String:Any?] = [
|
||||
"name": name,
|
||||
"status": status
|
||||
]
|
||||
|
||||
let nonNullParameters = APIHelper.rejectNil(formParams)
|
||||
let parameters = APIHelper.convertBoolToString(nonNullParameters)
|
||||
|
||||
let url = NSURLComponents(string: URLString)
|
||||
|
||||
let requestBuilder: RequestBuilder<Void>.Type = PetstoreClientAPI.requestBuilderFactory.getBuilder()
|
||||
|
||||
return requestBuilder.init(method: "POST", URLString: (url?.string ?? URLString), parameters: parameters, isBody: false)
|
||||
}
|
||||
|
||||
/**
|
||||
uploads an image
|
||||
- parameter petId: (path) ID of pet to update
|
||||
- parameter additionalMetadata: (form) Additional data to pass to server (optional)
|
||||
- parameter file: (form) file to upload (optional)
|
||||
- parameter completion: completion handler to receive the data and the error objects
|
||||
*/
|
||||
open class func uploadFile(petId: Int64, additionalMetadata: String? = nil, file: URL? = nil, completion: @escaping ((_ data: ApiResponse?, _ error: ErrorResponse?) -> Void)) {
|
||||
uploadFileWithRequestBuilder(petId: petId, additionalMetadata: additionalMetadata, file: file).execute { (response, error) -> Void in
|
||||
completion(response?.body, error)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
uploads an image
|
||||
- POST /pet/{petId}/uploadImage
|
||||
-
|
||||
- OAuth:
|
||||
- type: oauth2
|
||||
- name: petstore_auth
|
||||
- examples: [{contentType=application/json, example={
|
||||
"code" : 0,
|
||||
"type" : "type",
|
||||
"message" : "message"
|
||||
}}]
|
||||
- parameter petId: (path) ID of pet to update
|
||||
- parameter additionalMetadata: (form) Additional data to pass to server (optional)
|
||||
- parameter file: (form) file to upload (optional)
|
||||
- returns: RequestBuilder<ApiResponse>
|
||||
*/
|
||||
open class func uploadFileWithRequestBuilder(petId: Int64, additionalMetadata: String? = nil, file: URL? = nil) -> RequestBuilder<ApiResponse> {
|
||||
var path = "/pet/{petId}/uploadImage"
|
||||
let petIdPreEscape = "\(petId)"
|
||||
let petIdPostEscape = petIdPreEscape.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
|
||||
path = path.replacingOccurrences(of: "{petId}", with: petIdPostEscape, options: .literal, range: nil)
|
||||
let URLString = PetstoreClientAPI.basePath + path
|
||||
let formParams: [String:Any?] = [
|
||||
"additionalMetadata": additionalMetadata,
|
||||
"file": file
|
||||
]
|
||||
|
||||
let nonNullParameters = APIHelper.rejectNil(formParams)
|
||||
let parameters = APIHelper.convertBoolToString(nonNullParameters)
|
||||
|
||||
let url = NSURLComponents(string: URLString)
|
||||
|
||||
let requestBuilder: RequestBuilder<ApiResponse>.Type = PetstoreClientAPI.requestBuilderFactory.getBuilder()
|
||||
|
||||
return requestBuilder.init(method: "POST", URLString: (url?.string ?? URLString), parameters: parameters, isBody: false)
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,210 @@
|
||||
//
|
||||
// StoreAPI.swift
|
||||
//
|
||||
// Generated by swagger-codegen
|
||||
// https://github.com/swagger-api/swagger-codegen
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import Alamofire
|
||||
|
||||
|
||||
open class StoreAPI: APIBase {
|
||||
/**
|
||||
Delete purchase order by ID
|
||||
- parameter orderId: (path) ID of the order that needs to be deleted
|
||||
- parameter completion: completion handler to receive the data and the error objects
|
||||
*/
|
||||
open class func deleteOrder(orderId: String, completion: @escaping ((_ error: ErrorResponse?) -> Void)) {
|
||||
deleteOrderWithRequestBuilder(orderId: orderId).execute { (response, error) -> Void in
|
||||
completion(error)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Delete purchase order by ID
|
||||
- DELETE /store/order/{order_id}
|
||||
- For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
|
||||
|
||||
- parameter orderId: (path) ID of the order that needs to be deleted
|
||||
- returns: RequestBuilder<Void>
|
||||
*/
|
||||
open class func deleteOrderWithRequestBuilder(orderId: String) -> RequestBuilder<Void> {
|
||||
var path = "/store/order/{order_id}"
|
||||
let orderIdPreEscape = "\(orderId)"
|
||||
let orderIdPostEscape = orderIdPreEscape.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
|
||||
path = path.replacingOccurrences(of: "{order_id}", with: orderIdPostEscape, options: .literal, range: nil)
|
||||
let URLString = PetstoreClientAPI.basePath + path
|
||||
let parameters: [String:Any]? = nil
|
||||
|
||||
let url = NSURLComponents(string: URLString)
|
||||
|
||||
let requestBuilder: RequestBuilder<Void>.Type = PetstoreClientAPI.requestBuilderFactory.getBuilder()
|
||||
|
||||
return requestBuilder.init(method: "DELETE", URLString: (url?.string ?? URLString), parameters: parameters, isBody: false)
|
||||
}
|
||||
|
||||
/**
|
||||
Returns pet inventories by status
|
||||
- parameter completion: completion handler to receive the data and the error objects
|
||||
*/
|
||||
open class func getInventory(completion: @escaping ((_ data: [String:Int32]?, _ error: ErrorResponse?) -> Void)) {
|
||||
getInventoryWithRequestBuilder().execute { (response, error) -> Void in
|
||||
completion(response?.body, error)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Returns pet inventories by status
|
||||
- GET /store/inventory
|
||||
- Returns a map of status codes to quantities
|
||||
- API Key:
|
||||
- type: apiKey api_key
|
||||
- name: api_key
|
||||
- examples: [{contentType=application/json, example={
|
||||
"key" : 0
|
||||
}}]
|
||||
- returns: RequestBuilder<[String:Int32]>
|
||||
*/
|
||||
open class func getInventoryWithRequestBuilder() -> RequestBuilder<[String:Int32]> {
|
||||
let path = "/store/inventory"
|
||||
let URLString = PetstoreClientAPI.basePath + path
|
||||
let parameters: [String:Any]? = nil
|
||||
|
||||
let url = NSURLComponents(string: URLString)
|
||||
|
||||
let requestBuilder: RequestBuilder<[String:Int32]>.Type = PetstoreClientAPI.requestBuilderFactory.getBuilder()
|
||||
|
||||
return requestBuilder.init(method: "GET", URLString: (url?.string ?? URLString), parameters: parameters, isBody: false)
|
||||
}
|
||||
|
||||
/**
|
||||
Find purchase order by ID
|
||||
- parameter orderId: (path) ID of pet that needs to be fetched
|
||||
- parameter completion: completion handler to receive the data and the error objects
|
||||
*/
|
||||
open class func getOrderById(orderId: Int64, completion: @escaping ((_ data: Order?, _ error: ErrorResponse?) -> Void)) {
|
||||
getOrderByIdWithRequestBuilder(orderId: orderId).execute { (response, error) -> Void in
|
||||
completion(response?.body, error)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Find purchase order by ID
|
||||
- GET /store/order/{order_id}
|
||||
- For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions
|
||||
|
||||
- examples: [{contentType=application/xml, example=<Order>
|
||||
<id>123456789</id>
|
||||
<petId>123456789</petId>
|
||||
<quantity>123</quantity>
|
||||
<shipDate>2000-01-23T04:56:07.000Z</shipDate>
|
||||
<status>aeiou</status>
|
||||
<complete>true</complete>
|
||||
</Order>}, {contentType=application/json, example={
|
||||
"petId" : 6,
|
||||
"quantity" : 1,
|
||||
"id" : 0,
|
||||
"shipDate" : "2000-01-23T04:56:07.000+00:00",
|
||||
"complete" : false,
|
||||
"status" : "placed"
|
||||
}}]
|
||||
- examples: [{contentType=application/xml, example=<Order>
|
||||
<id>123456789</id>
|
||||
<petId>123456789</petId>
|
||||
<quantity>123</quantity>
|
||||
<shipDate>2000-01-23T04:56:07.000Z</shipDate>
|
||||
<status>aeiou</status>
|
||||
<complete>true</complete>
|
||||
</Order>}, {contentType=application/json, example={
|
||||
"petId" : 6,
|
||||
"quantity" : 1,
|
||||
"id" : 0,
|
||||
"shipDate" : "2000-01-23T04:56:07.000+00:00",
|
||||
"complete" : false,
|
||||
"status" : "placed"
|
||||
}}]
|
||||
- parameter orderId: (path) ID of pet that needs to be fetched
|
||||
- returns: RequestBuilder<Order>
|
||||
*/
|
||||
open class func getOrderByIdWithRequestBuilder(orderId: Int64) -> RequestBuilder<Order> {
|
||||
var path = "/store/order/{order_id}"
|
||||
let orderIdPreEscape = "\(orderId)"
|
||||
let orderIdPostEscape = orderIdPreEscape.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
|
||||
path = path.replacingOccurrences(of: "{order_id}", with: orderIdPostEscape, options: .literal, range: nil)
|
||||
let URLString = PetstoreClientAPI.basePath + path
|
||||
let parameters: [String:Any]? = nil
|
||||
|
||||
let url = NSURLComponents(string: URLString)
|
||||
|
||||
let requestBuilder: RequestBuilder<Order>.Type = PetstoreClientAPI.requestBuilderFactory.getBuilder()
|
||||
|
||||
return requestBuilder.init(method: "GET", URLString: (url?.string ?? URLString), parameters: parameters, isBody: false)
|
||||
}
|
||||
|
||||
/**
|
||||
Place an order for a pet
|
||||
- parameter body: (body) order placed for purchasing the pet
|
||||
- parameter completion: completion handler to receive the data and the error objects
|
||||
*/
|
||||
open class func placeOrder(body: Order, completion: @escaping ((_ data: Order?, _ error: ErrorResponse?) -> Void)) {
|
||||
placeOrderWithRequestBuilder(body: body).execute { (response, error) -> Void in
|
||||
completion(response?.body, error)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Place an order for a pet
|
||||
- POST /store/order
|
||||
-
|
||||
|
||||
- examples: [{contentType=application/xml, example=<Order>
|
||||
<id>123456789</id>
|
||||
<petId>123456789</petId>
|
||||
<quantity>123</quantity>
|
||||
<shipDate>2000-01-23T04:56:07.000Z</shipDate>
|
||||
<status>aeiou</status>
|
||||
<complete>true</complete>
|
||||
</Order>}, {contentType=application/json, example={
|
||||
"petId" : 6,
|
||||
"quantity" : 1,
|
||||
"id" : 0,
|
||||
"shipDate" : "2000-01-23T04:56:07.000+00:00",
|
||||
"complete" : false,
|
||||
"status" : "placed"
|
||||
}}]
|
||||
- examples: [{contentType=application/xml, example=<Order>
|
||||
<id>123456789</id>
|
||||
<petId>123456789</petId>
|
||||
<quantity>123</quantity>
|
||||
<shipDate>2000-01-23T04:56:07.000Z</shipDate>
|
||||
<status>aeiou</status>
|
||||
<complete>true</complete>
|
||||
</Order>}, {contentType=application/json, example={
|
||||
"petId" : 6,
|
||||
"quantity" : 1,
|
||||
"id" : 0,
|
||||
"shipDate" : "2000-01-23T04:56:07.000+00:00",
|
||||
"complete" : false,
|
||||
"status" : "placed"
|
||||
}}]
|
||||
- parameter body: (body) order placed for purchasing the pet
|
||||
- returns: RequestBuilder<Order>
|
||||
*/
|
||||
open class func placeOrderWithRequestBuilder(body: Order) -> RequestBuilder<Order> {
|
||||
let path = "/store/order"
|
||||
let URLString = PetstoreClientAPI.basePath + path
|
||||
let parameters = body.encodeToJSON()
|
||||
|
||||
let url = NSURLComponents(string: URLString)
|
||||
|
||||
let requestBuilder: RequestBuilder<Order>.Type = PetstoreClientAPI.requestBuilderFactory.getBuilder()
|
||||
|
||||
return requestBuilder.init(method: "POST", URLString: (url?.string ?? URLString), parameters: parameters, isBody: true)
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,326 @@
|
||||
//
|
||||
// UserAPI.swift
|
||||
//
|
||||
// Generated by swagger-codegen
|
||||
// https://github.com/swagger-api/swagger-codegen
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import Alamofire
|
||||
|
||||
|
||||
open class UserAPI: APIBase {
|
||||
/**
|
||||
Create user
|
||||
- parameter body: (body) Created user object
|
||||
- parameter completion: completion handler to receive the data and the error objects
|
||||
*/
|
||||
open class func createUser(body: User, completion: @escaping ((_ error: ErrorResponse?) -> Void)) {
|
||||
createUserWithRequestBuilder(body: body).execute { (response, error) -> Void in
|
||||
completion(error)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Create user
|
||||
- POST /user
|
||||
- This can only be done by the logged in user.
|
||||
|
||||
- parameter body: (body) Created user object
|
||||
- returns: RequestBuilder<Void>
|
||||
*/
|
||||
open class func createUserWithRequestBuilder(body: User) -> RequestBuilder<Void> {
|
||||
let path = "/user"
|
||||
let URLString = PetstoreClientAPI.basePath + path
|
||||
let parameters = body.encodeToJSON()
|
||||
|
||||
let url = NSURLComponents(string: URLString)
|
||||
|
||||
let requestBuilder: RequestBuilder<Void>.Type = PetstoreClientAPI.requestBuilderFactory.getBuilder()
|
||||
|
||||
return requestBuilder.init(method: "POST", URLString: (url?.string ?? URLString), parameters: parameters, isBody: true)
|
||||
}
|
||||
|
||||
/**
|
||||
Creates list of users with given input array
|
||||
- parameter body: (body) List of user object
|
||||
- parameter completion: completion handler to receive the data and the error objects
|
||||
*/
|
||||
open class func createUsersWithArrayInput(body: [User], completion: @escaping ((_ error: ErrorResponse?) -> Void)) {
|
||||
createUsersWithArrayInputWithRequestBuilder(body: body).execute { (response, error) -> Void in
|
||||
completion(error)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Creates list of users with given input array
|
||||
- POST /user/createWithArray
|
||||
-
|
||||
|
||||
- parameter body: (body) List of user object
|
||||
- returns: RequestBuilder<Void>
|
||||
*/
|
||||
open class func createUsersWithArrayInputWithRequestBuilder(body: [User]) -> RequestBuilder<Void> {
|
||||
let path = "/user/createWithArray"
|
||||
let URLString = PetstoreClientAPI.basePath + path
|
||||
let parameters = body.encodeToJSON()
|
||||
|
||||
let url = NSURLComponents(string: URLString)
|
||||
|
||||
let requestBuilder: RequestBuilder<Void>.Type = PetstoreClientAPI.requestBuilderFactory.getBuilder()
|
||||
|
||||
return requestBuilder.init(method: "POST", URLString: (url?.string ?? URLString), parameters: parameters, isBody: true)
|
||||
}
|
||||
|
||||
/**
|
||||
Creates list of users with given input array
|
||||
- parameter body: (body) List of user object
|
||||
- parameter completion: completion handler to receive the data and the error objects
|
||||
*/
|
||||
open class func createUsersWithListInput(body: [User], completion: @escaping ((_ error: ErrorResponse?) -> Void)) {
|
||||
createUsersWithListInputWithRequestBuilder(body: body).execute { (response, error) -> Void in
|
||||
completion(error)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Creates list of users with given input array
|
||||
- POST /user/createWithList
|
||||
-
|
||||
|
||||
- parameter body: (body) List of user object
|
||||
- returns: RequestBuilder<Void>
|
||||
*/
|
||||
open class func createUsersWithListInputWithRequestBuilder(body: [User]) -> RequestBuilder<Void> {
|
||||
let path = "/user/createWithList"
|
||||
let URLString = PetstoreClientAPI.basePath + path
|
||||
let parameters = body.encodeToJSON()
|
||||
|
||||
let url = NSURLComponents(string: URLString)
|
||||
|
||||
let requestBuilder: RequestBuilder<Void>.Type = PetstoreClientAPI.requestBuilderFactory.getBuilder()
|
||||
|
||||
return requestBuilder.init(method: "POST", URLString: (url?.string ?? URLString), parameters: parameters, isBody: true)
|
||||
}
|
||||
|
||||
/**
|
||||
Delete user
|
||||
- parameter username: (path) The name that needs to be deleted
|
||||
- parameter completion: completion handler to receive the data and the error objects
|
||||
*/
|
||||
open class func deleteUser(username: String, completion: @escaping ((_ error: ErrorResponse?) -> Void)) {
|
||||
deleteUserWithRequestBuilder(username: username).execute { (response, error) -> Void in
|
||||
completion(error)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Delete user
|
||||
- DELETE /user/{username}
|
||||
- This can only be done by the logged in user.
|
||||
|
||||
- parameter username: (path) The name that needs to be deleted
|
||||
- returns: RequestBuilder<Void>
|
||||
*/
|
||||
open class func deleteUserWithRequestBuilder(username: String) -> RequestBuilder<Void> {
|
||||
var path = "/user/{username}"
|
||||
let usernamePreEscape = "\(username)"
|
||||
let usernamePostEscape = usernamePreEscape.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
|
||||
path = path.replacingOccurrences(of: "{username}", with: usernamePostEscape, options: .literal, range: nil)
|
||||
let URLString = PetstoreClientAPI.basePath + path
|
||||
let parameters: [String:Any]? = nil
|
||||
|
||||
let url = NSURLComponents(string: URLString)
|
||||
|
||||
let requestBuilder: RequestBuilder<Void>.Type = PetstoreClientAPI.requestBuilderFactory.getBuilder()
|
||||
|
||||
return requestBuilder.init(method: "DELETE", URLString: (url?.string ?? URLString), parameters: parameters, isBody: false)
|
||||
}
|
||||
|
||||
/**
|
||||
Get user by user name
|
||||
- parameter username: (path) The name that needs to be fetched. Use user1 for testing.
|
||||
- parameter completion: completion handler to receive the data and the error objects
|
||||
*/
|
||||
open class func getUserByName(username: String, completion: @escaping ((_ data: User?, _ error: ErrorResponse?) -> Void)) {
|
||||
getUserByNameWithRequestBuilder(username: username).execute { (response, error) -> Void in
|
||||
completion(response?.body, error)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Get user by user name
|
||||
- GET /user/{username}
|
||||
-
|
||||
|
||||
- examples: [{contentType=application/xml, example=<User>
|
||||
<id>123456789</id>
|
||||
<username>aeiou</username>
|
||||
<firstName>aeiou</firstName>
|
||||
<lastName>aeiou</lastName>
|
||||
<email>aeiou</email>
|
||||
<password>aeiou</password>
|
||||
<phone>aeiou</phone>
|
||||
<userStatus>123</userStatus>
|
||||
</User>}, {contentType=application/json, example={
|
||||
"firstName" : "firstName",
|
||||
"lastName" : "lastName",
|
||||
"password" : "password",
|
||||
"userStatus" : 6,
|
||||
"phone" : "phone",
|
||||
"id" : 0,
|
||||
"email" : "email",
|
||||
"username" : "username"
|
||||
}}]
|
||||
- examples: [{contentType=application/xml, example=<User>
|
||||
<id>123456789</id>
|
||||
<username>aeiou</username>
|
||||
<firstName>aeiou</firstName>
|
||||
<lastName>aeiou</lastName>
|
||||
<email>aeiou</email>
|
||||
<password>aeiou</password>
|
||||
<phone>aeiou</phone>
|
||||
<userStatus>123</userStatus>
|
||||
</User>}, {contentType=application/json, example={
|
||||
"firstName" : "firstName",
|
||||
"lastName" : "lastName",
|
||||
"password" : "password",
|
||||
"userStatus" : 6,
|
||||
"phone" : "phone",
|
||||
"id" : 0,
|
||||
"email" : "email",
|
||||
"username" : "username"
|
||||
}}]
|
||||
- parameter username: (path) The name that needs to be fetched. Use user1 for testing.
|
||||
- returns: RequestBuilder<User>
|
||||
*/
|
||||
open class func getUserByNameWithRequestBuilder(username: String) -> RequestBuilder<User> {
|
||||
var path = "/user/{username}"
|
||||
let usernamePreEscape = "\(username)"
|
||||
let usernamePostEscape = usernamePreEscape.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
|
||||
path = path.replacingOccurrences(of: "{username}", with: usernamePostEscape, options: .literal, range: nil)
|
||||
let URLString = PetstoreClientAPI.basePath + path
|
||||
let parameters: [String:Any]? = nil
|
||||
|
||||
let url = NSURLComponents(string: URLString)
|
||||
|
||||
let requestBuilder: RequestBuilder<User>.Type = PetstoreClientAPI.requestBuilderFactory.getBuilder()
|
||||
|
||||
return requestBuilder.init(method: "GET", URLString: (url?.string ?? URLString), parameters: parameters, isBody: false)
|
||||
}
|
||||
|
||||
/**
|
||||
Logs user into the system
|
||||
- parameter username: (query) The user name for login
|
||||
- parameter password: (query) The password for login in clear text
|
||||
- parameter completion: completion handler to receive the data and the error objects
|
||||
*/
|
||||
open class func loginUser(username: String, password: String, completion: @escaping ((_ data: String?, _ error: ErrorResponse?) -> Void)) {
|
||||
loginUserWithRequestBuilder(username: username, password: password).execute { (response, error) -> Void in
|
||||
completion(response?.body, error)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Logs user into the system
|
||||
- GET /user/login
|
||||
-
|
||||
|
||||
- responseHeaders: [X-Rate-Limit(Int32), X-Expires-After(Date)]
|
||||
- responseHeaders: [X-Rate-Limit(Int32), X-Expires-After(Date)]
|
||||
- examples: [{contentType=application/xml, example=aeiou}, {contentType=application/json, example=""}]
|
||||
- examples: [{contentType=application/xml, example=aeiou}, {contentType=application/json, example=""}]
|
||||
- parameter username: (query) The user name for login
|
||||
- parameter password: (query) The password for login in clear text
|
||||
- returns: RequestBuilder<String>
|
||||
*/
|
||||
open class func loginUserWithRequestBuilder(username: String, password: String) -> RequestBuilder<String> {
|
||||
let path = "/user/login"
|
||||
let URLString = PetstoreClientAPI.basePath + path
|
||||
let parameters: [String:Any]? = nil
|
||||
|
||||
let url = NSURLComponents(string: URLString)
|
||||
url?.queryItems = APIHelper.mapValuesToQueryItems(values:[
|
||||
"username": username,
|
||||
"password": password
|
||||
])
|
||||
|
||||
let requestBuilder: RequestBuilder<String>.Type = PetstoreClientAPI.requestBuilderFactory.getBuilder()
|
||||
|
||||
return requestBuilder.init(method: "GET", URLString: (url?.string ?? URLString), parameters: parameters, isBody: false)
|
||||
}
|
||||
|
||||
/**
|
||||
Logs out current logged in user session
|
||||
- parameter completion: completion handler to receive the data and the error objects
|
||||
*/
|
||||
open class func logoutUser(completion: @escaping ((_ error: ErrorResponse?) -> Void)) {
|
||||
logoutUserWithRequestBuilder().execute { (response, error) -> Void in
|
||||
completion(error)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Logs out current logged in user session
|
||||
- GET /user/logout
|
||||
-
|
||||
|
||||
- returns: RequestBuilder<Void>
|
||||
*/
|
||||
open class func logoutUserWithRequestBuilder() -> RequestBuilder<Void> {
|
||||
let path = "/user/logout"
|
||||
let URLString = PetstoreClientAPI.basePath + path
|
||||
let parameters: [String:Any]? = nil
|
||||
|
||||
let url = NSURLComponents(string: URLString)
|
||||
|
||||
let requestBuilder: RequestBuilder<Void>.Type = PetstoreClientAPI.requestBuilderFactory.getBuilder()
|
||||
|
||||
return requestBuilder.init(method: "GET", URLString: (url?.string ?? URLString), parameters: parameters, isBody: false)
|
||||
}
|
||||
|
||||
/**
|
||||
Updated user
|
||||
- parameter username: (path) name that need to be deleted
|
||||
- parameter body: (body) Updated user object
|
||||
- parameter completion: completion handler to receive the data and the error objects
|
||||
*/
|
||||
open class func updateUser(username: String, body: User, completion: @escaping ((_ error: ErrorResponse?) -> Void)) {
|
||||
updateUserWithRequestBuilder(username: username, body: body).execute { (response, error) -> Void in
|
||||
completion(error)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Updated user
|
||||
- PUT /user/{username}
|
||||
- This can only be done by the logged in user.
|
||||
|
||||
- parameter username: (path) name that need to be deleted
|
||||
- parameter body: (body) Updated user object
|
||||
- returns: RequestBuilder<Void>
|
||||
*/
|
||||
open class func updateUserWithRequestBuilder(username: String, body: User) -> RequestBuilder<Void> {
|
||||
var path = "/user/{username}"
|
||||
let usernamePreEscape = "\(username)"
|
||||
let usernamePostEscape = usernamePreEscape.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
|
||||
path = path.replacingOccurrences(of: "{username}", with: usernamePostEscape, options: .literal, range: nil)
|
||||
let URLString = PetstoreClientAPI.basePath + path
|
||||
let parameters = body.encodeToJSON()
|
||||
|
||||
let url = NSURLComponents(string: URLString)
|
||||
|
||||
let requestBuilder: RequestBuilder<Void>.Type = PetstoreClientAPI.requestBuilderFactory.getBuilder()
|
||||
|
||||
return requestBuilder.init(method: "PUT", URLString: (url?.string ?? URLString), parameters: parameters, isBody: true)
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,380 @@
|
||||
// AlamofireImplementations.swift
|
||||
//
|
||||
// Generated by swagger-codegen
|
||||
// https://github.com/swagger-api/swagger-codegen
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import Alamofire
|
||||
|
||||
class AlamofireRequestBuilderFactory: RequestBuilderFactory {
|
||||
func getBuilder<T>() -> RequestBuilder<T>.Type {
|
||||
return AlamofireRequestBuilder<T>.self
|
||||
}
|
||||
}
|
||||
|
||||
private struct SynchronizedDictionary<K: Hashable, V> {
|
||||
|
||||
private var dictionary = [K: V]()
|
||||
private let queue = DispatchQueue(
|
||||
label: "SynchronizedDictionary",
|
||||
qos: DispatchQoS.userInitiated,
|
||||
attributes: [DispatchQueue.Attributes.concurrent],
|
||||
autoreleaseFrequency: DispatchQueue.AutoreleaseFrequency.inherit,
|
||||
target: nil
|
||||
)
|
||||
|
||||
public subscript(key: K) -> V? {
|
||||
get {
|
||||
var value: V?
|
||||
|
||||
queue.sync {
|
||||
value = self.dictionary[key]
|
||||
}
|
||||
|
||||
return value
|
||||
}
|
||||
set {
|
||||
queue.sync(flags: DispatchWorkItemFlags.barrier) {
|
||||
self.dictionary[key] = newValue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class JSONEncodingWrapper: ParameterEncoding {
|
||||
var bodyParameters: Any?
|
||||
var encoding: JSONEncoding = JSONEncoding()
|
||||
|
||||
public init(parameters: Any?) {
|
||||
self.bodyParameters = parameters
|
||||
}
|
||||
|
||||
public func encode(_ urlRequest: URLRequestConvertible, with parameters: Parameters?) throws -> URLRequest {
|
||||
return try encoding.encode(urlRequest, withJSONObject: bodyParameters)
|
||||
}
|
||||
}
|
||||
|
||||
// Store manager to retain its reference
|
||||
private var managerStore = SynchronizedDictionary<String, Alamofire.SessionManager>()
|
||||
|
||||
open class AlamofireRequestBuilder<T>: RequestBuilder<T> {
|
||||
required public init(method: String, URLString: String, parameters: Any?, isBody: Bool, headers: [String : String] = [:]) {
|
||||
super.init(method: method, URLString: URLString, parameters: parameters, isBody: isBody, headers: headers)
|
||||
}
|
||||
|
||||
/**
|
||||
May be overridden by a subclass if you want to control the session
|
||||
configuration.
|
||||
*/
|
||||
open func createSessionManager() -> Alamofire.SessionManager {
|
||||
let configuration = URLSessionConfiguration.default
|
||||
configuration.httpAdditionalHeaders = buildHeaders()
|
||||
return Alamofire.SessionManager(configuration: configuration)
|
||||
}
|
||||
|
||||
/**
|
||||
May be overridden by a subclass if you want to control the Content-Type
|
||||
that is given to an uploaded form part.
|
||||
|
||||
Return nil to use the default behavior (inferring the Content-Type from
|
||||
the file extension). Return the desired Content-Type otherwise.
|
||||
*/
|
||||
open func contentTypeForFormPart(fileURL: URL) -> String? {
|
||||
return nil
|
||||
}
|
||||
|
||||
/**
|
||||
May be overridden by a subclass if you want to control the request
|
||||
configuration (e.g. to override the cache policy).
|
||||
*/
|
||||
open func makeRequest(manager: SessionManager, method: HTTPMethod, encoding: ParameterEncoding, headers: [String:String]) -> DataRequest {
|
||||
return manager.request(URLString, method: method, parameters: parameters as? Parameters, encoding: encoding, headers: headers)
|
||||
}
|
||||
|
||||
override open func execute(_ completion: @escaping (_ response: Response<T>?, _ error: ErrorResponse?) -> Void) {
|
||||
let managerId:String = UUID().uuidString
|
||||
// Create a new manager for each request to customize its request header
|
||||
let manager = createSessionManager()
|
||||
managerStore[managerId] = manager
|
||||
|
||||
let encoding:ParameterEncoding = isBody ? JSONEncodingWrapper(parameters: parameters) : URLEncoding()
|
||||
|
||||
let xMethod = Alamofire.HTTPMethod(rawValue: method)
|
||||
|
||||
let param = parameters as? Parameters
|
||||
let fileKeys = param == nil ? [] : param!.filter { $1 is NSURL }
|
||||
.map { $0.0 }
|
||||
|
||||
if fileKeys.count > 0 {
|
||||
manager.upload(multipartFormData: { mpForm in
|
||||
for (k, v) in param! {
|
||||
switch v {
|
||||
case let fileURL as URL:
|
||||
if let mimeType = self.contentTypeForFormPart(fileURL: fileURL) {
|
||||
mpForm.append(fileURL, withName: k, fileName: fileURL.lastPathComponent, mimeType: mimeType)
|
||||
}
|
||||
else {
|
||||
mpForm.append(fileURL, withName: k)
|
||||
}
|
||||
break
|
||||
case let string as String:
|
||||
mpForm.append(string.data(using: String.Encoding.utf8)!, withName: k)
|
||||
break
|
||||
case let number as NSNumber:
|
||||
mpForm.append(number.stringValue.data(using: String.Encoding.utf8)!, withName: k)
|
||||
break
|
||||
default:
|
||||
fatalError("Unprocessable value \(v) with key \(k)")
|
||||
break
|
||||
}
|
||||
}
|
||||
}, to: URLString, method: xMethod!, headers: nil, encodingCompletion: { encodingResult in
|
||||
switch encodingResult {
|
||||
case .success(let upload, _, _):
|
||||
if let onProgressReady = self.onProgressReady {
|
||||
onProgressReady(upload.uploadProgress)
|
||||
}
|
||||
self.processRequest(request: upload, managerId, completion)
|
||||
case .failure(let encodingError):
|
||||
completion(nil, ErrorResponse.HttpError(statusCode: 415, data: nil, error: encodingError))
|
||||
}
|
||||
})
|
||||
} else {
|
||||
let request = makeRequest(manager: manager, method: xMethod!, encoding: encoding, headers: headers)
|
||||
if let onProgressReady = self.onProgressReady {
|
||||
onProgressReady(request.progress)
|
||||
}
|
||||
processRequest(request: request, managerId, completion)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private func processRequest(request: DataRequest, _ managerId: String, _ completion: @escaping (_ response: Response<T>?, _ error: ErrorResponse?) -> Void) {
|
||||
if let credential = self.credential {
|
||||
request.authenticate(usingCredential: credential)
|
||||
}
|
||||
|
||||
let cleanupRequest = {
|
||||
managerStore[managerId] = nil
|
||||
}
|
||||
|
||||
let validatedRequest = request.validate()
|
||||
|
||||
switch T.self {
|
||||
case is String.Type:
|
||||
validatedRequest.responseString(completionHandler: { (stringResponse) in
|
||||
cleanupRequest()
|
||||
|
||||
if stringResponse.result.isFailure {
|
||||
completion(
|
||||
nil,
|
||||
ErrorResponse.HttpError(statusCode: stringResponse.response?.statusCode ?? 500, data: stringResponse.data, error: stringResponse.result.error as Error!)
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
completion(
|
||||
Response(
|
||||
response: stringResponse.response!,
|
||||
body: ((stringResponse.result.value ?? "") as! T)
|
||||
),
|
||||
nil
|
||||
)
|
||||
})
|
||||
case is Void.Type:
|
||||
validatedRequest.responseData(completionHandler: { (voidResponse) in
|
||||
cleanupRequest()
|
||||
|
||||
if voidResponse.result.isFailure {
|
||||
completion(
|
||||
nil,
|
||||
ErrorResponse.HttpError(statusCode: voidResponse.response?.statusCode ?? 500, data: voidResponse.data, error: voidResponse.result.error!)
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
completion(
|
||||
Response(
|
||||
response: voidResponse.response!,
|
||||
body: nil),
|
||||
nil
|
||||
)
|
||||
})
|
||||
case is Data.Type:
|
||||
validatedRequest.responseData(completionHandler: { (dataResponse) in
|
||||
cleanupRequest()
|
||||
|
||||
if (dataResponse.result.isFailure) {
|
||||
completion(
|
||||
nil,
|
||||
ErrorResponse.HttpError(statusCode: dataResponse.response?.statusCode ?? 500, data: dataResponse.data, error: dataResponse.result.error!)
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
completion(
|
||||
Response(
|
||||
response: dataResponse.response!,
|
||||
body: (dataResponse.data as! T)
|
||||
),
|
||||
nil
|
||||
)
|
||||
})
|
||||
case is URL.Type:
|
||||
validatedRequest.responseData(completionHandler: { (dataResponse) in
|
||||
cleanupRequest()
|
||||
|
||||
do {
|
||||
|
||||
guard !dataResponse.result.isFailure else {
|
||||
throw DownloadException.responseFailed
|
||||
}
|
||||
|
||||
guard let data = dataResponse.data else {
|
||||
throw DownloadException.responseDataMissing
|
||||
}
|
||||
|
||||
guard let request = request.request else {
|
||||
throw DownloadException.requestMissing
|
||||
}
|
||||
|
||||
let fileManager = FileManager.default
|
||||
let urlRequest = try request.asURLRequest()
|
||||
let documentsDirectory = fileManager.urls(for: .documentDirectory, in: .userDomainMask)[0]
|
||||
let requestURL = try self.getURL(from: urlRequest)
|
||||
|
||||
var requestPath = try self.getPath(from: requestURL)
|
||||
|
||||
if let headerFileName = self.getFileName(fromContentDisposition: dataResponse.response?.allHeaderFields["Content-Disposition"] as? String) {
|
||||
requestPath = requestPath.appending("/\(headerFileName)")
|
||||
}
|
||||
|
||||
let filePath = documentsDirectory.appendingPathComponent(requestPath)
|
||||
let directoryPath = filePath.deletingLastPathComponent().path
|
||||
|
||||
try fileManager.createDirectory(atPath: directoryPath, withIntermediateDirectories: true, attributes: nil)
|
||||
try data.write(to: filePath, options: .atomic)
|
||||
|
||||
completion(
|
||||
Response(
|
||||
response: dataResponse.response!,
|
||||
body: (filePath as! T)
|
||||
),
|
||||
nil
|
||||
)
|
||||
|
||||
} catch let requestParserError as DownloadException {
|
||||
completion(nil, ErrorResponse.HttpError(statusCode: 400, data: dataResponse.data, error: requestParserError))
|
||||
} catch let error {
|
||||
completion(nil, ErrorResponse.HttpError(statusCode: 400, data: dataResponse.data, error: error))
|
||||
}
|
||||
return
|
||||
})
|
||||
default:
|
||||
validatedRequest.responseJSON(options: .allowFragments) { response in
|
||||
cleanupRequest()
|
||||
|
||||
if response.result.isFailure {
|
||||
completion(nil, ErrorResponse.HttpError(statusCode: response.response?.statusCode ?? 500, data: response.data, error: response.result.error!))
|
||||
return
|
||||
}
|
||||
|
||||
// handle HTTP 204 No Content
|
||||
// NSNull would crash decoders
|
||||
if response.response?.statusCode == 204 && response.result.value is NSNull{
|
||||
completion(nil, nil)
|
||||
return
|
||||
}
|
||||
|
||||
if () is T {
|
||||
completion(Response(response: response.response!, body: (() as! T)), nil)
|
||||
return
|
||||
}
|
||||
if let json: Any = response.result.value {
|
||||
let decoded = Decoders.decode(clazz: T.self, source: json as AnyObject, instance: nil)
|
||||
switch decoded {
|
||||
case let .success(object): completion(Response(response: response.response!, body: object), nil)
|
||||
case let .failure(error): completion(nil, ErrorResponse.DecodeError(response: response.data, decodeError: error))
|
||||
}
|
||||
return
|
||||
} else if "" is T {
|
||||
// swagger-parser currently doesn't support void, which will be fixed in future swagger-parser release
|
||||
// https://github.com/swagger-api/swagger-parser/pull/34
|
||||
completion(Response(response: response.response!, body: ("" as! T)), nil)
|
||||
return
|
||||
}
|
||||
|
||||
completion(nil, ErrorResponse.HttpError(statusCode: 500, data: nil, error: NSError(domain: "localhost", code: 500, userInfo: ["reason": "unreacheable code"])))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
open func buildHeaders() -> [String: String] {
|
||||
var httpHeaders = SessionManager.defaultHTTPHeaders
|
||||
for (key, value) in self.headers {
|
||||
httpHeaders[key] = value
|
||||
}
|
||||
return httpHeaders
|
||||
}
|
||||
|
||||
fileprivate func getFileName(fromContentDisposition contentDisposition : String?) -> String? {
|
||||
|
||||
guard let contentDisposition = contentDisposition else {
|
||||
return nil
|
||||
}
|
||||
|
||||
let items = contentDisposition.components(separatedBy: ";")
|
||||
|
||||
var filename : String? = nil
|
||||
|
||||
for contentItem in items {
|
||||
|
||||
let filenameKey = "filename="
|
||||
guard let range = contentItem.range(of: filenameKey) else {
|
||||
break
|
||||
}
|
||||
|
||||
filename = contentItem
|
||||
return filename?
|
||||
.replacingCharacters(in: range, with:"")
|
||||
.replacingOccurrences(of: "\"", with: "")
|
||||
.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
}
|
||||
|
||||
return filename
|
||||
|
||||
}
|
||||
|
||||
fileprivate func getPath(from url : URL) throws -> String {
|
||||
|
||||
guard var path = NSURLComponents(url: url, resolvingAgainstBaseURL: true)?.path else {
|
||||
throw DownloadException.requestMissingPath
|
||||
}
|
||||
|
||||
if path.hasPrefix("/") {
|
||||
path.remove(at: path.startIndex)
|
||||
}
|
||||
|
||||
return path
|
||||
|
||||
}
|
||||
|
||||
fileprivate func getURL(from urlRequest : URLRequest) throws -> URL {
|
||||
|
||||
guard let url = urlRequest.url else {
|
||||
throw DownloadException.requestMissingURL
|
||||
}
|
||||
|
||||
return url
|
||||
}
|
||||
}
|
||||
|
||||
fileprivate enum DownloadException : Error {
|
||||
case responseDataMissing
|
||||
case responseFailed
|
||||
case requestMissing
|
||||
case requestMissingPath
|
||||
case requestMissingURL
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
// Configuration.swift
|
||||
//
|
||||
// Generated by swagger-codegen
|
||||
// https://github.com/swagger-api/swagger-codegen
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
open class Configuration {
|
||||
|
||||
// This value is used to configure the date formatter that is used to serialize dates into JSON format.
|
||||
// You must set it prior to encoding any dates, and it will only be read once.
|
||||
open static var dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ"
|
||||
|
||||
}
|
@ -0,0 +1,187 @@
|
||||
// Extensions.swift
|
||||
//
|
||||
// Generated by swagger-codegen
|
||||
// https://github.com/swagger-api/swagger-codegen
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import Alamofire
|
||||
|
||||
extension Bool: JSONEncodable {
|
||||
func encodeToJSON() -> Any { return self as Any }
|
||||
}
|
||||
|
||||
extension Float: JSONEncodable {
|
||||
func encodeToJSON() -> Any { return self as Any }
|
||||
}
|
||||
|
||||
extension Int: JSONEncodable {
|
||||
func encodeToJSON() -> Any { return self as Any }
|
||||
}
|
||||
|
||||
extension Int32: JSONEncodable {
|
||||
func encodeToJSON() -> Any { return NSNumber(value: self as Int32) }
|
||||
}
|
||||
|
||||
extension Int64: JSONEncodable {
|
||||
func encodeToJSON() -> Any { return NSNumber(value: self as Int64) }
|
||||
}
|
||||
|
||||
extension Double: JSONEncodable {
|
||||
func encodeToJSON() -> Any { return self as Any }
|
||||
}
|
||||
|
||||
extension String: JSONEncodable {
|
||||
func encodeToJSON() -> Any { return self as Any }
|
||||
}
|
||||
|
||||
private func encodeIfPossible<T>(_ object: T) -> Any {
|
||||
if let encodableObject = object as? JSONEncodable {
|
||||
return encodableObject.encodeToJSON()
|
||||
} else {
|
||||
return object as Any
|
||||
}
|
||||
}
|
||||
|
||||
extension Array: JSONEncodable {
|
||||
func encodeToJSON() -> Any {
|
||||
return self.map(encodeIfPossible)
|
||||
}
|
||||
}
|
||||
|
||||
extension Dictionary: JSONEncodable {
|
||||
func encodeToJSON() -> Any {
|
||||
var dictionary = [AnyHashable: Any]()
|
||||
for (key, value) in self {
|
||||
dictionary[key as! NSObject] = encodeIfPossible(value)
|
||||
}
|
||||
return dictionary as Any
|
||||
}
|
||||
}
|
||||
|
||||
extension Data: JSONEncodable {
|
||||
func encodeToJSON() -> Any {
|
||||
return self.base64EncodedString(options: Data.Base64EncodingOptions())
|
||||
}
|
||||
}
|
||||
|
||||
private let dateFormatter: DateFormatter = {
|
||||
let fmt = DateFormatter()
|
||||
fmt.dateFormat = Configuration.dateFormat
|
||||
fmt.locale = Locale(identifier: "en_US_POSIX")
|
||||
return fmt
|
||||
}()
|
||||
|
||||
extension Date: JSONEncodable {
|
||||
func encodeToJSON() -> Any {
|
||||
return dateFormatter.string(from: self) as Any
|
||||
}
|
||||
}
|
||||
|
||||
extension UUID: JSONEncodable {
|
||||
func encodeToJSON() -> Any {
|
||||
return self.uuidString
|
||||
}
|
||||
}
|
||||
|
||||
/// Represents an ISO-8601 full-date (RFC-3339).
|
||||
/// ex: 12-31-1999
|
||||
/// https://xml2rfc.tools.ietf.org/public/rfc/html/rfc3339.html#anchor14
|
||||
public final class ISOFullDate: CustomStringConvertible {
|
||||
|
||||
public let year: Int
|
||||
public let month: Int
|
||||
public let day: Int
|
||||
|
||||
public init(year: Int, month: Int, day: Int) {
|
||||
self.year = year
|
||||
self.month = month
|
||||
self.day = day
|
||||
}
|
||||
|
||||
/**
|
||||
Converts a Date to an ISOFullDate. Only interested in the year, month, day components.
|
||||
|
||||
- parameter date: The date to convert.
|
||||
|
||||
- returns: An ISOFullDate constructed from the year, month, day of the date.
|
||||
*/
|
||||
public static func from(date: Date) -> ISOFullDate? {
|
||||
let calendar = Calendar(identifier: .gregorian)
|
||||
|
||||
let components = calendar.dateComponents(
|
||||
[
|
||||
.year,
|
||||
.month,
|
||||
.day,
|
||||
],
|
||||
from: date
|
||||
)
|
||||
|
||||
guard
|
||||
let year = components.year,
|
||||
let month = components.month,
|
||||
let day = components.day
|
||||
else {
|
||||
return nil
|
||||
}
|
||||
|
||||
return ISOFullDate(
|
||||
year: year,
|
||||
month: month,
|
||||
day: day
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
Converts a ISO-8601 full-date string to an ISOFullDate.
|
||||
|
||||
- parameter string: The ISO-8601 full-date format string to convert.
|
||||
|
||||
- returns: An ISOFullDate constructed from the string.
|
||||
*/
|
||||
public static func from(string: String) -> ISOFullDate? {
|
||||
let components = string
|
||||
.characters
|
||||
.split(separator: "-")
|
||||
.map(String.init)
|
||||
.flatMap { Int($0) }
|
||||
guard components.count == 3 else { return nil }
|
||||
|
||||
return ISOFullDate(
|
||||
year: components[0],
|
||||
month: components[1],
|
||||
day: components[2]
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
Converts the receiver to a Date, in the default time zone.
|
||||
|
||||
- returns: A Date from the components of the receiver, in the default time zone.
|
||||
*/
|
||||
public func toDate() -> Date? {
|
||||
var components = DateComponents()
|
||||
components.year = year
|
||||
components.month = month
|
||||
components.day = day
|
||||
components.timeZone = TimeZone.ReferenceType.default
|
||||
let calendar = Calendar(identifier: .gregorian)
|
||||
return calendar.date(from: components)
|
||||
}
|
||||
|
||||
// MARK: CustomStringConvertible
|
||||
|
||||
public var description: String {
|
||||
return "\(year)-\(month)-\(day)"
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extension ISOFullDate: JSONEncodable {
|
||||
public func encodeToJSON() -> Any {
|
||||
return "\(year)-\(month)-\(day)"
|
||||
}
|
||||
}
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,28 @@
|
||||
//
|
||||
// AdditionalPropertiesClass.swift
|
||||
//
|
||||
// Generated by swagger-codegen
|
||||
// https://github.com/swagger-api/swagger-codegen
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
|
||||
open class AdditionalPropertiesClass: JSONEncodable {
|
||||
|
||||
public var mapProperty: [String:String]?
|
||||
public var mapOfMapProperty: [String:[String:String]]?
|
||||
|
||||
public init() {}
|
||||
|
||||
// MARK: JSONEncodable
|
||||
open func encodeToJSON() -> Any {
|
||||
var nillableDictionary = [String:Any?]()
|
||||
nillableDictionary["map_property"] = self.mapProperty?.encodeToJSON()
|
||||
nillableDictionary["map_of_map_property"] = self.mapOfMapProperty?.encodeToJSON()
|
||||
|
||||
let dictionary: [String:Any] = APIHelper.rejectNil(nillableDictionary) ?? [:]
|
||||
return dictionary
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,28 @@
|
||||
//
|
||||
// Animal.swift
|
||||
//
|
||||
// Generated by swagger-codegen
|
||||
// https://github.com/swagger-api/swagger-codegen
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
|
||||
open class Animal: JSONEncodable {
|
||||
|
||||
public var className: String?
|
||||
public var color: String?
|
||||
|
||||
public init() {}
|
||||
|
||||
// MARK: JSONEncodable
|
||||
open func encodeToJSON() -> Any {
|
||||
var nillableDictionary = [String:Any?]()
|
||||
nillableDictionary["className"] = self.className
|
||||
nillableDictionary["color"] = self.color
|
||||
|
||||
let dictionary: [String:Any] = APIHelper.rejectNil(nillableDictionary) ?? [:]
|
||||
return dictionary
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,11 @@
|
||||
//
|
||||
// AnimalFarm.swift
|
||||
//
|
||||
// Generated by swagger-codegen
|
||||
// https://github.com/swagger-api/swagger-codegen
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
|
||||
public typealias AnimalFarm = [Animal]
|
@ -0,0 +1,35 @@
|
||||
//
|
||||
// ApiResponse.swift
|
||||
//
|
||||
// Generated by swagger-codegen
|
||||
// https://github.com/swagger-api/swagger-codegen
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
|
||||
open class ApiResponse: JSONEncodable {
|
||||
|
||||
public var code: Int32?
|
||||
public var codeNum: NSNumber? {
|
||||
get {
|
||||
return code.map({ return NSNumber(value: $0) })
|
||||
}
|
||||
}
|
||||
public var type: String?
|
||||
public var message: String?
|
||||
|
||||
public init() {}
|
||||
|
||||
// MARK: JSONEncodable
|
||||
open func encodeToJSON() -> Any {
|
||||
var nillableDictionary = [String:Any?]()
|
||||
nillableDictionary["code"] = self.code?.encodeToJSON()
|
||||
nillableDictionary["type"] = self.type
|
||||
nillableDictionary["message"] = self.message
|
||||
|
||||
let dictionary: [String:Any] = APIHelper.rejectNil(nillableDictionary) ?? [:]
|
||||
return dictionary
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,26 @@
|
||||
//
|
||||
// ArrayOfArrayOfNumberOnly.swift
|
||||
//
|
||||
// Generated by swagger-codegen
|
||||
// https://github.com/swagger-api/swagger-codegen
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
|
||||
open class ArrayOfArrayOfNumberOnly: JSONEncodable {
|
||||
|
||||
public var arrayArrayNumber: [[Double]]?
|
||||
|
||||
public init() {}
|
||||
|
||||
// MARK: JSONEncodable
|
||||
open func encodeToJSON() -> Any {
|
||||
var nillableDictionary = [String:Any?]()
|
||||
nillableDictionary["ArrayArrayNumber"] = self.arrayArrayNumber?.encodeToJSON()
|
||||
|
||||
let dictionary: [String:Any] = APIHelper.rejectNil(nillableDictionary) ?? [:]
|
||||
return dictionary
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,26 @@
|
||||
//
|
||||
// ArrayOfNumberOnly.swift
|
||||
//
|
||||
// Generated by swagger-codegen
|
||||
// https://github.com/swagger-api/swagger-codegen
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
|
||||
open class ArrayOfNumberOnly: JSONEncodable {
|
||||
|
||||
public var arrayNumber: [Double]?
|
||||
|
||||
public init() {}
|
||||
|
||||
// MARK: JSONEncodable
|
||||
open func encodeToJSON() -> Any {
|
||||
var nillableDictionary = [String:Any?]()
|
||||
nillableDictionary["ArrayNumber"] = self.arrayNumber?.encodeToJSON()
|
||||
|
||||
let dictionary: [String:Any] = APIHelper.rejectNil(nillableDictionary) ?? [:]
|
||||
return dictionary
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,30 @@
|
||||
//
|
||||
// ArrayTest.swift
|
||||
//
|
||||
// Generated by swagger-codegen
|
||||
// https://github.com/swagger-api/swagger-codegen
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
|
||||
open class ArrayTest: JSONEncodable {
|
||||
|
||||
public var arrayOfString: [String]?
|
||||
public var arrayArrayOfInteger: [[Int64]]?
|
||||
public var arrayArrayOfModel: [[ReadOnlyFirst]]?
|
||||
|
||||
public init() {}
|
||||
|
||||
// MARK: JSONEncodable
|
||||
open func encodeToJSON() -> Any {
|
||||
var nillableDictionary = [String:Any?]()
|
||||
nillableDictionary["array_of_string"] = self.arrayOfString?.encodeToJSON()
|
||||
nillableDictionary["array_array_of_integer"] = self.arrayArrayOfInteger?.encodeToJSON()
|
||||
nillableDictionary["array_array_of_model"] = self.arrayArrayOfModel?.encodeToJSON()
|
||||
|
||||
let dictionary: [String:Any] = APIHelper.rejectNil(nillableDictionary) ?? [:]
|
||||
return dictionary
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,37 @@
|
||||
//
|
||||
// Capitalization.swift
|
||||
//
|
||||
// Generated by swagger-codegen
|
||||
// https://github.com/swagger-api/swagger-codegen
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
|
||||
open class Capitalization: JSONEncodable {
|
||||
|
||||
public var smallCamel: String?
|
||||
public var capitalCamel: String?
|
||||
public var smallSnake: String?
|
||||
public var capitalSnake: String?
|
||||
public var sCAETHFlowPoints: String?
|
||||
/** Name of the pet */
|
||||
public var ATT_NAME: String?
|
||||
|
||||
public init() {}
|
||||
|
||||
// MARK: JSONEncodable
|
||||
open func encodeToJSON() -> Any {
|
||||
var nillableDictionary = [String:Any?]()
|
||||
nillableDictionary["smallCamel"] = self.smallCamel
|
||||
nillableDictionary["CapitalCamel"] = self.capitalCamel
|
||||
nillableDictionary["small_Snake"] = self.smallSnake
|
||||
nillableDictionary["Capital_Snake"] = self.capitalSnake
|
||||
nillableDictionary["SCA_ETH_Flow_Points"] = self.sCAETHFlowPoints
|
||||
nillableDictionary["ATT_NAME"] = self.ATT_NAME
|
||||
|
||||
let dictionary: [String:Any] = APIHelper.rejectNil(nillableDictionary) ?? [:]
|
||||
return dictionary
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,31 @@
|
||||
//
|
||||
// Cat.swift
|
||||
//
|
||||
// Generated by swagger-codegen
|
||||
// https://github.com/swagger-api/swagger-codegen
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
|
||||
open class Cat: Animal {
|
||||
|
||||
public var declawed: Bool?
|
||||
public var declawedNum: NSNumber? {
|
||||
get {
|
||||
return declawed.map({ return NSNumber(value: $0) })
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// MARK: JSONEncodable
|
||||
override open func encodeToJSON() -> Any {
|
||||
var nillableDictionary = super.encodeToJSON() as? [String:Any?] ?? [String:Any?]()
|
||||
nillableDictionary["declawed"] = self.declawed
|
||||
|
||||
let dictionary: [String:Any] = APIHelper.rejectNil(nillableDictionary) ?? [:]
|
||||
return dictionary
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,33 @@
|
||||
//
|
||||
// Category.swift
|
||||
//
|
||||
// Generated by swagger-codegen
|
||||
// https://github.com/swagger-api/swagger-codegen
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
|
||||
open class Category: JSONEncodable {
|
||||
|
||||
public var id: Int64?
|
||||
public var idNum: NSNumber? {
|
||||
get {
|
||||
return id.map({ return NSNumber(value: $0) })
|
||||
}
|
||||
}
|
||||
public var name: String?
|
||||
|
||||
public init() {}
|
||||
|
||||
// MARK: JSONEncodable
|
||||
open func encodeToJSON() -> Any {
|
||||
var nillableDictionary = [String:Any?]()
|
||||
nillableDictionary["id"] = self.id?.encodeToJSON()
|
||||
nillableDictionary["name"] = self.name
|
||||
|
||||
let dictionary: [String:Any] = APIHelper.rejectNil(nillableDictionary) ?? [:]
|
||||
return dictionary
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,27 @@
|
||||
//
|
||||
// ClassModel.swift
|
||||
//
|
||||
// Generated by swagger-codegen
|
||||
// https://github.com/swagger-api/swagger-codegen
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
|
||||
/** Model for testing model with \"_class\" property */
|
||||
open class ClassModel: JSONEncodable {
|
||||
|
||||
public var _class: String?
|
||||
|
||||
public init() {}
|
||||
|
||||
// MARK: JSONEncodable
|
||||
open func encodeToJSON() -> Any {
|
||||
var nillableDictionary = [String:Any?]()
|
||||
nillableDictionary["_class"] = self._class
|
||||
|
||||
let dictionary: [String:Any] = APIHelper.rejectNil(nillableDictionary) ?? [:]
|
||||
return dictionary
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,26 @@
|
||||
//
|
||||
// Client.swift
|
||||
//
|
||||
// Generated by swagger-codegen
|
||||
// https://github.com/swagger-api/swagger-codegen
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
|
||||
open class Client: JSONEncodable {
|
||||
|
||||
public var client: String?
|
||||
|
||||
public init() {}
|
||||
|
||||
// MARK: JSONEncodable
|
||||
open func encodeToJSON() -> Any {
|
||||
var nillableDictionary = [String:Any?]()
|
||||
nillableDictionary["client"] = self.client
|
||||
|
||||
let dictionary: [String:Any] = APIHelper.rejectNil(nillableDictionary) ?? [:]
|
||||
return dictionary
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,26 @@
|
||||
//
|
||||
// Dog.swift
|
||||
//
|
||||
// Generated by swagger-codegen
|
||||
// https://github.com/swagger-api/swagger-codegen
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
|
||||
open class Dog: Animal {
|
||||
|
||||
public var breed: String?
|
||||
|
||||
|
||||
|
||||
// MARK: JSONEncodable
|
||||
override open func encodeToJSON() -> Any {
|
||||
var nillableDictionary = super.encodeToJSON() as? [String:Any?] ?? [String:Any?]()
|
||||
nillableDictionary["breed"] = self.breed
|
||||
|
||||
let dictionary: [String:Any] = APIHelper.rejectNil(nillableDictionary) ?? [:]
|
||||
return dictionary
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,36 @@
|
||||
//
|
||||
// EnumArrays.swift
|
||||
//
|
||||
// Generated by swagger-codegen
|
||||
// https://github.com/swagger-api/swagger-codegen
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
|
||||
open class EnumArrays: JSONEncodable {
|
||||
|
||||
public enum JustSymbol: String {
|
||||
case greaterThanOrEqualTo = ">="
|
||||
case dollar = "$"
|
||||
}
|
||||
public enum ArrayEnum: String {
|
||||
case fish = "fish"
|
||||
case crab = "crab"
|
||||
}
|
||||
public var justSymbol: JustSymbol?
|
||||
public var arrayEnum: [ArrayEnum]?
|
||||
|
||||
public init() {}
|
||||
|
||||
// MARK: JSONEncodable
|
||||
open func encodeToJSON() -> Any {
|
||||
var nillableDictionary = [String:Any?]()
|
||||
nillableDictionary["just_symbol"] = self.justSymbol?.rawValue
|
||||
nillableDictionary["array_enum"] = self.arrayEnum?.map({$0.rawValue}).encodeToJSON()
|
||||
|
||||
let dictionary: [String:Any] = APIHelper.rejectNil(nillableDictionary) ?? [:]
|
||||
return dictionary
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,17 @@
|
||||
//
|
||||
// EnumClass.swift
|
||||
//
|
||||
// Generated by swagger-codegen
|
||||
// https://github.com/swagger-api/swagger-codegen
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
|
||||
public enum EnumClass: String {
|
||||
case abc = "_abc"
|
||||
case efg = "-efg"
|
||||
case xyz = "(xyz)"
|
||||
|
||||
func encodeToJSON() -> Any { return self.rawValue }
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
//
|
||||
// EnumTest.swift
|
||||
//
|
||||
// Generated by swagger-codegen
|
||||
// https://github.com/swagger-api/swagger-codegen
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
|
||||
open class EnumTest: JSONEncodable {
|
||||
|
||||
public enum EnumString: String {
|
||||
case upper = "UPPER"
|
||||
case lower = "lower"
|
||||
case empty = ""
|
||||
}
|
||||
public enum EnumInteger: Int32 {
|
||||
case _1 = 1
|
||||
case number1 = -1
|
||||
}
|
||||
public enum EnumNumber: Double {
|
||||
case _11 = 1.1
|
||||
case number12 = -1.2
|
||||
}
|
||||
public var enumString: EnumString?
|
||||
public var enumInteger: EnumInteger?
|
||||
public var enumNumber: EnumNumber?
|
||||
public var outerEnum: OuterEnum?
|
||||
|
||||
public init() {}
|
||||
|
||||
// MARK: JSONEncodable
|
||||
open func encodeToJSON() -> Any {
|
||||
var nillableDictionary = [String:Any?]()
|
||||
nillableDictionary["enum_string"] = self.enumString?.rawValue
|
||||
nillableDictionary["enum_integer"] = self.enumInteger?.rawValue
|
||||
nillableDictionary["enum_number"] = self.enumNumber?.rawValue
|
||||
nillableDictionary["outerEnum"] = self.outerEnum?.encodeToJSON()
|
||||
|
||||
let dictionary: [String:Any] = APIHelper.rejectNil(nillableDictionary) ?? [:]
|
||||
return dictionary
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,80 @@
|
||||
//
|
||||
// FormatTest.swift
|
||||
//
|
||||
// Generated by swagger-codegen
|
||||
// https://github.com/swagger-api/swagger-codegen
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
|
||||
open class FormatTest: JSONEncodable {
|
||||
|
||||
public var integer: Int32?
|
||||
public var integerNum: NSNumber? {
|
||||
get {
|
||||
return integer.map({ return NSNumber(value: $0) })
|
||||
}
|
||||
}
|
||||
public var int32: Int32?
|
||||
public var int32Num: NSNumber? {
|
||||
get {
|
||||
return int32.map({ return NSNumber(value: $0) })
|
||||
}
|
||||
}
|
||||
public var int64: Int64?
|
||||
public var int64Num: NSNumber? {
|
||||
get {
|
||||
return int64.map({ return NSNumber(value: $0) })
|
||||
}
|
||||
}
|
||||
public var number: Double?
|
||||
public var numberNum: NSNumber? {
|
||||
get {
|
||||
return number.map({ return NSNumber(value: $0) })
|
||||
}
|
||||
}
|
||||
public var float: Float?
|
||||
public var floatNum: NSNumber? {
|
||||
get {
|
||||
return float.map({ return NSNumber(value: $0) })
|
||||
}
|
||||
}
|
||||
public var double: Double?
|
||||
public var doubleNum: NSNumber? {
|
||||
get {
|
||||
return double.map({ return NSNumber(value: $0) })
|
||||
}
|
||||
}
|
||||
public var string: String?
|
||||
public var byte: Data?
|
||||
public var binary: Data?
|
||||
public var date: ISOFullDate?
|
||||
public var dateTime: Date?
|
||||
public var uuid: UUID?
|
||||
public var password: String?
|
||||
|
||||
public init() {}
|
||||
|
||||
// MARK: JSONEncodable
|
||||
open func encodeToJSON() -> Any {
|
||||
var nillableDictionary = [String:Any?]()
|
||||
nillableDictionary["integer"] = self.integer?.encodeToJSON()
|
||||
nillableDictionary["int32"] = self.int32?.encodeToJSON()
|
||||
nillableDictionary["int64"] = self.int64?.encodeToJSON()
|
||||
nillableDictionary["number"] = self.number
|
||||
nillableDictionary["float"] = self.float
|
||||
nillableDictionary["double"] = self.double
|
||||
nillableDictionary["string"] = self.string
|
||||
nillableDictionary["byte"] = self.byte?.encodeToJSON()
|
||||
nillableDictionary["binary"] = self.binary?.encodeToJSON()
|
||||
nillableDictionary["date"] = self.date?.encodeToJSON()
|
||||
nillableDictionary["dateTime"] = self.dateTime?.encodeToJSON()
|
||||
nillableDictionary["uuid"] = self.uuid?.encodeToJSON()
|
||||
nillableDictionary["password"] = self.password
|
||||
|
||||
let dictionary: [String:Any] = APIHelper.rejectNil(nillableDictionary) ?? [:]
|
||||
return dictionary
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,28 @@
|
||||
//
|
||||
// HasOnlyReadOnly.swift
|
||||
//
|
||||
// Generated by swagger-codegen
|
||||
// https://github.com/swagger-api/swagger-codegen
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
|
||||
open class HasOnlyReadOnly: JSONEncodable {
|
||||
|
||||
public var bar: String?
|
||||
public var foo: String?
|
||||
|
||||
public init() {}
|
||||
|
||||
// MARK: JSONEncodable
|
||||
open func encodeToJSON() -> Any {
|
||||
var nillableDictionary = [String:Any?]()
|
||||
nillableDictionary["bar"] = self.bar
|
||||
nillableDictionary["foo"] = self.foo
|
||||
|
||||
let dictionary: [String:Any] = APIHelper.rejectNil(nillableDictionary) ?? [:]
|
||||
return dictionary
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,26 @@
|
||||
//
|
||||
// List.swift
|
||||
//
|
||||
// Generated by swagger-codegen
|
||||
// https://github.com/swagger-api/swagger-codegen
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
|
||||
open class List: JSONEncodable {
|
||||
|
||||
public var _123List: String?
|
||||
|
||||
public init() {}
|
||||
|
||||
// MARK: JSONEncodable
|
||||
open func encodeToJSON() -> Any {
|
||||
var nillableDictionary = [String:Any?]()
|
||||
nillableDictionary["123-list"] = self._123List
|
||||
|
||||
let dictionary: [String:Any] = APIHelper.rejectNil(nillableDictionary) ?? [:]
|
||||
return dictionary
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,31 @@
|
||||
//
|
||||
// MapTest.swift
|
||||
//
|
||||
// Generated by swagger-codegen
|
||||
// https://github.com/swagger-api/swagger-codegen
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
|
||||
open class MapTest: JSONEncodable {
|
||||
|
||||
public enum MapOfEnumString: String {
|
||||
case upper = "UPPER"
|
||||
case lower = "lower"
|
||||
}
|
||||
public var mapMapOfString: [String:[String:String]]?
|
||||
public var mapOfEnumString: [String:String]?
|
||||
|
||||
public init() {}
|
||||
|
||||
// MARK: JSONEncodable
|
||||
open func encodeToJSON() -> Any {
|
||||
var nillableDictionary = [String:Any?]()
|
||||
nillableDictionary["map_map_of_string"] = self.mapMapOfString?.encodeToJSON()//TODO: handle enum map scenario
|
||||
|
||||
let dictionary: [String:Any] = APIHelper.rejectNil(nillableDictionary) ?? [:]
|
||||
return dictionary
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,30 @@
|
||||
//
|
||||
// MixedPropertiesAndAdditionalPropertiesClass.swift
|
||||
//
|
||||
// Generated by swagger-codegen
|
||||
// https://github.com/swagger-api/swagger-codegen
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
|
||||
open class MixedPropertiesAndAdditionalPropertiesClass: JSONEncodable {
|
||||
|
||||
public var uuid: UUID?
|
||||
public var dateTime: Date?
|
||||
public var map: [String:Animal]?
|
||||
|
||||
public init() {}
|
||||
|
||||
// MARK: JSONEncodable
|
||||
open func encodeToJSON() -> Any {
|
||||
var nillableDictionary = [String:Any?]()
|
||||
nillableDictionary["uuid"] = self.uuid?.encodeToJSON()
|
||||
nillableDictionary["dateTime"] = self.dateTime?.encodeToJSON()
|
||||
nillableDictionary["map"] = self.map?.encodeToJSON()
|
||||
|
||||
let dictionary: [String:Any] = APIHelper.rejectNil(nillableDictionary) ?? [:]
|
||||
return dictionary
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,34 @@
|
||||
//
|
||||
// Model200Response.swift
|
||||
//
|
||||
// Generated by swagger-codegen
|
||||
// https://github.com/swagger-api/swagger-codegen
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
|
||||
/** Model for testing model name starting with number */
|
||||
open class Model200Response: JSONEncodable {
|
||||
|
||||
public var name: Int32?
|
||||
public var nameNum: NSNumber? {
|
||||
get {
|
||||
return name.map({ return NSNumber(value: $0) })
|
||||
}
|
||||
}
|
||||
public var _class: String?
|
||||
|
||||
public init() {}
|
||||
|
||||
// MARK: JSONEncodable
|
||||
open func encodeToJSON() -> Any {
|
||||
var nillableDictionary = [String:Any?]()
|
||||
nillableDictionary["name"] = self.name?.encodeToJSON()
|
||||
nillableDictionary["class"] = self._class
|
||||
|
||||
let dictionary: [String:Any] = APIHelper.rejectNil(nillableDictionary) ?? [:]
|
||||
return dictionary
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,48 @@
|
||||
//
|
||||
// Name.swift
|
||||
//
|
||||
// Generated by swagger-codegen
|
||||
// https://github.com/swagger-api/swagger-codegen
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
|
||||
/** Model for testing model name same as property name */
|
||||
open class Name: JSONEncodable {
|
||||
|
||||
public var name: Int32?
|
||||
public var nameNum: NSNumber? {
|
||||
get {
|
||||
return name.map({ return NSNumber(value: $0) })
|
||||
}
|
||||
}
|
||||
public var snakeCase: Int32?
|
||||
public var snakeCaseNum: NSNumber? {
|
||||
get {
|
||||
return snakeCase.map({ return NSNumber(value: $0) })
|
||||
}
|
||||
}
|
||||
public var property: String?
|
||||
public var _123Number: Int32?
|
||||
public var _123NumberNum: NSNumber? {
|
||||
get {
|
||||
return _123Number.map({ return NSNumber(value: $0) })
|
||||
}
|
||||
}
|
||||
|
||||
public init() {}
|
||||
|
||||
// MARK: JSONEncodable
|
||||
open func encodeToJSON() -> Any {
|
||||
var nillableDictionary = [String:Any?]()
|
||||
nillableDictionary["name"] = self.name?.encodeToJSON()
|
||||
nillableDictionary["snake_case"] = self.snakeCase?.encodeToJSON()
|
||||
nillableDictionary["property"] = self.property
|
||||
nillableDictionary["123Number"] = self._123Number?.encodeToJSON()
|
||||
|
||||
let dictionary: [String:Any] = APIHelper.rejectNil(nillableDictionary) ?? [:]
|
||||
return dictionary
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,31 @@
|
||||
//
|
||||
// NumberOnly.swift
|
||||
//
|
||||
// Generated by swagger-codegen
|
||||
// https://github.com/swagger-api/swagger-codegen
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
|
||||
open class NumberOnly: JSONEncodable {
|
||||
|
||||
public var justNumber: Double?
|
||||
public var justNumberNum: NSNumber? {
|
||||
get {
|
||||
return justNumber.map({ return NSNumber(value: $0) })
|
||||
}
|
||||
}
|
||||
|
||||
public init() {}
|
||||
|
||||
// MARK: JSONEncodable
|
||||
open func encodeToJSON() -> Any {
|
||||
var nillableDictionary = [String:Any?]()
|
||||
nillableDictionary["JustNumber"] = self.justNumber
|
||||
|
||||
let dictionary: [String:Any] = APIHelper.rejectNil(nillableDictionary) ?? [:]
|
||||
return dictionary
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,62 @@
|
||||
//
|
||||
// Order.swift
|
||||
//
|
||||
// Generated by swagger-codegen
|
||||
// https://github.com/swagger-api/swagger-codegen
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
|
||||
open class Order: JSONEncodable {
|
||||
|
||||
public enum Status: String {
|
||||
case placed = "placed"
|
||||
case approved = "approved"
|
||||
case delivered = "delivered"
|
||||
}
|
||||
public var id: Int64?
|
||||
public var idNum: NSNumber? {
|
||||
get {
|
||||
return id.map({ return NSNumber(value: $0) })
|
||||
}
|
||||
}
|
||||
public var petId: Int64?
|
||||
public var petIdNum: NSNumber? {
|
||||
get {
|
||||
return petId.map({ return NSNumber(value: $0) })
|
||||
}
|
||||
}
|
||||
public var quantity: Int32?
|
||||
public var quantityNum: NSNumber? {
|
||||
get {
|
||||
return quantity.map({ return NSNumber(value: $0) })
|
||||
}
|
||||
}
|
||||
public var shipDate: Date?
|
||||
/** Order Status */
|
||||
public var status: Status?
|
||||
public var complete: Bool?
|
||||
public var completeNum: NSNumber? {
|
||||
get {
|
||||
return complete.map({ return NSNumber(value: $0) })
|
||||
}
|
||||
}
|
||||
|
||||
public init() {}
|
||||
|
||||
// MARK: JSONEncodable
|
||||
open func encodeToJSON() -> Any {
|
||||
var nillableDictionary = [String:Any?]()
|
||||
nillableDictionary["id"] = self.id?.encodeToJSON()
|
||||
nillableDictionary["petId"] = self.petId?.encodeToJSON()
|
||||
nillableDictionary["quantity"] = self.quantity?.encodeToJSON()
|
||||
nillableDictionary["shipDate"] = self.shipDate?.encodeToJSON()
|
||||
nillableDictionary["status"] = self.status?.rawValue
|
||||
nillableDictionary["complete"] = self.complete
|
||||
|
||||
let dictionary: [String:Any] = APIHelper.rejectNil(nillableDictionary) ?? [:]
|
||||
return dictionary
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,24 @@
|
||||
//
|
||||
// OuterBoolean.swift
|
||||
//
|
||||
// Generated by swagger-codegen
|
||||
// https://github.com/swagger-api/swagger-codegen
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
|
||||
open class OuterBoolean: JSONEncodable {
|
||||
|
||||
|
||||
public init() {}
|
||||
|
||||
// MARK: JSONEncodable
|
||||
open func encodeToJSON() -> Any {
|
||||
var nillableDictionary = [String:Any?]()
|
||||
|
||||
let dictionary: [String:Any] = APIHelper.rejectNil(nillableDictionary) ?? [:]
|
||||
return dictionary
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,30 @@
|
||||
//
|
||||
// OuterComposite.swift
|
||||
//
|
||||
// Generated by swagger-codegen
|
||||
// https://github.com/swagger-api/swagger-codegen
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
|
||||
open class OuterComposite: JSONEncodable {
|
||||
|
||||
public var myNumber: OuterNumber?
|
||||
public var myString: OuterString?
|
||||
public var myBoolean: OuterBoolean?
|
||||
|
||||
public init() {}
|
||||
|
||||
// MARK: JSONEncodable
|
||||
open func encodeToJSON() -> Any {
|
||||
var nillableDictionary = [String:Any?]()
|
||||
nillableDictionary["my_number"] = self.myNumber?.encodeToJSON()
|
||||
nillableDictionary["my_string"] = self.myString?.encodeToJSON()
|
||||
nillableDictionary["my_boolean"] = self.myBoolean?.encodeToJSON()
|
||||
|
||||
let dictionary: [String:Any] = APIHelper.rejectNil(nillableDictionary) ?? [:]
|
||||
return dictionary
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,17 @@
|
||||
//
|
||||
// OuterEnum.swift
|
||||
//
|
||||
// Generated by swagger-codegen
|
||||
// https://github.com/swagger-api/swagger-codegen
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
|
||||
public enum OuterEnum: String {
|
||||
case placed = "placed"
|
||||
case approved = "approved"
|
||||
case delivered = "delivered"
|
||||
|
||||
func encodeToJSON() -> Any { return self.rawValue }
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
//
|
||||
// OuterNumber.swift
|
||||
//
|
||||
// Generated by swagger-codegen
|
||||
// https://github.com/swagger-api/swagger-codegen
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
|
||||
open class OuterNumber: JSONEncodable {
|
||||
|
||||
|
||||
public init() {}
|
||||
|
||||
// MARK: JSONEncodable
|
||||
open func encodeToJSON() -> Any {
|
||||
var nillableDictionary = [String:Any?]()
|
||||
|
||||
let dictionary: [String:Any] = APIHelper.rejectNil(nillableDictionary) ?? [:]
|
||||
return dictionary
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,24 @@
|
||||
//
|
||||
// OuterString.swift
|
||||
//
|
||||
// Generated by swagger-codegen
|
||||
// https://github.com/swagger-api/swagger-codegen
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
|
||||
open class OuterString: JSONEncodable {
|
||||
|
||||
|
||||
public init() {}
|
||||
|
||||
// MARK: JSONEncodable
|
||||
open func encodeToJSON() -> Any {
|
||||
var nillableDictionary = [String:Any?]()
|
||||
|
||||
let dictionary: [String:Any] = APIHelper.rejectNil(nillableDictionary) ?? [:]
|
||||
return dictionary
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,47 @@
|
||||
//
|
||||
// Pet.swift
|
||||
//
|
||||
// Generated by swagger-codegen
|
||||
// https://github.com/swagger-api/swagger-codegen
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
|
||||
open class Pet: JSONEncodable {
|
||||
|
||||
public enum Status: String {
|
||||
case available = "available"
|
||||
case pending = "pending"
|
||||
case sold = "sold"
|
||||
}
|
||||
public var id: Int64?
|
||||
public var idNum: NSNumber? {
|
||||
get {
|
||||
return id.map({ return NSNumber(value: $0) })
|
||||
}
|
||||
}
|
||||
public var category: Category?
|
||||
public var name: String?
|
||||
public var photoUrls: [String]?
|
||||
public var tags: [Tag]?
|
||||
/** pet status in the store */
|
||||
public var status: Status?
|
||||
|
||||
public init() {}
|
||||
|
||||
// MARK: JSONEncodable
|
||||
open func encodeToJSON() -> Any {
|
||||
var nillableDictionary = [String:Any?]()
|
||||
nillableDictionary["id"] = self.id?.encodeToJSON()
|
||||
nillableDictionary["category"] = self.category?.encodeToJSON()
|
||||
nillableDictionary["name"] = self.name
|
||||
nillableDictionary["photoUrls"] = self.photoUrls?.encodeToJSON()
|
||||
nillableDictionary["tags"] = self.tags?.encodeToJSON()
|
||||
nillableDictionary["status"] = self.status?.rawValue
|
||||
|
||||
let dictionary: [String:Any] = APIHelper.rejectNil(nillableDictionary) ?? [:]
|
||||
return dictionary
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,28 @@
|
||||
//
|
||||
// ReadOnlyFirst.swift
|
||||
//
|
||||
// Generated by swagger-codegen
|
||||
// https://github.com/swagger-api/swagger-codegen
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
|
||||
open class ReadOnlyFirst: JSONEncodable {
|
||||
|
||||
public var bar: String?
|
||||
public var baz: String?
|
||||
|
||||
public init() {}
|
||||
|
||||
// MARK: JSONEncodable
|
||||
open func encodeToJSON() -> Any {
|
||||
var nillableDictionary = [String:Any?]()
|
||||
nillableDictionary["bar"] = self.bar
|
||||
nillableDictionary["baz"] = self.baz
|
||||
|
||||
let dictionary: [String:Any] = APIHelper.rejectNil(nillableDictionary) ?? [:]
|
||||
return dictionary
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,32 @@
|
||||
//
|
||||
// Return.swift
|
||||
//
|
||||
// Generated by swagger-codegen
|
||||
// https://github.com/swagger-api/swagger-codegen
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
|
||||
/** Model for testing reserved words */
|
||||
open class Return: JSONEncodable {
|
||||
|
||||
public var _return: Int32?
|
||||
public var _returnNum: NSNumber? {
|
||||
get {
|
||||
return _return.map({ return NSNumber(value: $0) })
|
||||
}
|
||||
}
|
||||
|
||||
public init() {}
|
||||
|
||||
// MARK: JSONEncodable
|
||||
open func encodeToJSON() -> Any {
|
||||
var nillableDictionary = [String:Any?]()
|
||||
nillableDictionary["return"] = self._return?.encodeToJSON()
|
||||
|
||||
let dictionary: [String:Any] = APIHelper.rejectNil(nillableDictionary) ?? [:]
|
||||
return dictionary
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,31 @@
|
||||
//
|
||||
// SpecialModelName.swift
|
||||
//
|
||||
// Generated by swagger-codegen
|
||||
// https://github.com/swagger-api/swagger-codegen
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
|
||||
open class SpecialModelName: JSONEncodable {
|
||||
|
||||
public var specialPropertyName: Int64?
|
||||
public var specialPropertyNameNum: NSNumber? {
|
||||
get {
|
||||
return specialPropertyName.map({ return NSNumber(value: $0) })
|
||||
}
|
||||
}
|
||||
|
||||
public init() {}
|
||||
|
||||
// MARK: JSONEncodable
|
||||
open func encodeToJSON() -> Any {
|
||||
var nillableDictionary = [String:Any?]()
|
||||
nillableDictionary["$special[property.name]"] = self.specialPropertyName?.encodeToJSON()
|
||||
|
||||
let dictionary: [String:Any] = APIHelper.rejectNil(nillableDictionary) ?? [:]
|
||||
return dictionary
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,33 @@
|
||||
//
|
||||
// Tag.swift
|
||||
//
|
||||
// Generated by swagger-codegen
|
||||
// https://github.com/swagger-api/swagger-codegen
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
|
||||
open class Tag: JSONEncodable {
|
||||
|
||||
public var id: Int64?
|
||||
public var idNum: NSNumber? {
|
||||
get {
|
||||
return id.map({ return NSNumber(value: $0) })
|
||||
}
|
||||
}
|
||||
public var name: String?
|
||||
|
||||
public init() {}
|
||||
|
||||
// MARK: JSONEncodable
|
||||
open func encodeToJSON() -> Any {
|
||||
var nillableDictionary = [String:Any?]()
|
||||
nillableDictionary["id"] = self.id?.encodeToJSON()
|
||||
nillableDictionary["name"] = self.name
|
||||
|
||||
let dictionary: [String:Any] = APIHelper.rejectNil(nillableDictionary) ?? [:]
|
||||
return dictionary
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,51 @@
|
||||
//
|
||||
// User.swift
|
||||
//
|
||||
// Generated by swagger-codegen
|
||||
// https://github.com/swagger-api/swagger-codegen
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
|
||||
open class User: JSONEncodable {
|
||||
|
||||
public var id: Int64?
|
||||
public var idNum: NSNumber? {
|
||||
get {
|
||||
return id.map({ return NSNumber(value: $0) })
|
||||
}
|
||||
}
|
||||
public var username: String?
|
||||
public var firstName: String?
|
||||
public var lastName: String?
|
||||
public var email: String?
|
||||
public var password: String?
|
||||
public var phone: String?
|
||||
/** User Status */
|
||||
public var userStatus: Int32?
|
||||
public var userStatusNum: NSNumber? {
|
||||
get {
|
||||
return userStatus.map({ return NSNumber(value: $0) })
|
||||
}
|
||||
}
|
||||
|
||||
public init() {}
|
||||
|
||||
// MARK: JSONEncodable
|
||||
open func encodeToJSON() -> Any {
|
||||
var nillableDictionary = [String:Any?]()
|
||||
nillableDictionary["id"] = self.id?.encodeToJSON()
|
||||
nillableDictionary["username"] = self.username
|
||||
nillableDictionary["firstName"] = self.firstName
|
||||
nillableDictionary["lastName"] = self.lastName
|
||||
nillableDictionary["email"] = self.email
|
||||
nillableDictionary["password"] = self.password
|
||||
nillableDictionary["phone"] = self.phone
|
||||
nillableDictionary["userStatus"] = self.userStatus?.encodeToJSON()
|
||||
|
||||
let dictionary: [String:Any] = APIHelper.rejectNil(nillableDictionary) ?? [:]
|
||||
return dictionary
|
||||
}
|
||||
}
|
||||
|
52
samples/client/petstore/swift3/objcCompatible/git_push.sh
Normal file
52
samples/client/petstore/swift3/objcCompatible/git_push.sh
Normal file
@ -0,0 +1,52 @@
|
||||
#!/bin/sh
|
||||
# ref: https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/
|
||||
#
|
||||
# Usage example: /bin/sh ./git_push.sh wing328 swagger-petstore-perl "minor update"
|
||||
|
||||
git_user_id=$1
|
||||
git_repo_id=$2
|
||||
release_note=$3
|
||||
|
||||
if [ "$git_user_id" = "" ]; then
|
||||
git_user_id="GIT_USER_ID"
|
||||
echo "[INFO] No command line input provided. Set \$git_user_id to $git_user_id"
|
||||
fi
|
||||
|
||||
if [ "$git_repo_id" = "" ]; then
|
||||
git_repo_id="GIT_REPO_ID"
|
||||
echo "[INFO] No command line input provided. Set \$git_repo_id to $git_repo_id"
|
||||
fi
|
||||
|
||||
if [ "$release_note" = "" ]; then
|
||||
release_note="Minor update"
|
||||
echo "[INFO] No command line input provided. Set \$release_note to $release_note"
|
||||
fi
|
||||
|
||||
# Initialize the local directory as a Git repository
|
||||
git init
|
||||
|
||||
# Adds the files in the local repository and stages them for commit.
|
||||
git add .
|
||||
|
||||
# Commits the tracked changes and prepares them to be pushed to a remote repository.
|
||||
git commit -m "$release_note"
|
||||
|
||||
# Sets the new remote
|
||||
git_remote=`git remote`
|
||||
if [ "$git_remote" = "" ]; then # git remote not defined
|
||||
|
||||
if [ "$GIT_TOKEN" = "" ]; then
|
||||
echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git crediential in your environment."
|
||||
git remote add origin https://github.com/${git_user_id}/${git_repo_id}.git
|
||||
else
|
||||
git remote add origin https://${git_user_id}:${GIT_TOKEN}@github.com/${git_user_id}/${git_repo_id}.git
|
||||
fi
|
||||
|
||||
fi
|
||||
|
||||
git pull origin master
|
||||
|
||||
# Pushes (Forces) the changes in the local repository up to the remote repository
|
||||
echo "Git pushing to https://github.com/${git_user_id}/${git_repo_id}.git"
|
||||
git push origin master 2>&1 | grep -v 'To https'
|
||||
|
@ -32,10 +32,10 @@ open class APIBase {
|
||||
open class RequestBuilder<T> {
|
||||
var credential: URLCredential?
|
||||
var headers: [String:String]
|
||||
let parameters: Any?
|
||||
let isBody: Bool
|
||||
let method: String
|
||||
let URLString: String
|
||||
public let parameters: Any?
|
||||
public let isBody: Bool
|
||||
public let method: String
|
||||
public let URLString: String
|
||||
|
||||
/// Optional block to obtain a reference to the request's progress instance when available.
|
||||
public var onProgressReady: ((Progress) -> ())?
|
||||
|
@ -1,5 +1,5 @@
|
||||
//
|
||||
// AnotherFakeAPI.swift
|
||||
// AnotherfakeAPI.swift
|
||||
//
|
||||
// Generated by swagger-codegen
|
||||
// https://github.com/swagger-api/swagger-codegen
|
||||
@ -10,7 +10,7 @@ import Alamofire
|
||||
import PromiseKit
|
||||
|
||||
|
||||
open class AnotherFakeAPI: APIBase {
|
||||
open class AnotherfakeAPI: APIBase {
|
||||
/**
|
||||
To test special tags
|
||||
- parameter body: (body) client model
|
||||
|
@ -54,7 +54,7 @@ open class Fake_classname_tags123API: APIBase {
|
||||
open class func testClassnameWithRequestBuilder(body: Client) -> RequestBuilder<Client> {
|
||||
let path = "/fake_classname_test"
|
||||
let URLString = PetstoreClientAPI.basePath + path
|
||||
let parameters = body.encodeToJSON() as? [String:AnyObject]
|
||||
let parameters = body.encodeToJSON()
|
||||
|
||||
let url = NSURLComponents(string: URLString)
|
||||
|
||||
|
@ -104,7 +104,9 @@ open class PetAPI: APIBase {
|
||||
*/
|
||||
open class func deletePetWithRequestBuilder(petId: Int64, apiKey: String? = nil) -> RequestBuilder<Void> {
|
||||
var path = "/pet/{petId}"
|
||||
path = path.replacingOccurrences(of: "{petId}", with: "\(petId)", options: .literal, range: nil)
|
||||
let petIdPreEscape = "\(petId)"
|
||||
let petIdPostEscape = petIdPreEscape.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
|
||||
path = path.replacingOccurrences(of: "{petId}", with: petIdPostEscape, options: .literal, range: nil)
|
||||
let URLString = PetstoreClientAPI.basePath + path
|
||||
let parameters: [String:Any]? = nil
|
||||
|
||||
@ -494,7 +496,9 @@ open class PetAPI: APIBase {
|
||||
*/
|
||||
open class func getPetByIdWithRequestBuilder(petId: Int64) -> RequestBuilder<Pet> {
|
||||
var path = "/pet/{petId}"
|
||||
path = path.replacingOccurrences(of: "{petId}", with: "\(petId)", options: .literal, range: nil)
|
||||
let petIdPreEscape = "\(petId)"
|
||||
let petIdPostEscape = petIdPreEscape.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
|
||||
path = path.replacingOccurrences(of: "{petId}", with: petIdPostEscape, options: .literal, range: nil)
|
||||
let URLString = PetstoreClientAPI.basePath + path
|
||||
let parameters: [String:Any]? = nil
|
||||
|
||||
@ -601,7 +605,9 @@ open class PetAPI: APIBase {
|
||||
*/
|
||||
open class func updatePetWithFormWithRequestBuilder(petId: Int64, name: String? = nil, status: String? = nil) -> RequestBuilder<Void> {
|
||||
var path = "/pet/{petId}"
|
||||
path = path.replacingOccurrences(of: "{petId}", with: "\(petId)", options: .literal, range: nil)
|
||||
let petIdPreEscape = "\(petId)"
|
||||
let petIdPostEscape = petIdPreEscape.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
|
||||
path = path.replacingOccurrences(of: "{petId}", with: petIdPostEscape, options: .literal, range: nil)
|
||||
let URLString = PetstoreClientAPI.basePath + path
|
||||
let formParams: [String:Any?] = [
|
||||
"name": name,
|
||||
@ -669,7 +675,9 @@ open class PetAPI: APIBase {
|
||||
*/
|
||||
open class func uploadFileWithRequestBuilder(petId: Int64, additionalMetadata: String? = nil, file: URL? = nil) -> RequestBuilder<ApiResponse> {
|
||||
var path = "/pet/{petId}/uploadImage"
|
||||
path = path.replacingOccurrences(of: "{petId}", with: "\(petId)", options: .literal, range: nil)
|
||||
let petIdPreEscape = "\(petId)"
|
||||
let petIdPostEscape = petIdPreEscape.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
|
||||
path = path.replacingOccurrences(of: "{petId}", with: petIdPostEscape, options: .literal, range: nil)
|
||||
let URLString = PetstoreClientAPI.basePath + path
|
||||
let formParams: [String:Any?] = [
|
||||
"additionalMetadata": additionalMetadata,
|
||||
|
@ -49,7 +49,9 @@ open class StoreAPI: APIBase {
|
||||
*/
|
||||
open class func deleteOrderWithRequestBuilder(orderId: String) -> RequestBuilder<Void> {
|
||||
var path = "/store/order/{order_id}"
|
||||
path = path.replacingOccurrences(of: "{order_id}", with: "\(orderId)", options: .literal, range: nil)
|
||||
let orderIdPreEscape = "\(orderId)"
|
||||
let orderIdPostEscape = orderIdPreEscape.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
|
||||
path = path.replacingOccurrences(of: "{order_id}", with: orderIdPostEscape, options: .literal, range: nil)
|
||||
let URLString = PetstoreClientAPI.basePath + path
|
||||
let parameters: [String:Any]? = nil
|
||||
|
||||
@ -178,7 +180,9 @@ open class StoreAPI: APIBase {
|
||||
*/
|
||||
open class func getOrderByIdWithRequestBuilder(orderId: Int64) -> RequestBuilder<Order> {
|
||||
var path = "/store/order/{order_id}"
|
||||
path = path.replacingOccurrences(of: "{order_id}", with: "\(orderId)", options: .literal, range: nil)
|
||||
let orderIdPreEscape = "\(orderId)"
|
||||
let orderIdPostEscape = orderIdPreEscape.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
|
||||
path = path.replacingOccurrences(of: "{order_id}", with: orderIdPostEscape, options: .literal, range: nil)
|
||||
let URLString = PetstoreClientAPI.basePath + path
|
||||
let parameters: [String:Any]? = nil
|
||||
|
||||
|
@ -193,7 +193,9 @@ open class UserAPI: APIBase {
|
||||
*/
|
||||
open class func deleteUserWithRequestBuilder(username: String) -> RequestBuilder<Void> {
|
||||
var path = "/user/{username}"
|
||||
path = path.replacingOccurrences(of: "{username}", with: "\(username)", options: .literal, range: nil)
|
||||
let usernamePreEscape = "\(username)"
|
||||
let usernamePostEscape = usernamePreEscape.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
|
||||
path = path.replacingOccurrences(of: "{username}", with: usernamePostEscape, options: .literal, range: nil)
|
||||
let URLString = PetstoreClientAPI.basePath + path
|
||||
let parameters: [String:Any]? = nil
|
||||
|
||||
@ -280,7 +282,9 @@ open class UserAPI: APIBase {
|
||||
*/
|
||||
open class func getUserByNameWithRequestBuilder(username: String) -> RequestBuilder<User> {
|
||||
var path = "/user/{username}"
|
||||
path = path.replacingOccurrences(of: "{username}", with: "\(username)", options: .literal, range: nil)
|
||||
let usernamePreEscape = "\(username)"
|
||||
let usernamePostEscape = usernamePreEscape.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
|
||||
path = path.replacingOccurrences(of: "{username}", with: usernamePostEscape, options: .literal, range: nil)
|
||||
let URLString = PetstoreClientAPI.basePath + path
|
||||
let parameters: [String:Any]? = nil
|
||||
|
||||
@ -436,7 +440,9 @@ open class UserAPI: APIBase {
|
||||
*/
|
||||
open class func updateUserWithRequestBuilder(username: String, body: User) -> RequestBuilder<Void> {
|
||||
var path = "/user/{username}"
|
||||
path = path.replacingOccurrences(of: "{username}", with: "\(username)", options: .literal, range: nil)
|
||||
let usernamePreEscape = "\(username)"
|
||||
let usernamePostEscape = usernamePreEscape.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
|
||||
path = path.replacingOccurrences(of: "{username}", with: usernamePostEscape, options: .literal, range: nil)
|
||||
let URLString = PetstoreClientAPI.basePath + path
|
||||
let parameters = body.encodeToJSON()
|
||||
|
||||
|
@ -102,4 +102,14 @@ class UserAPITests: XCTestCase {
|
||||
self.waitForExpectations(timeout: testTimeout, handler: nil)
|
||||
}
|
||||
|
||||
func testPathParamsAreEscaped() {
|
||||
// The path for this operation is /user/{userId}. In order to make a usable path,
|
||||
// then we must make sure that {userId} is percent-escaped when it is substituted
|
||||
// into the path. So we intentionally introduce a path with spaces.
|
||||
let userRequestBuilder = UserAPI.getUserByNameWithRequestBuilder(username: "User Name With Spaces")
|
||||
let urlContainsSpace = userRequestBuilder.URLString.contains(" ")
|
||||
|
||||
XCTAssert(!urlContainsSpace, "Expected URL to be escaped, but it was not.")
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -32,10 +32,10 @@ open class APIBase {
|
||||
open class RequestBuilder<T> {
|
||||
var credential: URLCredential?
|
||||
var headers: [String:String]
|
||||
let parameters: Any?
|
||||
let isBody: Bool
|
||||
let method: String
|
||||
let URLString: String
|
||||
public let parameters: Any?
|
||||
public let isBody: Bool
|
||||
public let method: String
|
||||
public let URLString: String
|
||||
|
||||
/// Optional block to obtain a reference to the request's progress instance when available.
|
||||
public var onProgressReady: ((Progress) -> ())?
|
||||
|
@ -1,5 +1,5 @@
|
||||
//
|
||||
// AnotherFakeAPI.swift
|
||||
// AnotherfakeAPI.swift
|
||||
//
|
||||
// Generated by swagger-codegen
|
||||
// https://github.com/swagger-api/swagger-codegen
|
||||
@ -10,7 +10,7 @@ import Alamofire
|
||||
import RxSwift
|
||||
|
||||
|
||||
open class AnotherFakeAPI: APIBase {
|
||||
open class AnotherfakeAPI: APIBase {
|
||||
/**
|
||||
To test special tags
|
||||
- parameter body: (body) client model
|
||||
|
@ -56,7 +56,7 @@ open class Fake_classname_tags123API: APIBase {
|
||||
open class func testClassnameWithRequestBuilder(body: Client) -> RequestBuilder<Client> {
|
||||
let path = "/fake_classname_test"
|
||||
let URLString = PetstoreClientAPI.basePath + path
|
||||
let parameters = body.encodeToJSON() as? [String:AnyObject]
|
||||
let parameters = body.encodeToJSON()
|
||||
|
||||
let url = NSURLComponents(string: URLString)
|
||||
|
||||
|
@ -108,7 +108,9 @@ open class PetAPI: APIBase {
|
||||
*/
|
||||
open class func deletePetWithRequestBuilder(petId: Int64, apiKey: String? = nil) -> RequestBuilder<Void> {
|
||||
var path = "/pet/{petId}"
|
||||
path = path.replacingOccurrences(of: "{petId}", with: "\(petId)", options: .literal, range: nil)
|
||||
let petIdPreEscape = "\(petId)"
|
||||
let petIdPostEscape = petIdPreEscape.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
|
||||
path = path.replacingOccurrences(of: "{petId}", with: petIdPostEscape, options: .literal, range: nil)
|
||||
let URLString = PetstoreClientAPI.basePath + path
|
||||
let parameters: [String:Any]? = nil
|
||||
|
||||
@ -504,7 +506,9 @@ open class PetAPI: APIBase {
|
||||
*/
|
||||
open class func getPetByIdWithRequestBuilder(petId: Int64) -> RequestBuilder<Pet> {
|
||||
var path = "/pet/{petId}"
|
||||
path = path.replacingOccurrences(of: "{petId}", with: "\(petId)", options: .literal, range: nil)
|
||||
let petIdPreEscape = "\(petId)"
|
||||
let petIdPostEscape = petIdPreEscape.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
|
||||
path = path.replacingOccurrences(of: "{petId}", with: petIdPostEscape, options: .literal, range: nil)
|
||||
let URLString = PetstoreClientAPI.basePath + path
|
||||
let parameters: [String:Any]? = nil
|
||||
|
||||
@ -615,7 +619,9 @@ open class PetAPI: APIBase {
|
||||
*/
|
||||
open class func updatePetWithFormWithRequestBuilder(petId: Int64, name: String? = nil, status: String? = nil) -> RequestBuilder<Void> {
|
||||
var path = "/pet/{petId}"
|
||||
path = path.replacingOccurrences(of: "{petId}", with: "\(petId)", options: .literal, range: nil)
|
||||
let petIdPreEscape = "\(petId)"
|
||||
let petIdPostEscape = petIdPreEscape.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
|
||||
path = path.replacingOccurrences(of: "{petId}", with: petIdPostEscape, options: .literal, range: nil)
|
||||
let URLString = PetstoreClientAPI.basePath + path
|
||||
let formParams: [String:Any?] = [
|
||||
"name": name,
|
||||
@ -685,7 +691,9 @@ open class PetAPI: APIBase {
|
||||
*/
|
||||
open class func uploadFileWithRequestBuilder(petId: Int64, additionalMetadata: String? = nil, file: URL? = nil) -> RequestBuilder<ApiResponse> {
|
||||
var path = "/pet/{petId}/uploadImage"
|
||||
path = path.replacingOccurrences(of: "{petId}", with: "\(petId)", options: .literal, range: nil)
|
||||
let petIdPreEscape = "\(petId)"
|
||||
let petIdPostEscape = petIdPreEscape.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
|
||||
path = path.replacingOccurrences(of: "{petId}", with: petIdPostEscape, options: .literal, range: nil)
|
||||
let URLString = PetstoreClientAPI.basePath + path
|
||||
let formParams: [String:Any?] = [
|
||||
"additionalMetadata": additionalMetadata,
|
||||
|
@ -51,7 +51,9 @@ open class StoreAPI: APIBase {
|
||||
*/
|
||||
open class func deleteOrderWithRequestBuilder(orderId: String) -> RequestBuilder<Void> {
|
||||
var path = "/store/order/{order_id}"
|
||||
path = path.replacingOccurrences(of: "{order_id}", with: "\(orderId)", options: .literal, range: nil)
|
||||
let orderIdPreEscape = "\(orderId)"
|
||||
let orderIdPostEscape = orderIdPreEscape.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
|
||||
path = path.replacingOccurrences(of: "{order_id}", with: orderIdPostEscape, options: .literal, range: nil)
|
||||
let URLString = PetstoreClientAPI.basePath + path
|
||||
let parameters: [String:Any]? = nil
|
||||
|
||||
@ -184,7 +186,9 @@ open class StoreAPI: APIBase {
|
||||
*/
|
||||
open class func getOrderByIdWithRequestBuilder(orderId: Int64) -> RequestBuilder<Order> {
|
||||
var path = "/store/order/{order_id}"
|
||||
path = path.replacingOccurrences(of: "{order_id}", with: "\(orderId)", options: .literal, range: nil)
|
||||
let orderIdPreEscape = "\(orderId)"
|
||||
let orderIdPostEscape = orderIdPreEscape.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
|
||||
path = path.replacingOccurrences(of: "{order_id}", with: orderIdPostEscape, options: .literal, range: nil)
|
||||
let URLString = PetstoreClientAPI.basePath + path
|
||||
let parameters: [String:Any]? = nil
|
||||
|
||||
|
@ -201,7 +201,9 @@ open class UserAPI: APIBase {
|
||||
*/
|
||||
open class func deleteUserWithRequestBuilder(username: String) -> RequestBuilder<Void> {
|
||||
var path = "/user/{username}"
|
||||
path = path.replacingOccurrences(of: "{username}", with: "\(username)", options: .literal, range: nil)
|
||||
let usernamePreEscape = "\(username)"
|
||||
let usernamePostEscape = usernamePreEscape.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
|
||||
path = path.replacingOccurrences(of: "{username}", with: usernamePostEscape, options: .literal, range: nil)
|
||||
let URLString = PetstoreClientAPI.basePath + path
|
||||
let parameters: [String:Any]? = nil
|
||||
|
||||
@ -290,7 +292,9 @@ open class UserAPI: APIBase {
|
||||
*/
|
||||
open class func getUserByNameWithRequestBuilder(username: String) -> RequestBuilder<User> {
|
||||
var path = "/user/{username}"
|
||||
path = path.replacingOccurrences(of: "{username}", with: "\(username)", options: .literal, range: nil)
|
||||
let usernamePreEscape = "\(username)"
|
||||
let usernamePostEscape = usernamePreEscape.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
|
||||
path = path.replacingOccurrences(of: "{username}", with: usernamePostEscape, options: .literal, range: nil)
|
||||
let URLString = PetstoreClientAPI.basePath + path
|
||||
let parameters: [String:Any]? = nil
|
||||
|
||||
@ -452,7 +456,9 @@ open class UserAPI: APIBase {
|
||||
*/
|
||||
open class func updateUserWithRequestBuilder(username: String, body: User) -> RequestBuilder<Void> {
|
||||
var path = "/user/{username}"
|
||||
path = path.replacingOccurrences(of: "{username}", with: "\(username)", options: .literal, range: nil)
|
||||
let usernamePreEscape = "\(username)"
|
||||
let usernamePostEscape = usernamePreEscape.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
|
||||
path = path.replacingOccurrences(of: "{username}", with: usernamePostEscape, options: .literal, range: nil)
|
||||
let URLString = PetstoreClientAPI.basePath + path
|
||||
let parameters = body.encodeToJSON()
|
||||
|
||||
|
@ -160,4 +160,14 @@ class UserAPITests: XCTestCase {
|
||||
self.waitForExpectations(timeout: testTimeout, handler: nil)
|
||||
}
|
||||
|
||||
func testPathParamsAreEscaped() {
|
||||
// The path for this operation is /user/{userId}. In order to make a usable path,
|
||||
// then we must make sure that {userId} is percent-escaped when it is substituted
|
||||
// into the path. So we intentionally introduce a path with spaces.
|
||||
let userRequestBuilder = UserAPI.getUserByNameWithRequestBuilder(username: "User Name With Spaces")
|
||||
let urlContainsSpace = userRequestBuilder.URLString.contains(" ")
|
||||
|
||||
XCTAssert(!urlContainsSpace, "Expected URL to be escaped, but it was not.")
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -32,10 +32,10 @@ open class APIBase {
|
||||
open class RequestBuilder<T> {
|
||||
var credential: URLCredential?
|
||||
var headers: [String:String]
|
||||
let parameters: Any?
|
||||
let isBody: Bool
|
||||
let method: String
|
||||
let URLString: String
|
||||
public let parameters: Any?
|
||||
public let isBody: Bool
|
||||
public let method: String
|
||||
public let URLString: String
|
||||
|
||||
/// Optional block to obtain a reference to the request's progress instance when available.
|
||||
public var onProgressReady: ((Progress) -> ())?
|
||||
|
@ -1,5 +1,5 @@
|
||||
//
|
||||
// AnotherFakeAPI.swift
|
||||
// AnotherfakeAPI.swift
|
||||
//
|
||||
// Generated by swagger-codegen
|
||||
// https://github.com/swagger-api/swagger-codegen
|
||||
@ -9,7 +9,7 @@ import Foundation
|
||||
import Alamofire
|
||||
|
||||
|
||||
open class AnotherFakeAPI: APIBase {
|
||||
open class AnotherfakeAPI: APIBase {
|
||||
/**
|
||||
To test special tags
|
||||
- parameter body: (body) client model
|
||||
|
@ -37,7 +37,7 @@ open class Fake_classname_tags123API: APIBase {
|
||||
open class func testClassnameWithRequestBuilder(body: Client) -> RequestBuilder<Client> {
|
||||
let path = "/fake_classname_test"
|
||||
let URLString = PetstoreClientAPI.basePath + path
|
||||
let parameters = body.encodeToJSON() as? [String:AnyObject]
|
||||
let parameters = body.encodeToJSON()
|
||||
|
||||
let url = NSURLComponents(string: URLString)
|
||||
|
||||
|
@ -70,7 +70,9 @@ open class PetAPI: APIBase {
|
||||
*/
|
||||
open class func deletePetWithRequestBuilder(petId: Int64, apiKey: String? = nil) -> RequestBuilder<Void> {
|
||||
var path = "/pet/{petId}"
|
||||
path = path.replacingOccurrences(of: "{petId}", with: "\(petId)", options: .literal, range: nil)
|
||||
let petIdPreEscape = "\(petId)"
|
||||
let petIdPostEscape = petIdPreEscape.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
|
||||
path = path.replacingOccurrences(of: "{petId}", with: petIdPostEscape, options: .literal, range: nil)
|
||||
let URLString = PetstoreClientAPI.basePath + path
|
||||
let parameters: [String:Any]? = nil
|
||||
|
||||
@ -412,7 +414,9 @@ open class PetAPI: APIBase {
|
||||
*/
|
||||
open class func getPetByIdWithRequestBuilder(petId: Int64) -> RequestBuilder<Pet> {
|
||||
var path = "/pet/{petId}"
|
||||
path = path.replacingOccurrences(of: "{petId}", with: "\(petId)", options: .literal, range: nil)
|
||||
let petIdPreEscape = "\(petId)"
|
||||
let petIdPostEscape = petIdPreEscape.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
|
||||
path = path.replacingOccurrences(of: "{petId}", with: petIdPostEscape, options: .literal, range: nil)
|
||||
let URLString = PetstoreClientAPI.basePath + path
|
||||
let parameters: [String:Any]? = nil
|
||||
|
||||
@ -485,7 +489,9 @@ open class PetAPI: APIBase {
|
||||
*/
|
||||
open class func updatePetWithFormWithRequestBuilder(petId: Int64, name: String? = nil, status: String? = nil) -> RequestBuilder<Void> {
|
||||
var path = "/pet/{petId}"
|
||||
path = path.replacingOccurrences(of: "{petId}", with: "\(petId)", options: .literal, range: nil)
|
||||
let petIdPreEscape = "\(petId)"
|
||||
let petIdPostEscape = petIdPreEscape.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
|
||||
path = path.replacingOccurrences(of: "{petId}", with: petIdPostEscape, options: .literal, range: nil)
|
||||
let URLString = PetstoreClientAPI.basePath + path
|
||||
let formParams: [String:Any?] = [
|
||||
"name": name,
|
||||
@ -535,7 +541,9 @@ open class PetAPI: APIBase {
|
||||
*/
|
||||
open class func uploadFileWithRequestBuilder(petId: Int64, additionalMetadata: String? = nil, file: URL? = nil) -> RequestBuilder<ApiResponse> {
|
||||
var path = "/pet/{petId}/uploadImage"
|
||||
path = path.replacingOccurrences(of: "{petId}", with: "\(petId)", options: .literal, range: nil)
|
||||
let petIdPreEscape = "\(petId)"
|
||||
let petIdPostEscape = petIdPreEscape.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
|
||||
path = path.replacingOccurrences(of: "{petId}", with: petIdPostEscape, options: .literal, range: nil)
|
||||
let URLString = PetstoreClientAPI.basePath + path
|
||||
let formParams: [String:Any?] = [
|
||||
"additionalMetadata": additionalMetadata,
|
||||
|
@ -32,7 +32,9 @@ open class StoreAPI: APIBase {
|
||||
*/
|
||||
open class func deleteOrderWithRequestBuilder(orderId: String) -> RequestBuilder<Void> {
|
||||
var path = "/store/order/{order_id}"
|
||||
path = path.replacingOccurrences(of: "{order_id}", with: "\(orderId)", options: .literal, range: nil)
|
||||
let orderIdPreEscape = "\(orderId)"
|
||||
let orderIdPostEscape = orderIdPreEscape.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
|
||||
path = path.replacingOccurrences(of: "{order_id}", with: orderIdPostEscape, options: .literal, range: nil)
|
||||
let URLString = PetstoreClientAPI.basePath + path
|
||||
let parameters: [String:Any]? = nil
|
||||
|
||||
@ -130,7 +132,9 @@ open class StoreAPI: APIBase {
|
||||
*/
|
||||
open class func getOrderByIdWithRequestBuilder(orderId: Int64) -> RequestBuilder<Order> {
|
||||
var path = "/store/order/{order_id}"
|
||||
path = path.replacingOccurrences(of: "{order_id}", with: "\(orderId)", options: .literal, range: nil)
|
||||
let orderIdPreEscape = "\(orderId)"
|
||||
let orderIdPostEscape = orderIdPreEscape.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
|
||||
path = path.replacingOccurrences(of: "{order_id}", with: orderIdPostEscape, options: .literal, range: nil)
|
||||
let URLString = PetstoreClientAPI.basePath + path
|
||||
let parameters: [String:Any]? = nil
|
||||
|
||||
|
@ -128,7 +128,9 @@ open class UserAPI: APIBase {
|
||||
*/
|
||||
open class func deleteUserWithRequestBuilder(username: String) -> RequestBuilder<Void> {
|
||||
var path = "/user/{username}"
|
||||
path = path.replacingOccurrences(of: "{username}", with: "\(username)", options: .literal, range: nil)
|
||||
let usernamePreEscape = "\(username)"
|
||||
let usernamePostEscape = usernamePreEscape.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
|
||||
path = path.replacingOccurrences(of: "{username}", with: usernamePostEscape, options: .literal, range: nil)
|
||||
let URLString = PetstoreClientAPI.basePath + path
|
||||
let parameters: [String:Any]? = nil
|
||||
|
||||
@ -199,7 +201,9 @@ open class UserAPI: APIBase {
|
||||
*/
|
||||
open class func getUserByNameWithRequestBuilder(username: String) -> RequestBuilder<User> {
|
||||
var path = "/user/{username}"
|
||||
path = path.replacingOccurrences(of: "{username}", with: "\(username)", options: .literal, range: nil)
|
||||
let usernamePreEscape = "\(username)"
|
||||
let usernamePostEscape = usernamePreEscape.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
|
||||
path = path.replacingOccurrences(of: "{username}", with: usernamePostEscape, options: .literal, range: nil)
|
||||
let URLString = PetstoreClientAPI.basePath + path
|
||||
let parameters: [String:Any]? = nil
|
||||
|
||||
@ -306,7 +310,9 @@ open class UserAPI: APIBase {
|
||||
*/
|
||||
open class func updateUserWithRequestBuilder(username: String, body: User) -> RequestBuilder<Void> {
|
||||
var path = "/user/{username}"
|
||||
path = path.replacingOccurrences(of: "{username}", with: "\(username)", options: .literal, range: nil)
|
||||
let usernamePreEscape = "\(username)"
|
||||
let usernamePostEscape = usernamePreEscape.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
|
||||
path = path.replacingOccurrences(of: "{username}", with: usernamePostEscape, options: .literal, range: nil)
|
||||
let URLString = PetstoreClientAPI.basePath + path
|
||||
let parameters = body.encodeToJSON()
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user