forked from loafle/openapi-generator-original
Add generated code
This commit is contained in:
parent
a7c91d610f
commit
495e528eec
2
samples/client/petstore/swift/Cartfile
Normal file
2
samples/client/petstore/swift/Cartfile
Normal file
@ -0,0 +1,2 @@
|
||||
github "Alamofire/Alamofire" >= 1.2
|
||||
github "mxcl/PromiseKit" >=1.5.3
|
@ -0,0 +1,21 @@
|
||||
// APIHelper.swift
|
||||
//
|
||||
// Generated by swagger-codegen
|
||||
// https://github.com/swagger-api/swagger-codegen
|
||||
//
|
||||
|
||||
class APIHelper {
|
||||
static func rejectNil(source: [String:AnyObject?]) -> [String:AnyObject]? {
|
||||
var destination = [String:AnyObject]()
|
||||
for (key, nillableValue) in source {
|
||||
if let value: AnyObject = nillableValue {
|
||||
destination[key] = value
|
||||
}
|
||||
}
|
||||
|
||||
if destination.isEmpty {
|
||||
return nil
|
||||
}
|
||||
return destination
|
||||
}
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
// APIs.swift
|
||||
//
|
||||
// Generated by swagger-codegen
|
||||
// https://github.com/swagger-api/swagger-codegen
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import PromiseKit
|
||||
|
||||
class PetstoreClientAPI {
|
||||
static let basePath = "http://petstore.swagger.io/v2"
|
||||
static var credential: NSURLCredential?
|
||||
static var requestBuilderFactory: RequestBuilderFactory = AlamofireRequestBuilderFactory()
|
||||
}
|
||||
|
||||
class APIBase {
|
||||
func toParameters(encodable: JSONEncodable?) -> [String: AnyObject]? {
|
||||
let encoded: AnyObject? = encodable?.encodeToJSON()
|
||||
|
||||
if encoded! is [AnyObject] {
|
||||
var dictionary = [String:AnyObject]()
|
||||
for (index, item) in enumerate(encoded as! [AnyObject]) {
|
||||
dictionary["\(index)"] = item
|
||||
}
|
||||
return dictionary
|
||||
} else {
|
||||
return encoded as? [String:AnyObject]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class RequestBuilder<T> {
|
||||
var credential: NSURLCredential?
|
||||
var headers: [String:String] = [:]
|
||||
let parameters: [String:AnyObject]?
|
||||
let isBody: Bool
|
||||
let method: String
|
||||
let URLString: String
|
||||
|
||||
required init(method: String, URLString: String, parameters: [String:AnyObject]?, isBody: Bool) {
|
||||
self.method = method
|
||||
self.URLString = URLString
|
||||
self.parameters = parameters
|
||||
self.isBody = isBody
|
||||
}
|
||||
|
||||
func execute() -> Promise<Response<T>> { fatalError("Not implemented") }
|
||||
|
||||
func addHeader(#name: String, value: String) -> Self {
|
||||
if !value.isEmpty {
|
||||
headers[name] = value
|
||||
}
|
||||
return self
|
||||
}
|
||||
|
||||
func addCredential() -> Self {
|
||||
self.credential = PetstoreClientAPI.credential
|
||||
return self
|
||||
}
|
||||
}
|
||||
|
||||
protocol RequestBuilderFactory {
|
||||
func getBuilder<T>() -> RequestBuilder<T>.Type
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,225 @@
|
||||
//
|
||||
// PetAPI.swift
|
||||
//
|
||||
// Generated by swagger-codegen
|
||||
// https://github.com/swagger-api/swagger-codegen
|
||||
//
|
||||
|
||||
import Alamofire
|
||||
import PromiseKit
|
||||
|
||||
extension PetstoreClientAPI {
|
||||
|
||||
class PetAPI: APIBase {
|
||||
|
||||
/**
|
||||
|
||||
Update an existing pet
|
||||
|
||||
- PUT /pet
|
||||
-
|
||||
- authMethods: [com.wordnik.swagger.codegen.CodegenSecurity@5fd7e9cb]
|
||||
|
||||
:param: body (body) Pet object that needs to be added to the store
|
||||
|
||||
:returns: Promise<Response<Void>>
|
||||
*/
|
||||
func updatePet(#body: Pet?) -> RequestBuilder<Void> {
|
||||
let path = "/pet"
|
||||
let url = PetstoreClientAPI.basePath + path
|
||||
|
||||
let parameters = body?.encodeToJSON() as? [String:AnyObject]
|
||||
|
||||
let requestBuilder: RequestBuilder<Void>.Type = PetstoreClientAPI.requestBuilderFactory.getBuilder()
|
||||
|
||||
return requestBuilder(method: "PUT", URLString: url, parameters: parameters, isBody: true)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Add a new pet to the store
|
||||
|
||||
- POST /pet
|
||||
-
|
||||
- authMethods: [com.wordnik.swagger.codegen.CodegenSecurity@58363f95]
|
||||
|
||||
:param: body (body) Pet object that needs to be added to the store
|
||||
|
||||
:returns: Promise<Response<Void>>
|
||||
*/
|
||||
func addPet(#body: Pet?) -> RequestBuilder<Void> {
|
||||
let path = "/pet"
|
||||
let url = PetstoreClientAPI.basePath + path
|
||||
|
||||
let parameters = body?.encodeToJSON() as? [String:AnyObject]
|
||||
|
||||
let requestBuilder: RequestBuilder<Void>.Type = PetstoreClientAPI.requestBuilderFactory.getBuilder()
|
||||
|
||||
return requestBuilder(method: "POST", URLString: url, parameters: parameters, isBody: true)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Finds Pets by status
|
||||
|
||||
- GET /pet/findByStatus
|
||||
- Multiple status values can be provided with comma seperated strings
|
||||
- authMethods: [com.wordnik.swagger.codegen.CodegenSecurity@51887c71]
|
||||
- examples: [{example=[ {\n "tags" : [ {\n "id" : 123456789,\n "name" : "aeiou"\n } ],\n "id" : 123456789,\n "category" : {\n "id" : 123456789,\n "name" : "aeiou"\n },\n "status" : "aeiou",\n "name" : "doggie",\n "photoUrls" : [ "aeiou" ]\n} ], contentType=application/json}, {example=<Pet>\n <id>123456</id>\n <Category>\n <id>123456</id>\n <name>string</name>\n </Category>\n <name>doggie</name>\n <photoUrls>string</photoUrls>\n <Tag>\n <id>123456</id>\n <name>string</name>\n </Tag>\n <status>string</status>\n</Pet>, contentType=application/xml}]
|
||||
- examples: [{example=[ {\n "tags" : [ {\n "id" : 123456789,\n "name" : "aeiou"\n } ],\n "id" : 123456789,\n "category" : {\n "id" : 123456789,\n "name" : "aeiou"\n },\n "status" : "aeiou",\n "name" : "doggie",\n "photoUrls" : [ "aeiou" ]\n} ], contentType=application/json}, {example=<Pet>\n <id>123456</id>\n <Category>\n <id>123456</id>\n <name>string</name>\n </Category>\n <name>doggie</name>\n <photoUrls>string</photoUrls>\n <Tag>\n <id>123456</id>\n <name>string</name>\n </Tag>\n <status>string</status>\n</Pet>, contentType=application/xml}]
|
||||
|
||||
:param: status (query) Status values that need to be considered for filter
|
||||
|
||||
:returns: Promise<Response<[Pet]>>
|
||||
*/
|
||||
func findPetsByStatus(#status: [String]?) -> RequestBuilder<[Pet]> {
|
||||
let path = "/pet/findByStatus"
|
||||
let url = PetstoreClientAPI.basePath + path
|
||||
|
||||
let nillableParameters: [String:AnyObject?] = [
|
||||
"status": status
|
||||
]
|
||||
let parameters = APIHelper.rejectNil(nillableParameters)
|
||||
|
||||
let requestBuilder: RequestBuilder<[Pet]>.Type = PetstoreClientAPI.requestBuilderFactory.getBuilder()
|
||||
|
||||
return requestBuilder(method: "GET", URLString: url, parameters: parameters, isBody: false)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Finds Pets by tags
|
||||
|
||||
- GET /pet/findByTags
|
||||
- Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing.
|
||||
- authMethods: [com.wordnik.swagger.codegen.CodegenSecurity@4ede45aa]
|
||||
- examples: [{example=[ {\n "tags" : [ {\n "id" : 123456789,\n "name" : "aeiou"\n } ],\n "id" : 123456789,\n "category" : {\n "id" : 123456789,\n "name" : "aeiou"\n },\n "status" : "aeiou",\n "name" : "doggie",\n "photoUrls" : [ "aeiou" ]\n} ], contentType=application/json}, {example=<Pet>\n <id>123456</id>\n <Category>\n <id>123456</id>\n <name>string</name>\n </Category>\n <name>doggie</name>\n <photoUrls>string</photoUrls>\n <Tag>\n <id>123456</id>\n <name>string</name>\n </Tag>\n <status>string</status>\n</Pet>, contentType=application/xml}]
|
||||
- examples: [{example=[ {\n "tags" : [ {\n "id" : 123456789,\n "name" : "aeiou"\n } ],\n "id" : 123456789,\n "category" : {\n "id" : 123456789,\n "name" : "aeiou"\n },\n "status" : "aeiou",\n "name" : "doggie",\n "photoUrls" : [ "aeiou" ]\n} ], contentType=application/json}, {example=<Pet>\n <id>123456</id>\n <Category>\n <id>123456</id>\n <name>string</name>\n </Category>\n <name>doggie</name>\n <photoUrls>string</photoUrls>\n <Tag>\n <id>123456</id>\n <name>string</name>\n </Tag>\n <status>string</status>\n</Pet>, contentType=application/xml}]
|
||||
|
||||
:param: tags (query) Tags to filter by
|
||||
|
||||
:returns: Promise<Response<[Pet]>>
|
||||
*/
|
||||
func findPetsByTags(#tags: [String]?) -> RequestBuilder<[Pet]> {
|
||||
let path = "/pet/findByTags"
|
||||
let url = PetstoreClientAPI.basePath + path
|
||||
|
||||
let nillableParameters: [String:AnyObject?] = [
|
||||
"tags": tags
|
||||
]
|
||||
let parameters = APIHelper.rejectNil(nillableParameters)
|
||||
|
||||
let requestBuilder: RequestBuilder<[Pet]>.Type = PetstoreClientAPI.requestBuilderFactory.getBuilder()
|
||||
|
||||
return requestBuilder(method: "GET", URLString: url, parameters: parameters, isBody: false)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Find pet by ID
|
||||
|
||||
- GET /pet/{petId}
|
||||
- Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions
|
||||
- authMethods: [com.wordnik.swagger.codegen.CodegenSecurity@62afc459, com.wordnik.swagger.codegen.CodegenSecurity@183e1ad]
|
||||
- authMethods: [com.wordnik.swagger.codegen.CodegenSecurity@62afc459, com.wordnik.swagger.codegen.CodegenSecurity@183e1ad]
|
||||
- examples: [{example={\n "tags" : [ {\n "id" : 123456789,\n "name" : "aeiou"\n } ],\n "id" : 123456789,\n "category" : {\n "id" : 123456789,\n "name" : "aeiou"\n },\n "status" : "aeiou",\n "name" : "doggie",\n "photoUrls" : [ "aeiou" ]\n}, contentType=application/json}, {example=<Pet>\n <id>123456</id>\n <Category>\n <id>123456</id>\n <name>string</name>\n </Category>\n <name>doggie</name>\n <photoUrls>string</photoUrls>\n <Tag>\n <id>123456</id>\n <name>string</name>\n </Tag>\n <status>string</status>\n</Pet>, contentType=application/xml}]
|
||||
- examples: [{example={\n "tags" : [ {\n "id" : 123456789,\n "name" : "aeiou"\n } ],\n "id" : 123456789,\n "category" : {\n "id" : 123456789,\n "name" : "aeiou"\n },\n "status" : "aeiou",\n "name" : "doggie",\n "photoUrls" : [ "aeiou" ]\n}, contentType=application/json}, {example=<Pet>\n <id>123456</id>\n <Category>\n <id>123456</id>\n <name>string</name>\n </Category>\n <name>doggie</name>\n <photoUrls>string</photoUrls>\n <Tag>\n <id>123456</id>\n <name>string</name>\n </Tag>\n <status>string</status>\n</Pet>, contentType=application/xml}]
|
||||
|
||||
:param: petId (path) ID of pet that needs to be fetched
|
||||
|
||||
:returns: Promise<Response<Pet>>
|
||||
*/
|
||||
func getPetById(#petId: Int) -> RequestBuilder<Pet> {
|
||||
var path = "/pet/{petId}"
|
||||
path = path.stringByReplacingOccurrencesOfString("{petId}", withString: "\(petId)", options: .LiteralSearch, range: nil)
|
||||
let url = PetstoreClientAPI.basePath + path
|
||||
|
||||
let nillableParameters: [String:AnyObject?] = [:]
|
||||
let parameters = APIHelper.rejectNil(nillableParameters)
|
||||
|
||||
let requestBuilder: RequestBuilder<Pet>.Type = PetstoreClientAPI.requestBuilderFactory.getBuilder()
|
||||
|
||||
return requestBuilder(method: "GET", URLString: url, parameters: parameters, isBody: true)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Updates a pet in the store with form data
|
||||
|
||||
- POST /pet/{petId}
|
||||
-
|
||||
- authMethods: [com.wordnik.swagger.codegen.CodegenSecurity@795525a1]
|
||||
|
||||
:param: petId (path) ID of pet that needs to be updated
|
||||
:param: name (form) Updated name of the pet
|
||||
:param: status (form) Updated status of the pet
|
||||
|
||||
:returns: Promise<Response<Void>>
|
||||
*/
|
||||
func updatePetWithForm(#petId: String, name: String?, status: String?) -> RequestBuilder<Void> {
|
||||
var path = "/pet/{petId}"
|
||||
path = path.stringByReplacingOccurrencesOfString("{petId}", withString: "\(petId)", options: .LiteralSearch, range: nil)
|
||||
let url = PetstoreClientAPI.basePath + path
|
||||
|
||||
let nillableParameters: [String:AnyObject?] = [:]
|
||||
let parameters = APIHelper.rejectNil(nillableParameters)
|
||||
|
||||
let requestBuilder: RequestBuilder<Void>.Type = PetstoreClientAPI.requestBuilderFactory.getBuilder()
|
||||
|
||||
return requestBuilder(method: "POST", URLString: url, parameters: parameters, isBody: true)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Deletes a pet
|
||||
|
||||
- DELETE /pet/{petId}
|
||||
-
|
||||
- authMethods: [com.wordnik.swagger.codegen.CodegenSecurity@4519ab42]
|
||||
|
||||
:param: petId (path) Pet id to delete
|
||||
|
||||
:returns: Promise<Response<Void>>
|
||||
*/
|
||||
func deletePet(#petId: Int) -> RequestBuilder<Void> {
|
||||
var path = "/pet/{petId}"
|
||||
path = path.stringByReplacingOccurrencesOfString("{petId}", withString: "\(petId)", options: .LiteralSearch, range: nil)
|
||||
let url = PetstoreClientAPI.basePath + path
|
||||
|
||||
let nillableParameters: [String:AnyObject?] = [:]
|
||||
let parameters = APIHelper.rejectNil(nillableParameters)
|
||||
|
||||
let requestBuilder: RequestBuilder<Void>.Type = PetstoreClientAPI.requestBuilderFactory.getBuilder()
|
||||
|
||||
return requestBuilder(method: "DELETE", URLString: url, parameters: parameters, isBody: true)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
uploads an image
|
||||
|
||||
- POST /pet/{petId}/uploadImage
|
||||
-
|
||||
- authMethods: [com.wordnik.swagger.codegen.CodegenSecurity@183a9d7f]
|
||||
|
||||
:param: petId (path) ID of pet to update
|
||||
:param: additionalMetadata (form) Additional data to pass to server
|
||||
:param: file (form) file to upload
|
||||
|
||||
:returns: Promise<Response<Void>>
|
||||
*/
|
||||
func uploadFile(#petId: Int, additionalMetadata: String?, file: NSData?) -> RequestBuilder<Void> {
|
||||
var path = "/pet/{petId}/uploadImage"
|
||||
path = path.stringByReplacingOccurrencesOfString("{petId}", withString: "\(petId)", options: .LiteralSearch, range: nil)
|
||||
let url = PetstoreClientAPI.basePath + path
|
||||
|
||||
let nillableParameters: [String:AnyObject?] = [:]
|
||||
let parameters = APIHelper.rejectNil(nillableParameters)
|
||||
|
||||
let requestBuilder: RequestBuilder<Void>.Type = PetstoreClientAPI.requestBuilderFactory.getBuilder()
|
||||
|
||||
return requestBuilder(method: "POST", URLString: url, parameters: parameters, isBody: true)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,114 @@
|
||||
//
|
||||
// StoreAPI.swift
|
||||
//
|
||||
// Generated by swagger-codegen
|
||||
// https://github.com/swagger-api/swagger-codegen
|
||||
//
|
||||
|
||||
import Alamofire
|
||||
import PromiseKit
|
||||
|
||||
extension PetstoreClientAPI {
|
||||
|
||||
class StoreAPI: APIBase {
|
||||
|
||||
/**
|
||||
|
||||
Returns pet inventories by status
|
||||
|
||||
- GET /store/inventory
|
||||
- Returns a map of status codes to quantities
|
||||
- authMethods: [com.wordnik.swagger.codegen.CodegenSecurity@303a0946]
|
||||
- examples: [{example={\n "key" : 123\n}, contentType=application/json}, {example=not implemented com.wordnik.swagger.models.properties.MapProperty@2e030ea9, contentType=application/xml}]
|
||||
- examples: [{example={\n "key" : 123\n}, contentType=application/json}, {example=not implemented com.wordnik.swagger.models.properties.MapProperty@2e030ea9, contentType=application/xml}]
|
||||
|
||||
:returns: Promise<Response<[String:Int]>>
|
||||
*/
|
||||
func getInventory() -> RequestBuilder<[String:Int]> {
|
||||
let path = "/store/inventory"
|
||||
let url = PetstoreClientAPI.basePath + path
|
||||
|
||||
let nillableParameters: [String:AnyObject?] = [:]
|
||||
let parameters = APIHelper.rejectNil(nillableParameters)
|
||||
|
||||
let requestBuilder: RequestBuilder<[String:Int]>.Type = PetstoreClientAPI.requestBuilderFactory.getBuilder()
|
||||
|
||||
return requestBuilder(method: "GET", URLString: url, parameters: parameters, isBody: true)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Place an order for a pet
|
||||
|
||||
- POST /store/order
|
||||
-
|
||||
- examples: [{example={\n "id" : 123456789,\n "petId" : 123456789,\n "complete" : true,\n "status" : "aeiou",\n "quantity" : 123,\n "shipDate" : "2015-05-27T03:28:27.397+0000"\n}, contentType=application/json}, {example=<Order>\n <id>123456</id>\n <petId>123456</petId>\n <quantity>0</quantity>\n <shipDate>2015-05-27T12:28:27.400Z</shipDate>\n <status>string</status>\n <complete>true</complete>\n</Order>, contentType=application/xml}]
|
||||
- examples: [{example={\n "id" : 123456789,\n "petId" : 123456789,\n "complete" : true,\n "status" : "aeiou",\n "quantity" : 123,\n "shipDate" : "2015-05-27T03:28:27.397+0000"\n}, contentType=application/json}, {example=<Order>\n <id>123456</id>\n <petId>123456</petId>\n <quantity>0</quantity>\n <shipDate>2015-05-27T12:28:27.400Z</shipDate>\n <status>string</status>\n <complete>true</complete>\n</Order>, contentType=application/xml}]
|
||||
|
||||
:param: body (body) order placed for purchasing the pet
|
||||
|
||||
:returns: Promise<Response<Order>>
|
||||
*/
|
||||
func placeOrder(#body: Order?) -> RequestBuilder<Order> {
|
||||
let path = "/store/order"
|
||||
let url = PetstoreClientAPI.basePath + path
|
||||
|
||||
let parameters = body?.encodeToJSON() as? [String:AnyObject]
|
||||
|
||||
let requestBuilder: RequestBuilder<Order>.Type = PetstoreClientAPI.requestBuilderFactory.getBuilder()
|
||||
|
||||
return requestBuilder(method: "POST", URLString: url, parameters: parameters, isBody: true)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Find purchase order by ID
|
||||
|
||||
- GET /store/order/{orderId}
|
||||
- For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions
|
||||
- examples: [{example={\n "id" : 123456789,\n "petId" : 123456789,\n "complete" : true,\n "status" : "aeiou",\n "quantity" : 123,\n "shipDate" : "2015-05-27T03:28:27.402+0000"\n}, contentType=application/json}, {example=<Order>\n <id>123456</id>\n <petId>123456</petId>\n <quantity>0</quantity>\n <shipDate>2015-05-27T12:28:27.402Z</shipDate>\n <status>string</status>\n <complete>true</complete>\n</Order>, contentType=application/xml}]
|
||||
- examples: [{example={\n "id" : 123456789,\n "petId" : 123456789,\n "complete" : true,\n "status" : "aeiou",\n "quantity" : 123,\n "shipDate" : "2015-05-27T03:28:27.402+0000"\n}, contentType=application/json}, {example=<Order>\n <id>123456</id>\n <petId>123456</petId>\n <quantity>0</quantity>\n <shipDate>2015-05-27T12:28:27.402Z</shipDate>\n <status>string</status>\n <complete>true</complete>\n</Order>, contentType=application/xml}]
|
||||
|
||||
:param: orderId (path) ID of pet that needs to be fetched
|
||||
|
||||
:returns: Promise<Response<Order>>
|
||||
*/
|
||||
func getOrderById(#orderId: String) -> RequestBuilder<Order> {
|
||||
var path = "/store/order/{orderId}"
|
||||
path = path.stringByReplacingOccurrencesOfString("{orderId}", withString: "\(orderId)", options: .LiteralSearch, range: nil)
|
||||
let url = PetstoreClientAPI.basePath + path
|
||||
|
||||
let nillableParameters: [String:AnyObject?] = [:]
|
||||
let parameters = APIHelper.rejectNil(nillableParameters)
|
||||
|
||||
let requestBuilder: RequestBuilder<Order>.Type = PetstoreClientAPI.requestBuilderFactory.getBuilder()
|
||||
|
||||
return requestBuilder(method: "GET", URLString: url, parameters: parameters, isBody: true)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Delete purchase order by ID
|
||||
|
||||
- DELETE /store/order/{orderId}
|
||||
- For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
|
||||
|
||||
:param: orderId (path) ID of the order that needs to be deleted
|
||||
|
||||
:returns: Promise<Response<Void>>
|
||||
*/
|
||||
func deleteOrder(#orderId: String) -> RequestBuilder<Void> {
|
||||
var path = "/store/order/{orderId}"
|
||||
path = path.stringByReplacingOccurrencesOfString("{orderId}", withString: "\(orderId)", options: .LiteralSearch, range: nil)
|
||||
let url = PetstoreClientAPI.basePath + path
|
||||
|
||||
let nillableParameters: [String:AnyObject?] = [:]
|
||||
let parameters = APIHelper.rejectNil(nillableParameters)
|
||||
|
||||
let requestBuilder: RequestBuilder<Void>.Type = PetstoreClientAPI.requestBuilderFactory.getBuilder()
|
||||
|
||||
return requestBuilder(method: "DELETE", URLString: url, parameters: parameters, isBody: true)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,206 @@
|
||||
//
|
||||
// UserAPI.swift
|
||||
//
|
||||
// Generated by swagger-codegen
|
||||
// https://github.com/swagger-api/swagger-codegen
|
||||
//
|
||||
|
||||
import Alamofire
|
||||
import PromiseKit
|
||||
|
||||
extension PetstoreClientAPI {
|
||||
|
||||
class UserAPI: APIBase {
|
||||
|
||||
/**
|
||||
|
||||
Create user
|
||||
|
||||
- POST /user
|
||||
- This can only be done by the logged in user.
|
||||
|
||||
:param: body (body) Created user object
|
||||
|
||||
:returns: Promise<Response<Void>>
|
||||
*/
|
||||
func createUser(#body: User?) -> RequestBuilder<Void> {
|
||||
let path = "/user"
|
||||
let url = PetstoreClientAPI.basePath + path
|
||||
|
||||
let parameters = body?.encodeToJSON() as? [String:AnyObject]
|
||||
|
||||
let requestBuilder: RequestBuilder<Void>.Type = PetstoreClientAPI.requestBuilderFactory.getBuilder()
|
||||
|
||||
return requestBuilder(method: "POST", URLString: url, parameters: parameters, isBody: true)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Creates list of users with given input array
|
||||
|
||||
- POST /user/createWithArray
|
||||
-
|
||||
|
||||
:param: body (body) List of user object
|
||||
|
||||
:returns: Promise<Response<Void>>
|
||||
*/
|
||||
func createUsersWithArrayInput(#body: [User]?) -> RequestBuilder<Void> {
|
||||
let path = "/user/createWithArray"
|
||||
let url = PetstoreClientAPI.basePath + path
|
||||
|
||||
let parameters = body?.encodeToJSON() as? [String:AnyObject]
|
||||
|
||||
let requestBuilder: RequestBuilder<Void>.Type = PetstoreClientAPI.requestBuilderFactory.getBuilder()
|
||||
|
||||
return requestBuilder(method: "POST", URLString: url, parameters: parameters, isBody: true)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Creates list of users with given input array
|
||||
|
||||
- POST /user/createWithList
|
||||
-
|
||||
|
||||
:param: body (body) List of user object
|
||||
|
||||
:returns: Promise<Response<Void>>
|
||||
*/
|
||||
func createUsersWithListInput(#body: [User]?) -> RequestBuilder<Void> {
|
||||
let path = "/user/createWithList"
|
||||
let url = PetstoreClientAPI.basePath + path
|
||||
|
||||
let parameters = body?.encodeToJSON() as? [String:AnyObject]
|
||||
|
||||
let requestBuilder: RequestBuilder<Void>.Type = PetstoreClientAPI.requestBuilderFactory.getBuilder()
|
||||
|
||||
return requestBuilder(method: "POST", URLString: url, parameters: parameters, isBody: true)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Logs user into the system
|
||||
|
||||
- GET /user/login
|
||||
-
|
||||
- examples: [{example="aeiou", contentType=application/json}, {example=string, contentType=application/xml}]
|
||||
- examples: [{example="aeiou", contentType=application/json}, {example=string, contentType=application/xml}]
|
||||
|
||||
:param: username (query) The user name for login
|
||||
:param: password (query) The password for login in clear text
|
||||
|
||||
:returns: Promise<Response<String>>
|
||||
*/
|
||||
func loginUser(#username: String?, password: String?) -> RequestBuilder<String> {
|
||||
let path = "/user/login"
|
||||
let url = PetstoreClientAPI.basePath + path
|
||||
|
||||
let nillableParameters: [String:AnyObject?] = [
|
||||
"username": username,
|
||||
"password": password
|
||||
]
|
||||
let parameters = APIHelper.rejectNil(nillableParameters)
|
||||
|
||||
let requestBuilder: RequestBuilder<String>.Type = PetstoreClientAPI.requestBuilderFactory.getBuilder()
|
||||
|
||||
return requestBuilder(method: "GET", URLString: url, parameters: parameters, isBody: false)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Logs out current logged in user session
|
||||
|
||||
- GET /user/logout
|
||||
-
|
||||
|
||||
:returns: Promise<Response<Void>>
|
||||
*/
|
||||
func logoutUser() -> RequestBuilder<Void> {
|
||||
let path = "/user/logout"
|
||||
let url = PetstoreClientAPI.basePath + path
|
||||
|
||||
let nillableParameters: [String:AnyObject?] = [:]
|
||||
let parameters = APIHelper.rejectNil(nillableParameters)
|
||||
|
||||
let requestBuilder: RequestBuilder<Void>.Type = PetstoreClientAPI.requestBuilderFactory.getBuilder()
|
||||
|
||||
return requestBuilder(method: "GET", URLString: url, parameters: parameters, isBody: true)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Get user by user name
|
||||
|
||||
- GET /user/{username}
|
||||
-
|
||||
- examples: [{example={\n "id" : 123456789,\n "lastName" : "aeiou",\n "phone" : "aeiou",\n "username" : "aeiou",\n "email" : "aeiou",\n "userStatus" : 123,\n "firstName" : "aeiou",\n "password" : "aeiou"\n}, contentType=application/json}, {example=<User>\n <id>123456</id>\n <username>string</username>\n <firstName>string</firstName>\n <lastName>string</lastName>\n <email>string</email>\n <password>string</password>\n <phone>string</phone>\n <userStatus>0</userStatus>\n</User>, contentType=application/xml}]
|
||||
- examples: [{example={\n "id" : 123456789,\n "lastName" : "aeiou",\n "phone" : "aeiou",\n "username" : "aeiou",\n "email" : "aeiou",\n "userStatus" : 123,\n "firstName" : "aeiou",\n "password" : "aeiou"\n}, contentType=application/json}, {example=<User>\n <id>123456</id>\n <username>string</username>\n <firstName>string</firstName>\n <lastName>string</lastName>\n <email>string</email>\n <password>string</password>\n <phone>string</phone>\n <userStatus>0</userStatus>\n</User>, contentType=application/xml}]
|
||||
|
||||
:param: username (path) The name that needs to be fetched. Use user1 for testing.
|
||||
|
||||
:returns: Promise<Response<User>>
|
||||
*/
|
||||
func getUserByName(#username: String) -> RequestBuilder<User> {
|
||||
var path = "/user/{username}"
|
||||
path = path.stringByReplacingOccurrencesOfString("{username}", withString: "\(username)", options: .LiteralSearch, range: nil)
|
||||
let url = PetstoreClientAPI.basePath + path
|
||||
|
||||
let nillableParameters: [String:AnyObject?] = [:]
|
||||
let parameters = APIHelper.rejectNil(nillableParameters)
|
||||
|
||||
let requestBuilder: RequestBuilder<User>.Type = PetstoreClientAPI.requestBuilderFactory.getBuilder()
|
||||
|
||||
return requestBuilder(method: "GET", URLString: url, parameters: parameters, isBody: true)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Updated user
|
||||
|
||||
- PUT /user/{username}
|
||||
- This can only be done by the logged in user.
|
||||
|
||||
:param: username (path) name that need to be deleted
|
||||
:param: body (body) Updated user object
|
||||
|
||||
:returns: Promise<Response<Void>>
|
||||
*/
|
||||
func updateUser(#username: String, body: User?) -> RequestBuilder<Void> {
|
||||
var path = "/user/{username}"
|
||||
path = path.stringByReplacingOccurrencesOfString("{username}", withString: "\(username)", options: .LiteralSearch, range: nil)
|
||||
let url = PetstoreClientAPI.basePath + path
|
||||
|
||||
let parameters = body?.encodeToJSON() as? [String:AnyObject]
|
||||
|
||||
let requestBuilder: RequestBuilder<Void>.Type = PetstoreClientAPI.requestBuilderFactory.getBuilder()
|
||||
|
||||
return requestBuilder(method: "PUT", URLString: url, parameters: parameters, isBody: true)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Delete user
|
||||
|
||||
- DELETE /user/{username}
|
||||
- This can only be done by the logged in user.
|
||||
|
||||
:param: username (path) The name that needs to be deleted
|
||||
|
||||
:returns: Promise<Response<Void>>
|
||||
*/
|
||||
func deleteUser(#username: String) -> RequestBuilder<Void> {
|
||||
var path = "/user/{username}"
|
||||
path = path.stringByReplacingOccurrencesOfString("{username}", withString: "\(username)", options: .LiteralSearch, range: nil)
|
||||
let url = PetstoreClientAPI.basePath + path
|
||||
|
||||
let nillableParameters: [String:AnyObject?] = [:]
|
||||
let parameters = APIHelper.rejectNil(nillableParameters)
|
||||
|
||||
let requestBuilder: RequestBuilder<Void>.Type = PetstoreClientAPI.requestBuilderFactory.getBuilder()
|
||||
|
||||
return requestBuilder(method: "DELETE", URLString: url, parameters: parameters, isBody: true)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,80 @@
|
||||
// AlamofireImplementations.swift
|
||||
//
|
||||
// Generated by swagger-codegen
|
||||
// https://github.com/swagger-api/swagger-codegen
|
||||
//
|
||||
|
||||
import Alamofire
|
||||
import PromiseKit
|
||||
|
||||
class AlamofireRequestBuilderFactory: RequestBuilderFactory {
|
||||
func getBuilder<T>() -> RequestBuilder<T>.Type {
|
||||
return AlamofireRequestBuilder<T>.self
|
||||
}
|
||||
}
|
||||
|
||||
// Store manager to retain its reference
|
||||
private var managerStore: [String: Alamofire.Manager] = [:]
|
||||
|
||||
class AlamofireRequestBuilder<T>: RequestBuilder<T> {
|
||||
required init(method: String, URLString: String, parameters: [String : AnyObject]?, isBody: Bool) {
|
||||
super.init(method: method, URLString: URLString, parameters: parameters, isBody: isBody)
|
||||
}
|
||||
|
||||
override func execute() -> Promise<Response<T>> {
|
||||
let managerId = NSUUID().UUIDString
|
||||
// Create a new manager for each request to customize its request header
|
||||
let configuration = NSURLSessionConfiguration.defaultSessionConfiguration()
|
||||
configuration.HTTPAdditionalHeaders = buildHeaders()
|
||||
let manager = Alamofire.Manager(configuration: configuration)
|
||||
managerStore[managerId] = manager
|
||||
|
||||
let encoding = isBody ? Alamofire.ParameterEncoding.JSON : Alamofire.ParameterEncoding.URL
|
||||
let request = manager.request(Alamofire.Method(rawValue: method)!, URLString, parameters: parameters, encoding: encoding)
|
||||
if let credential = self.credential {
|
||||
request.authenticate(usingCredential: credential)
|
||||
}
|
||||
|
||||
let defer = Promise<Response<T>>.defer()
|
||||
request.responseJSON(options: .AllowFragments) { (req, res, json, error) in
|
||||
managerStore.removeValueForKey(managerId)
|
||||
|
||||
if let error = error {
|
||||
defer.reject(error)
|
||||
return
|
||||
}
|
||||
if res!.statusCode >= 400 {
|
||||
//TODO: Add error entity
|
||||
let userInfo: [NSObject : AnyObject] = (json != nil) ? ["data": json!] : [:]
|
||||
let error = NSError(domain: res!.URL!.URLString, code: res!.statusCode, userInfo: userInfo)
|
||||
defer.reject(error)
|
||||
return
|
||||
}
|
||||
|
||||
if () is T {
|
||||
let response = Response(response: res!, body: () as! T)
|
||||
defer.fulfill(response)
|
||||
return
|
||||
}
|
||||
if let json: AnyObject = json {
|
||||
let body = Decoders.decode(clazz: T.self, source: json)
|
||||
let response = Response(response: res!, body: body)
|
||||
defer.fulfill(response)
|
||||
return
|
||||
}
|
||||
|
||||
defer.reject(NSError(domain: "localhost", code: 500, userInfo: ["reason": "unreacheable code"]))
|
||||
}
|
||||
return defer.promise
|
||||
}
|
||||
|
||||
private func buildHeaders() -> [String: AnyObject] {
|
||||
var httpHeaders = Manager.defaultHTTPHeaders
|
||||
for (key, value) in self.headers {
|
||||
httpHeaders[key] = value
|
||||
}
|
||||
return httpHeaders
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,65 @@
|
||||
// Extensions.swift
|
||||
//
|
||||
// Generated by swagger-codegen
|
||||
// https://github.com/swagger-api/swagger-codegen
|
||||
//
|
||||
|
||||
import Alamofire
|
||||
import PromiseKit
|
||||
|
||||
extension Bool: JSONEncodable {
|
||||
func encodeToJSON() -> AnyObject { return self }
|
||||
}
|
||||
|
||||
extension Float: JSONEncodable {
|
||||
func encodeToJSON() -> AnyObject { return self }
|
||||
}
|
||||
|
||||
extension Int: JSONEncodable {
|
||||
func encodeToJSON() -> AnyObject { return self }
|
||||
}
|
||||
|
||||
extension Double: JSONEncodable {
|
||||
func encodeToJSON() -> AnyObject { return self }
|
||||
}
|
||||
|
||||
extension String: JSONEncodable {
|
||||
func encodeToJSON() -> AnyObject { return self }
|
||||
}
|
||||
|
||||
private func encodeIfPossible<T>(object: T) -> AnyObject {
|
||||
if object is JSONEncodable {
|
||||
return (object as! JSONEncodable).encodeToJSON()
|
||||
} else {
|
||||
return object as! AnyObject
|
||||
}
|
||||
}
|
||||
|
||||
extension Array: JSONEncodable {
|
||||
func encodeToJSON() -> AnyObject {
|
||||
return self.map(encodeIfPossible)
|
||||
}
|
||||
}
|
||||
|
||||
extension Dictionary: JSONEncodable {
|
||||
func encodeToJSON() -> AnyObject {
|
||||
var dictionary = [NSObject:AnyObject]()
|
||||
for (key, value) in self {
|
||||
dictionary[key as! NSObject] = encodeIfPossible(value)
|
||||
}
|
||||
return dictionary
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private let dateFormatter: NSDateFormatter = {
|
||||
let dateFormatter = NSDateFormatter()
|
||||
dateFormatter.dateFormat = "yyyy-MM-dd"
|
||||
return dateFormatter
|
||||
}()
|
||||
|
||||
extension NSDate: JSONEncodable {
|
||||
func encodeToJSON() -> AnyObject {
|
||||
return dateFormatter.stringFromDate(self)
|
||||
}
|
||||
}
|
@ -0,0 +1,185 @@
|
||||
// Models.swift
|
||||
//
|
||||
// Generated by swagger-codegen
|
||||
// https://github.com/swagger-api/swagger-codegen
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
protocol JSONEncodable {
|
||||
func encodeToJSON() -> AnyObject
|
||||
}
|
||||
|
||||
class Response<T> {
|
||||
let statusCode: Int
|
||||
let header: [String: String]
|
||||
let body: T
|
||||
|
||||
init(statusCode: Int, header: [String: String], body: T) {
|
||||
self.statusCode = statusCode
|
||||
self.header = header
|
||||
self.body = body
|
||||
}
|
||||
|
||||
convenience init(response: NSHTTPURLResponse, body: T) {
|
||||
let rawHeader = response.allHeaderFields
|
||||
var header = [String:String]()
|
||||
for (key, value) in rawHeader {
|
||||
header[key as! String] = value as? String
|
||||
}
|
||||
self.init(statusCode: response.statusCode, header: header, body: body)
|
||||
}
|
||||
}
|
||||
|
||||
private var once = dispatch_once_t()
|
||||
class Decoders {
|
||||
static private var decoders = Dictionary<String, ((AnyObject) -> AnyObject)>()
|
||||
|
||||
static func addDecoder<T>(#clazz: T.Type, decoder: ((AnyObject) -> T)) {
|
||||
let key = "\(T.self)"
|
||||
decoders[key] = { decoder($0) as! AnyObject }
|
||||
}
|
||||
|
||||
static func decode<T>(#clazz: [T].Type, source: AnyObject) -> [T] {
|
||||
let array = source as! [AnyObject]
|
||||
return array.map { Decoders.decode(clazz: T.self, source: $0) }
|
||||
}
|
||||
|
||||
static func decode<T, Key: Hashable>(#clazz: [Key:T].Type, source: AnyObject) -> [Key:T] {
|
||||
let sourceDictinoary = source as! [Key: AnyObject]
|
||||
var dictionary = [Key:T]()
|
||||
for (key, value) in sourceDictinoary {
|
||||
dictionary[key] = Decoders.decode(clazz: T.self, source: value)
|
||||
}
|
||||
return dictionary
|
||||
}
|
||||
|
||||
static func decode<T>(#clazz: T.Type, source: AnyObject) -> T {
|
||||
initialize()
|
||||
if source is T {
|
||||
return source as! T
|
||||
}
|
||||
|
||||
let key = "\(T.self)"
|
||||
if let decoder = decoders[key] {
|
||||
return decoder(source) as! T
|
||||
} else {
|
||||
fatalError("Source \(source) is not convertible to type \(clazz): Maybe swagger file is insufficient")
|
||||
}
|
||||
}
|
||||
|
||||
static func decodeOptional<T>(#clazz: T.Type, source: AnyObject?) -> T? {
|
||||
if source is NSNull {
|
||||
return nil
|
||||
}
|
||||
return source.map { (source: AnyObject) -> T in
|
||||
Decoders.decode(clazz: clazz, source: source)
|
||||
}
|
||||
}
|
||||
|
||||
static func decodeOptional<T>(#clazz: [T].Type, source: AnyObject?) -> [T]? {
|
||||
if source is NSNull {
|
||||
return nil
|
||||
}
|
||||
return source.map { (someSource: AnyObject) -> [T] in
|
||||
Decoders.decode(clazz: clazz, source: someSource)
|
||||
}
|
||||
}
|
||||
|
||||
static func decodeOptional<T, Key: Hashable>(#clazz: [Key:T].Type, source: AnyObject?) -> [Key:T]? {
|
||||
if source is NSNull {
|
||||
return nil
|
||||
}
|
||||
return source.map { (someSource: AnyObject) -> [Key:T] in
|
||||
Decoders.decode(clazz: clazz, source: someSource)
|
||||
}
|
||||
}
|
||||
|
||||
static private func initialize() {
|
||||
dispatch_once(&once) {
|
||||
let formatters = [
|
||||
"yyyy-MM-dd",
|
||||
"yyyy-MM-dd'T'HH:mm:ssZZZZZ",
|
||||
"yyyy-MM-dd'T'HH:mm:ss'Z'"
|
||||
].map { (format: String) -> NSDateFormatter in
|
||||
let formatter = NSDateFormatter()
|
||||
formatter.dateFormat = format
|
||||
return formatter
|
||||
}
|
||||
// Decoder for NSDate
|
||||
Decoders.addDecoder(clazz: NSDate.self) { (source: AnyObject) -> NSDate in
|
||||
let sourceString = source as! String
|
||||
for formatter in formatters {
|
||||
if let date = formatter.dateFromString(sourceString) {
|
||||
return date
|
||||
}
|
||||
}
|
||||
fatalError("formatter failed to parse \(sourceString)")
|
||||
}
|
||||
|
||||
// Decoder for User
|
||||
Decoders.addDecoder(clazz: User.self) { (source: AnyObject) -> User in
|
||||
let sourceDictionary = source as! [NSObject:AnyObject]
|
||||
var instance = User()
|
||||
instance.id = Decoders.decodeOptional(clazz: Int.self, source: sourceDictionary["id"])
|
||||
instance.username = Decoders.decodeOptional(clazz: String.self, source: sourceDictionary["username"])
|
||||
instance.firstName = Decoders.decodeOptional(clazz: String.self, source: sourceDictionary["firstName"])
|
||||
instance.lastName = Decoders.decodeOptional(clazz: String.self, source: sourceDictionary["lastName"])
|
||||
instance.email = Decoders.decodeOptional(clazz: String.self, source: sourceDictionary["email"])
|
||||
instance.password = Decoders.decodeOptional(clazz: String.self, source: sourceDictionary["password"])
|
||||
instance.phone = Decoders.decodeOptional(clazz: String.self, source: sourceDictionary["phone"])
|
||||
instance.userStatus = Decoders.decodeOptional(clazz: Int.self, source: sourceDictionary["userStatus"])
|
||||
return instance
|
||||
}
|
||||
|
||||
|
||||
// Decoder for Category
|
||||
Decoders.addDecoder(clazz: Category.self) { (source: AnyObject) -> Category in
|
||||
let sourceDictionary = source as! [NSObject:AnyObject]
|
||||
var instance = Category()
|
||||
instance.id = Decoders.decodeOptional(clazz: Int.self, source: sourceDictionary["id"])
|
||||
instance.name = Decoders.decodeOptional(clazz: String.self, source: sourceDictionary["name"])
|
||||
return instance
|
||||
}
|
||||
|
||||
|
||||
// Decoder for Pet
|
||||
Decoders.addDecoder(clazz: Pet.self) { (source: AnyObject) -> Pet in
|
||||
let sourceDictionary = source as! [NSObject:AnyObject]
|
||||
var instance = Pet()
|
||||
instance.id = Decoders.decodeOptional(clazz: Int.self, source: sourceDictionary["id"])
|
||||
instance.category = Decoders.decodeOptional(clazz: Category.self, source: sourceDictionary["category"])
|
||||
instance.name = Decoders.decode(clazz: String.self, source: sourceDictionary["name"]!)
|
||||
instance.photoUrls = Decoders.decode(clazz: Array.self, source: sourceDictionary["photoUrls"]!)
|
||||
instance.tags = Decoders.decodeOptional(clazz: Array.self, source: sourceDictionary["tags"])
|
||||
instance.status = (sourceDictionary["status"] as? String).map { Pet.Status(rawValue: $0)! }
|
||||
return instance
|
||||
}
|
||||
|
||||
|
||||
// Decoder for Tag
|
||||
Decoders.addDecoder(clazz: Tag.self) { (source: AnyObject) -> Tag in
|
||||
let sourceDictionary = source as! [NSObject:AnyObject]
|
||||
var instance = Tag()
|
||||
instance.id = Decoders.decodeOptional(clazz: Int.self, source: sourceDictionary["id"])
|
||||
instance.name = Decoders.decodeOptional(clazz: String.self, source: sourceDictionary["name"])
|
||||
return instance
|
||||
}
|
||||
|
||||
|
||||
// Decoder for Order
|
||||
Decoders.addDecoder(clazz: Order.self) { (source: AnyObject) -> Order in
|
||||
let sourceDictionary = source as! [NSObject:AnyObject]
|
||||
var instance = Order()
|
||||
instance.id = Decoders.decodeOptional(clazz: Int.self, source: sourceDictionary["id"])
|
||||
instance.petId = Decoders.decodeOptional(clazz: Int.self, source: sourceDictionary["petId"])
|
||||
instance.quantity = Decoders.decodeOptional(clazz: Int.self, source: sourceDictionary["quantity"])
|
||||
instance.shipDate = Decoders.decodeOptional(clazz: NSDate.self, source: sourceDictionary["shipDate"])
|
||||
instance.status = (sourceDictionary["status"] as? String).map { Order.Status(rawValue: $0)! }
|
||||
instance.complete = Decoders.decodeOptional(clazz: Bool.self, source: sourceDictionary["complete"])
|
||||
return instance
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
//
|
||||
// Category.swift
|
||||
//
|
||||
// Generated by swagger-codegen
|
||||
// https://github.com/swagger-api/swagger-codegen
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
|
||||
class Category: JSONEncodable {
|
||||
|
||||
var id: Int?
|
||||
var name: String?
|
||||
|
||||
|
||||
// MARK: JSONEncodable
|
||||
func encodeToJSON() -> AnyObject {
|
||||
var nillableDictionary = [String:AnyObject?]()
|
||||
nillableDictionary["id"] = self.id
|
||||
nillableDictionary["name"] = self.name
|
||||
let dictionary: [String:AnyObject] = APIHelper.rejectNil(nillableDictionary) ?? [:]
|
||||
return dictionary
|
||||
}
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
//
|
||||
// Order.swift
|
||||
//
|
||||
// Generated by swagger-codegen
|
||||
// https://github.com/swagger-api/swagger-codegen
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
|
||||
class Order: JSONEncodable {
|
||||
|
||||
enum Status: String {
|
||||
case Placed = "placed"
|
||||
case Approved = "approved"
|
||||
case Delivered = "delivered"
|
||||
}
|
||||
|
||||
var id: Int?
|
||||
var petId: Int?
|
||||
var quantity: Int?
|
||||
var shipDate: NSDate?
|
||||
/** Order Status */
|
||||
var status: Status?
|
||||
var complete: Bool?
|
||||
|
||||
|
||||
// MARK: JSONEncodable
|
||||
func encodeToJSON() -> AnyObject {
|
||||
var nillableDictionary = [String:AnyObject?]()
|
||||
nillableDictionary["id"] = self.id
|
||||
nillableDictionary["petId"] = self.petId
|
||||
nillableDictionary["quantity"] = self.quantity
|
||||
nillableDictionary["shipDate"] = self.shipDate?.encodeToJSON()
|
||||
nillableDictionary["status"] = self.status?.rawValue
|
||||
nillableDictionary["complete"] = self.complete
|
||||
let dictionary: [String:AnyObject] = APIHelper.rejectNil(nillableDictionary) ?? [:]
|
||||
return dictionary
|
||||
}
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
//
|
||||
// Pet.swift
|
||||
//
|
||||
// Generated by swagger-codegen
|
||||
// https://github.com/swagger-api/swagger-codegen
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
|
||||
class Pet: JSONEncodable {
|
||||
|
||||
enum Status: String {
|
||||
case Available = "available"
|
||||
case Pending = "pending"
|
||||
case Sold = "sold"
|
||||
}
|
||||
|
||||
var id: Int?
|
||||
var category: Category?
|
||||
var name: String!
|
||||
var photoUrls: [String]!
|
||||
var tags: [Tag]?
|
||||
/** pet status in the store */
|
||||
var status: Status?
|
||||
|
||||
|
||||
// MARK: JSONEncodable
|
||||
func encodeToJSON() -> AnyObject {
|
||||
var nillableDictionary = [String:AnyObject?]()
|
||||
nillableDictionary["id"] = self.id
|
||||
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:AnyObject] = APIHelper.rejectNil(nillableDictionary) ?? [:]
|
||||
return dictionary
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
//
|
||||
// Tag.swift
|
||||
//
|
||||
// Generated by swagger-codegen
|
||||
// https://github.com/swagger-api/swagger-codegen
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
|
||||
class Tag: JSONEncodable {
|
||||
|
||||
var id: Int?
|
||||
var name: String?
|
||||
|
||||
|
||||
// MARK: JSONEncodable
|
||||
func encodeToJSON() -> AnyObject {
|
||||
var nillableDictionary = [String:AnyObject?]()
|
||||
nillableDictionary["id"] = self.id
|
||||
nillableDictionary["name"] = self.name
|
||||
let dictionary: [String:AnyObject] = APIHelper.rejectNil(nillableDictionary) ?? [:]
|
||||
return dictionary
|
||||
}
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
//
|
||||
// User.swift
|
||||
//
|
||||
// Generated by swagger-codegen
|
||||
// https://github.com/swagger-api/swagger-codegen
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
|
||||
class User: JSONEncodable {
|
||||
|
||||
var id: Int?
|
||||
var username: String?
|
||||
var firstName: String?
|
||||
var lastName: String?
|
||||
var email: String?
|
||||
var password: String?
|
||||
var phone: String?
|
||||
/** User Status */
|
||||
var userStatus: Int?
|
||||
|
||||
|
||||
// MARK: JSONEncodable
|
||||
func encodeToJSON() -> AnyObject {
|
||||
var nillableDictionary = [String:AnyObject?]()
|
||||
nillableDictionary["id"] = self.id
|
||||
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
|
||||
let dictionary: [String:AnyObject] = APIHelper.rejectNil(nillableDictionary) ?? [:]
|
||||
return dictionary
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user