Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ open class {{classname}}: {{#parent}}{{{parent}}}{{/parent}}{{^parent}}Codable{{
}
{{/additionalPropertiesType}}

{{#hasVars}}
public init({{#vars}}{{name}}: {{{datatypeWithEnum}}}{{^required}}?{{/required}}{{#hasMore}}, {{/hasMore}}{{/vars}}) {
{{#vars}}
self.{{name}} = {{name}}
{{/vars}}
}
{{/hasVars}}

// Encodable protocol methods

public {{#parent}}override {{/parent}}func encode(to encoder: Encoder) throws {
Expand All @@ -79,7 +87,7 @@ open class {{classname}}: {{#parent}}{{{parent}}}{{/parent}}{{^parent}}Codable{{
}

// Decodable protocol methods

public {{#parent}}override {{/parent}}required init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: String.self)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ Pod::Spec.new do |s|
s.homepage = 'https://github.com/swagger-api/swagger-codegen'
s.summary = 'PetstoreClient'
s.source_files = 'PetstoreClient/Classes/**/*.swift'
s.dependency 'Alamofire', '~> 4.5'
s.dependency 'Alamofire', '~> 4.5.0'
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
//
// AnotherfakeAPI.swift
//
// Generated by swagger-codegen
// https://github.com/swagger-api/swagger-codegen
//

import Foundation
import Alamofire



open class AnotherfakeAPI {
/**
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: Error?) -> 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 = JSONEncodingHelper.encodingParameters(forEncodableObject: body)

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)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -327,15 +327,15 @@ open class FakeAPI {
*/
public enum EnumQueryInteger_testEnumParameters: Int {
case _1 = 1
case numberminus2 = -2
case number2 = -2
}

/**
* enum for parameter enumQueryDouble
*/
public enum EnumQueryDouble_testEnumParameters: Double {
case _11 = 1.1
case numberminus12 = -1.2
case number12 = -1.2
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,90 @@ extension UUID: JSONEncodable {
}
}

extension String: CodingKey {

public var stringValue: String {
return self
}

public init?(stringValue: String) {
self.init(stringLiteral: stringValue)
}

public var intValue: Int? {
return nil
}

public init?(intValue: Int) {
return nil
}

}

extension KeyedEncodingContainerProtocol {

public mutating func encodeArray<T>(_ values: [T], forKey key: Self.Key) throws where T : Encodable {
var arrayContainer = nestedUnkeyedContainer(forKey: key)
try arrayContainer.encode(contentsOf: values)
}

public mutating func encodeArrayIfPresent<T>(_ values: [T]?, forKey key: Self.Key) throws where T : Encodable {
if let values = values {
try encodeArray(values, forKey: key)
}
}

public mutating func encodeMap<T>(_ pairs: [Self.Key: T]) throws where T : Encodable {
for (key, value) in pairs {
try encode(value, forKey: key)
}
}

public mutating func encodeMapIfPresent<T>(_ pairs: [Self.Key: T]?) throws where T : Encodable {
if let pairs = pairs {
try encodeMap(pairs)
}
}

}

extension KeyedDecodingContainerProtocol {

public func decodeArray<T>(_ type: T.Type, forKey key: Self.Key) throws -> [T] where T : Decodable {
var tmpArray = [T]()

var nestedContainer = try nestedUnkeyedContainer(forKey: key)
while !nestedContainer.isAtEnd {
let arrayValue = try nestedContainer.decode(T.self)
tmpArray.append(arrayValue)
}

return tmpArray
}

public func decodeArrayIfPresent<T>(_ type: T.Type, forKey key: Self.Key) throws -> [T]? where T : Decodable {
var tmpArray: [T]? = nil

if contains(key) {
tmpArray = try decodeArray(T.self, forKey: key)
}

return tmpArray
}

public func decodeMap<T>(_ type: T.Type, excludedKeys: Set<Self.Key>) throws -> [Self.Key: T] where T : Decodable {
var map: [Self.Key : T] = [:]

for key in allKeys {
if !excludedKeys.contains(key) {
let value = try decode(T.self, forKey: key)
map[key] = value
}
}

return map
}

}


Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,35 @@
import Foundation



open class AdditionalPropertiesClass: Codable {

public var mapProperty: [String:String]?
public var mapOfMapProperty: [String:[String:String]]?

public init() {}

public init(mapProperty: [String:String]?, mapOfMapProperty: [String:[String:String]]?) {
self.mapProperty = mapProperty
self.mapOfMapProperty = mapOfMapProperty
}

// Encodable protocol methods

public func encode(to encoder: Encoder) throws {

var container = encoder.container(keyedBy: String.self)

private enum CodingKeys: String, CodingKey {
case mapProperty = "map_property"
case mapOfMapProperty = "map_of_map_property"
try container.encodeIfPresent(mapProperty, forKey: "map_property")
try container.encodeIfPresent(mapOfMapProperty, forKey: "map_of_map_property")
}

// Decodable protocol methods

public required init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: String.self)

mapProperty = try container.decodeIfPresent([String:String].self, forKey: "map_property")
mapOfMapProperty = try container.decodeIfPresent([String:[String:String]].self, forKey: "map_of_map_property")
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,35 @@
import Foundation



open class Animal: Codable {

public var className: String?
public var className: String
public var color: String?

public init() {}

public init(className: String, color: String?) {
self.className = className
self.color = color
}

// Encodable protocol methods

public func encode(to encoder: Encoder) throws {

var container = encoder.container(keyedBy: String.self)

private enum CodingKeys: String, CodingKey {
case className = "className"
case color = "color"
try container.encode(className, forKey: "className")
try container.encodeIfPresent(color, forKey: "color")
}

// Decodable protocol methods

public required init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: String.self)

className = try container.decode(String.self, forKey: "className")
color = try container.decodeIfPresent(String.self, forKey: "color")
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,39 @@
import Foundation



open class ApiResponse: Codable {

public var code: Int?
public var type: String?
public var message: String?

public init() {}

public init(code: Int?, type: String?, message: String?) {
self.code = code
self.type = type
self.message = message
}

// Encodable protocol methods

public func encode(to encoder: Encoder) throws {

var container = encoder.container(keyedBy: String.self)

private enum CodingKeys: String, CodingKey {
case code = "code"
case type = "type"
case message = "message"
try container.encodeIfPresent(code, forKey: "code")
try container.encodeIfPresent(type, forKey: "type")
try container.encodeIfPresent(message, forKey: "message")
}

// Decodable protocol methods

public required init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: String.self)

code = try container.decodeIfPresent(Int.self, forKey: "code")
type = try container.decodeIfPresent(String.self, forKey: "type")
message = try container.decodeIfPresent(String.self, forKey: "message")
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,31 @@
import Foundation



open class ArrayOfArrayOfNumberOnly: Codable {

public var arrayArrayNumber: [[Double]]?

public init() {}

public init(arrayArrayNumber: [[Double]]?) {
self.arrayArrayNumber = arrayArrayNumber
}

// Encodable protocol methods

public func encode(to encoder: Encoder) throws {

var container = encoder.container(keyedBy: String.self)

private enum CodingKeys: String, CodingKey {
case arrayArrayNumber = "ArrayArrayNumber"
try container.encodeArrayIfPresent(arrayArrayNumber, forKey: "ArrayArrayNumber")
}

// Decodable protocol methods

public required init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: String.self)

arrayArrayNumber = try container.decodeArrayIfPresent([Double].self, forKey: "ArrayArrayNumber")
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,31 @@
import Foundation



open class ArrayOfNumberOnly: Codable {

public var arrayNumber: [Double]?

public init() {}

public init(arrayNumber: [Double]?) {
self.arrayNumber = arrayNumber
}

// Encodable protocol methods

public func encode(to encoder: Encoder) throws {

var container = encoder.container(keyedBy: String.self)

private enum CodingKeys: String, CodingKey {
case arrayNumber = "ArrayNumber"
try container.encodeArrayIfPresent(arrayNumber, forKey: "ArrayNumber")
}

// Decodable protocol methods

public required init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: String.self)

arrayNumber = try container.decodeArrayIfPresent(Double.self, forKey: "ArrayNumber")
}
}

Loading