From b716b378c4d9579d25cc31a53d3815ddb8ed94f7 Mon Sep 17 00:00:00 2001 From: ehyche Date: Thu, 12 Oct 2017 05:35:59 -0400 Subject: [PATCH] Swift4: Add additional initializer for initializing model object with properties. (#6642) * Add addiitional files from upstream * Remove mis-added files * Add additional swift4 initializer for initializing model object with properties. This change fixes this issue: https://github.com/swagger-api/swagger-codegen/issues/6641 It adds an additional initializer which allows model objects to be initialized using the properties. For exxample, if we had this model: "ErrorInfo": { "type": "object", "properties": { "code": { "type": "integer", "format": "int32" }, "message": { "type": "string" }, "details": { "type": "array", "items": { "type": "string" } } }, "description": "Example Error object" }, This we generate an initializer for this model object like this: public init(code: Int?, message: String?, details: [String]?) { self.code = code self.message = message self.details = details } * Add hasVars checks around initializers and re-run all scripts to re-generate --- .../src/main/resources/swift4/model.mustache | 8 + .../swift4/default/PetstoreClient.podspec | 2 +- .../Swaggers/APIs/AnotherfakeAPI.swift | 52 ++ .../Classes/Swaggers/APIs/FakeAPI.swift | 4 +- .../Classes/Swaggers/Extensions.swift | 86 +++ .../Models/AdditionalPropertiesClass.swift | 28 +- .../Classes/Swaggers/Models/Animal.swift | 30 +- .../Classes/Swaggers/Models/ApiResponse.swift | 32 +- .../Models/ArrayOfArrayOfNumberOnly.swift | 24 +- .../Swaggers/Models/ArrayOfNumberOnly.swift | 24 +- .../Classes/Swaggers/Models/ArrayTest.swift | 32 +- .../Swaggers/Models/Capitalization.swift | 44 +- .../Classes/Swaggers/Models/Cat.swift | 24 +- .../Classes/Swaggers/Models/Category.swift | 28 +- .../Classes/Swaggers/Models/ClassModel.swift | 24 +- .../Classes/Swaggers/Models/Client.swift | 24 +- .../Classes/Swaggers/Models/Dog.swift | 24 +- .../Classes/Swaggers/Models/EnumArrays.swift | 28 +- .../Classes/Swaggers/Models/EnumTest.swift | 40 +- .../Classes/Swaggers/Models/FormatTest.swift | 80 ++- .../Swaggers/Models/HasOnlyReadOnly.swift | 28 +- .../Classes/Swaggers/Models/List.swift | 24 +- .../Classes/Swaggers/Models/MapTest.swift | 28 +- ...opertiesAndAdditionalPropertiesClass.swift | 32 +- .../Swaggers/Models/Model200Response.swift | 28 +- .../Classes/Swaggers/Models/Name.swift | 38 +- .../Classes/Swaggers/Models/NumberOnly.swift | 24 +- .../Classes/Swaggers/Models/Order.swift | 44 +- .../Swaggers/Models/OuterBoolean.swift | 23 +- .../Swaggers/Models/OuterComposite.swift | 32 +- .../Classes/Swaggers/Models/OuterNumber.swift | 23 +- .../Classes/Swaggers/Models/OuterString.swift | 23 +- .../Classes/Swaggers/Models/Pet.swift | 48 +- .../Swaggers/Models/ReadOnlyFirst.swift | 28 +- .../Classes/Swaggers/Models/Return.swift | 24 +- .../Swaggers/Models/SpecialModelName.swift | 24 +- .../Classes/Swaggers/Models/Tag.swift | 28 +- .../Classes/Swaggers/Models/User.swift | 52 +- .../petstore/swift4/objcCompatible/.gitignore | 63 ++ .../objcCompatible/.swagger-codegen-ignore | 23 + .../objcCompatible/.swagger-codegen/VERSION | 1 + .../petstore/swift4/objcCompatible/Cartfile | 1 + .../objcCompatible/PetstoreClient.podspec | 13 + .../Classes/Swaggers/APIHelper.swift | 65 ++ .../Classes/Swaggers/APIs.swift | 61 ++ .../Swaggers/APIs/AnotherfakeAPI.swift | 52 ++ .../Classes/Swaggers/APIs/FakeAPI.swift | 450 ++++++++++++++ .../APIs/Fake_classname_tags123API.swift | 54 ++ .../Classes/Swaggers/APIs/PetAPI.swift | 588 ++++++++++++++++++ .../Classes/Swaggers/APIs/StoreAPI.swift | 219 +++++++ .../Classes/Swaggers/APIs/UserAPI.swift | 344 ++++++++++ .../Swaggers/AlamofireImplementations.swift | 417 +++++++++++++ .../Classes/Swaggers/CodableHelper.swift | 55 ++ .../Classes/Swaggers/Configuration.swift | 15 + .../Classes/Swaggers/Extensions.swift | 173 ++++++ .../Swaggers/JSONEncodableEncoding.swift | 54 ++ .../Classes/Swaggers/JSONEncodingHelper.swift | 27 + .../Classes/Swaggers/Models.swift | 36 ++ .../Models/AdditionalPropertiesClass.swift | 42 ++ .../Classes/Swaggers/Models/Animal.swift | 42 ++ .../Classes/Swaggers/Models/AnimalFarm.swift | 11 + .../Classes/Swaggers/Models/ApiResponse.swift | 51 ++ .../Models/ArrayOfArrayOfNumberOnly.swift | 38 ++ .../Swaggers/Models/ArrayOfNumberOnly.swift | 38 ++ .../Classes/Swaggers/Models/ArrayTest.swift | 46 ++ .../Swaggers/Models/Capitalization.swift | 59 ++ .../Classes/Swaggers/Models/Cat.swift | 43 ++ .../Classes/Swaggers/Models/Category.swift | 47 ++ .../Classes/Swaggers/Models/ClassModel.swift | 39 ++ .../Classes/Swaggers/Models/Client.swift | 38 ++ .../Classes/Swaggers/Models/Dog.swift | 38 ++ .../Classes/Swaggers/Models/EnumArrays.swift | 50 ++ .../Classes/Swaggers/Models/EnumClass.swift | 16 + .../Classes/Swaggers/Models/EnumTest.swift | 63 ++ .../Classes/Swaggers/Models/FormatTest.swift | 116 ++++ .../Swaggers/Models/HasOnlyReadOnly.swift | 42 ++ .../Classes/Swaggers/Models/List.swift | 38 ++ .../Classes/Swaggers/Models/MapTest.swift | 46 ++ ...opertiesAndAdditionalPropertiesClass.swift | 46 ++ .../Swaggers/Models/Model200Response.swift | 48 ++ .../Classes/Swaggers/Models/Name.swift | 66 ++ .../Classes/Swaggers/Models/NumberOnly.swift | 43 ++ .../Classes/Swaggers/Models/Order.swift | 84 +++ .../Swaggers/Models/OuterBoolean.swift | 32 + .../Swaggers/Models/OuterComposite.swift | 46 ++ .../Classes/Swaggers/Models/OuterEnum.swift | 16 + .../Classes/Swaggers/Models/OuterNumber.swift | 32 + .../Classes/Swaggers/Models/OuterString.swift | 32 + .../Classes/Swaggers/Models/Pet.swift | 69 ++ .../Swaggers/Models/ReadOnlyFirst.swift | 42 ++ .../Classes/Swaggers/Models/Return.swift | 44 ++ .../Swaggers/Models/SpecialModelName.swift | 43 ++ .../Classes/Swaggers/Models/Tag.swift | 47 ++ .../Classes/Swaggers/Models/User.swift | 77 +++ .../swift4/objcCompatible/git_push.sh | 52 ++ .../swift4/promisekit/PetstoreClient.podspec | 2 +- .../Swaggers/APIs/AnotherfakeAPI.swift | 70 +++ .../Classes/Swaggers/APIs/FakeAPI.swift | 4 +- .../Classes/Swaggers/Extensions.swift | 86 +++ .../Models/AdditionalPropertiesClass.swift | 28 +- .../Classes/Swaggers/Models/Animal.swift | 30 +- .../Classes/Swaggers/Models/ApiResponse.swift | 32 +- .../Models/ArrayOfArrayOfNumberOnly.swift | 24 +- .../Swaggers/Models/ArrayOfNumberOnly.swift | 24 +- .../Classes/Swaggers/Models/ArrayTest.swift | 32 +- .../Swaggers/Models/Capitalization.swift | 44 +- .../Classes/Swaggers/Models/Cat.swift | 24 +- .../Classes/Swaggers/Models/Category.swift | 28 +- .../Classes/Swaggers/Models/ClassModel.swift | 24 +- .../Classes/Swaggers/Models/Client.swift | 24 +- .../Classes/Swaggers/Models/Dog.swift | 24 +- .../Classes/Swaggers/Models/EnumArrays.swift | 28 +- .../Classes/Swaggers/Models/EnumTest.swift | 40 +- .../Classes/Swaggers/Models/FormatTest.swift | 80 ++- .../Swaggers/Models/HasOnlyReadOnly.swift | 28 +- .../Classes/Swaggers/Models/List.swift | 24 +- .../Classes/Swaggers/Models/MapTest.swift | 28 +- ...opertiesAndAdditionalPropertiesClass.swift | 32 +- .../Swaggers/Models/Model200Response.swift | 28 +- .../Classes/Swaggers/Models/Name.swift | 38 +- .../Classes/Swaggers/Models/NumberOnly.swift | 24 +- .../Classes/Swaggers/Models/Order.swift | 44 +- .../Swaggers/Models/OuterBoolean.swift | 23 +- .../Swaggers/Models/OuterComposite.swift | 32 +- .../Classes/Swaggers/Models/OuterNumber.swift | 23 +- .../Classes/Swaggers/Models/OuterString.swift | 23 +- .../Classes/Swaggers/Models/Pet.swift | 48 +- .../Swaggers/Models/ReadOnlyFirst.swift | 28 +- .../Classes/Swaggers/Models/Return.swift | 24 +- .../Swaggers/Models/SpecialModelName.swift | 24 +- .../Classes/Swaggers/Models/Tag.swift | 28 +- .../Classes/Swaggers/Models/User.swift | 52 +- .../swift4/rxswift/PetstoreClient.podspec | 2 +- .../Swaggers/APIs/AnotherfakeAPI.swift | 72 +++ .../Classes/Swaggers/APIs/FakeAPI.swift | 4 +- .../Classes/Swaggers/Extensions.swift | 86 +++ .../Models/AdditionalPropertiesClass.swift | 28 +- .../Classes/Swaggers/Models/Animal.swift | 30 +- .../Classes/Swaggers/Models/ApiResponse.swift | 32 +- .../Models/ArrayOfArrayOfNumberOnly.swift | 24 +- .../Swaggers/Models/ArrayOfNumberOnly.swift | 24 +- .../Classes/Swaggers/Models/ArrayTest.swift | 32 +- .../Swaggers/Models/Capitalization.swift | 44 +- .../Classes/Swaggers/Models/Cat.swift | 24 +- .../Classes/Swaggers/Models/Category.swift | 28 +- .../Classes/Swaggers/Models/ClassModel.swift | 24 +- .../Classes/Swaggers/Models/Client.swift | 24 +- .../Classes/Swaggers/Models/Dog.swift | 24 +- .../Classes/Swaggers/Models/EnumArrays.swift | 28 +- .../Classes/Swaggers/Models/EnumTest.swift | 40 +- .../Classes/Swaggers/Models/FormatTest.swift | 80 ++- .../Swaggers/Models/HasOnlyReadOnly.swift | 28 +- .../Classes/Swaggers/Models/List.swift | 24 +- .../Classes/Swaggers/Models/MapTest.swift | 28 +- ...opertiesAndAdditionalPropertiesClass.swift | 32 +- .../Swaggers/Models/Model200Response.swift | 28 +- .../Classes/Swaggers/Models/Name.swift | 38 +- .../Classes/Swaggers/Models/NumberOnly.swift | 24 +- .../Classes/Swaggers/Models/Order.swift | 44 +- .../Swaggers/Models/OuterBoolean.swift | 23 +- .../Swaggers/Models/OuterComposite.swift | 32 +- .../Classes/Swaggers/Models/OuterNumber.swift | 23 +- .../Classes/Swaggers/Models/OuterString.swift | 23 +- .../Classes/Swaggers/Models/Pet.swift | 48 +- .../Swaggers/Models/ReadOnlyFirst.swift | 28 +- .../Classes/Swaggers/Models/Return.swift | 24 +- .../Swaggers/Models/SpecialModelName.swift | 24 +- .../Classes/Swaggers/Models/Tag.swift | 28 +- .../Classes/Swaggers/Models/User.swift | 52 +- .../Swaggers/AlamofireImplementations.swift | 110 ++++ .../Swaggers/Models/AllPrimitives.swift | 27 + .../Classes/Swaggers/Models/ErrorInfo.swift | 6 + .../Swaggers/Models/GetAllModelsResult.swift | 6 + ...ModelWithIntAdditionalPropertiesOnly.swift | 1 + ...ithPropertiesAndAdditionalProperties.swift | 11 + ...elWithStringAdditionalPropertiesOnly.swift | 1 + .../Swaggers/Models/VariableNameTest.swift | 5 + 177 files changed, 7610 insertions(+), 579 deletions(-) create mode 100644 samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/APIs/AnotherfakeAPI.swift create mode 100644 samples/client/petstore/swift4/objcCompatible/.gitignore create mode 100644 samples/client/petstore/swift4/objcCompatible/.swagger-codegen-ignore create mode 100644 samples/client/petstore/swift4/objcCompatible/.swagger-codegen/VERSION create mode 100644 samples/client/petstore/swift4/objcCompatible/Cartfile create mode 100644 samples/client/petstore/swift4/objcCompatible/PetstoreClient.podspec create mode 100644 samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/APIHelper.swift create mode 100644 samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/APIs.swift create mode 100644 samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/APIs/AnotherfakeAPI.swift create mode 100644 samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/APIs/FakeAPI.swift create mode 100644 samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/APIs/Fake_classname_tags123API.swift create mode 100644 samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/APIs/PetAPI.swift create mode 100644 samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/APIs/StoreAPI.swift create mode 100644 samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/APIs/UserAPI.swift create mode 100644 samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/AlamofireImplementations.swift create mode 100644 samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/CodableHelper.swift create mode 100644 samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Configuration.swift create mode 100644 samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Extensions.swift create mode 100644 samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/JSONEncodableEncoding.swift create mode 100644 samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/JSONEncodingHelper.swift create mode 100644 samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models.swift create mode 100644 samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/AdditionalPropertiesClass.swift create mode 100644 samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/Animal.swift create mode 100644 samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/AnimalFarm.swift create mode 100644 samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/ApiResponse.swift create mode 100644 samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/ArrayOfArrayOfNumberOnly.swift create mode 100644 samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/ArrayOfNumberOnly.swift create mode 100644 samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/ArrayTest.swift create mode 100644 samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/Capitalization.swift create mode 100644 samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/Cat.swift create mode 100644 samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/Category.swift create mode 100644 samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/ClassModel.swift create mode 100644 samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/Client.swift create mode 100644 samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/Dog.swift create mode 100644 samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/EnumArrays.swift create mode 100644 samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/EnumClass.swift create mode 100644 samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/EnumTest.swift create mode 100644 samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/FormatTest.swift create mode 100644 samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/HasOnlyReadOnly.swift create mode 100644 samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/List.swift create mode 100644 samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/MapTest.swift create mode 100644 samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/MixedPropertiesAndAdditionalPropertiesClass.swift create mode 100644 samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/Model200Response.swift create mode 100644 samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/Name.swift create mode 100644 samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/NumberOnly.swift create mode 100644 samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/Order.swift create mode 100644 samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/OuterBoolean.swift create mode 100644 samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/OuterComposite.swift create mode 100644 samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/OuterEnum.swift create mode 100644 samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/OuterNumber.swift create mode 100644 samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/OuterString.swift create mode 100644 samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/Pet.swift create mode 100644 samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/ReadOnlyFirst.swift create mode 100644 samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/Return.swift create mode 100644 samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/SpecialModelName.swift create mode 100644 samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/Tag.swift create mode 100644 samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/User.swift create mode 100644 samples/client/petstore/swift4/objcCompatible/git_push.sh create mode 100644 samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/APIs/AnotherfakeAPI.swift create mode 100644 samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/APIs/AnotherfakeAPI.swift diff --git a/modules/swagger-codegen/src/main/resources/swift4/model.mustache b/modules/swagger-codegen/src/main/resources/swift4/model.mustache index 383b229e447..9cbcca50456 100644 --- a/modules/swagger-codegen/src/main/resources/swift4/model.mustache +++ b/modules/swagger-codegen/src/main/resources/swift4/model.mustache @@ -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 { diff --git a/samples/client/petstore/swift4/default/PetstoreClient.podspec b/samples/client/petstore/swift4/default/PetstoreClient.podspec index 2671cdda937..7a28d478bf8 100644 --- a/samples/client/petstore/swift4/default/PetstoreClient.podspec +++ b/samples/client/petstore/swift4/default/PetstoreClient.podspec @@ -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 diff --git a/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/APIs/AnotherfakeAPI.swift b/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/APIs/AnotherfakeAPI.swift new file mode 100644 index 00000000000..9c135bdce3a --- /dev/null +++ b/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/APIs/AnotherfakeAPI.swift @@ -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 + */ + open class func testSpecialTagsWithRequestBuilder(body: Client) -> RequestBuilder { + let path = "/another-fake/dummy" + let URLString = PetstoreClientAPI.basePath + path + let parameters = JSONEncodingHelper.encodingParameters(forEncodableObject: body) + + let url = NSURLComponents(string: URLString) + + + let requestBuilder: RequestBuilder.Type = PetstoreClientAPI.requestBuilderFactory.getBuilder() + + return requestBuilder.init(method: "PATCH", URLString: (url?.string ?? URLString), parameters: parameters, isBody: true) + } + +} diff --git a/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/APIs/FakeAPI.swift b/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/APIs/FakeAPI.swift index b25de2db763..a111760bee0 100644 --- a/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/APIs/FakeAPI.swift +++ b/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/APIs/FakeAPI.swift @@ -327,7 +327,7 @@ open class FakeAPI { */ public enum EnumQueryInteger_testEnumParameters: Int { case _1 = 1 - case numberminus2 = -2 + case number2 = -2 } /** @@ -335,7 +335,7 @@ open class FakeAPI { */ public enum EnumQueryDouble_testEnumParameters: Double { case _11 = 1.1 - case numberminus12 = -1.2 + case number12 = -1.2 } /** diff --git a/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Extensions.swift b/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Extensions.swift index 202b47449d8..9cac90e08d4 100644 --- a/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Extensions.swift +++ b/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Extensions.swift @@ -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(_ values: [T], forKey key: Self.Key) throws where T : Encodable { + var arrayContainer = nestedUnkeyedContainer(forKey: key) + try arrayContainer.encode(contentsOf: values) + } + + public mutating func encodeArrayIfPresent(_ values: [T]?, forKey key: Self.Key) throws where T : Encodable { + if let values = values { + try encodeArray(values, forKey: key) + } + } + + public mutating func encodeMap(_ pairs: [Self.Key: T]) throws where T : Encodable { + for (key, value) in pairs { + try encode(value, forKey: key) + } + } + + public mutating func encodeMapIfPresent(_ pairs: [Self.Key: T]?) throws where T : Encodable { + if let pairs = pairs { + try encodeMap(pairs) + } + } + +} + +extension KeyedDecodingContainerProtocol { + + public func decodeArray(_ 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(_ 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(_ type: T.Type, excludedKeys: Set) 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 + } + +} + diff --git a/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/AdditionalPropertiesClass.swift b/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/AdditionalPropertiesClass.swift index b18644a34e3..57e6d1f76e1 100644 --- a/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/AdditionalPropertiesClass.swift +++ b/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/AdditionalPropertiesClass.swift @@ -8,17 +8,35 @@ import Foundation + open class AdditionalPropertiesClass: Codable { public var mapProperty: [String:String]? public var mapOfMapProperty: [String:[String:String]]? - public init() {} - - private enum CodingKeys: String, CodingKey { - case mapProperty = "map_property" - case mapOfMapProperty = "map_of_map_property" + 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) + + 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") + } } + diff --git a/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/Animal.swift b/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/Animal.swift index 1c0cc68a298..fd48bfb9b4c 100644 --- a/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/Animal.swift +++ b/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/Animal.swift @@ -8,17 +8,35 @@ import Foundation + open class Animal: Codable { - public var className: String? + public var className: String public var color: String? - public init() {} - - private enum CodingKeys: String, CodingKey { - case className = "className" - case color = "color" + 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) + + 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") + } } + diff --git a/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/ApiResponse.swift b/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/ApiResponse.swift index 842755fb3c4..de8b7ec6ebd 100644 --- a/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/ApiResponse.swift +++ b/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/ApiResponse.swift @@ -8,19 +8,39 @@ import Foundation + open class ApiResponse: Codable { public var code: Int? public var type: String? public var message: String? - public init() {} - - private enum CodingKeys: String, CodingKey { - case code = "code" - case type = "type" - case message = "message" + 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) + + 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") + } } + diff --git a/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/ArrayOfArrayOfNumberOnly.swift b/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/ArrayOfArrayOfNumberOnly.swift index 9f7ee34099c..0b3c86516c4 100644 --- a/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/ArrayOfArrayOfNumberOnly.swift +++ b/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/ArrayOfArrayOfNumberOnly.swift @@ -8,15 +8,31 @@ import Foundation + open class ArrayOfArrayOfNumberOnly: Codable { public var arrayArrayNumber: [[Double]]? - public init() {} - - private enum CodingKeys: String, CodingKey { - case arrayArrayNumber = "ArrayArrayNumber" + public init(arrayArrayNumber: [[Double]]?) { + self.arrayArrayNumber = arrayArrayNumber } + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + 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") + } } + diff --git a/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/ArrayOfNumberOnly.swift b/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/ArrayOfNumberOnly.swift index fba11ceb708..733fda10ef4 100644 --- a/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/ArrayOfNumberOnly.swift +++ b/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/ArrayOfNumberOnly.swift @@ -8,15 +8,31 @@ import Foundation + open class ArrayOfNumberOnly: Codable { public var arrayNumber: [Double]? - public init() {} - - private enum CodingKeys: String, CodingKey { - case arrayNumber = "ArrayNumber" + public init(arrayNumber: [Double]?) { + self.arrayNumber = arrayNumber } + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + 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") + } } + diff --git a/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/ArrayTest.swift b/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/ArrayTest.swift index bdf244f5e0a..fd948816d28 100644 --- a/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/ArrayTest.swift +++ b/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/ArrayTest.swift @@ -8,19 +8,39 @@ import Foundation + open class ArrayTest: Codable { public var arrayOfString: [String]? public var arrayArrayOfInteger: [[Int64]]? public var arrayArrayOfModel: [[ReadOnlyFirst]]? - public init() {} - - private enum CodingKeys: String, CodingKey { - case arrayOfString = "array_of_string" - case arrayArrayOfInteger = "array_array_of_integer" - case arrayArrayOfModel = "array_array_of_model" + public init(arrayOfString: [String]?, arrayArrayOfInteger: [[Int64]]?, arrayArrayOfModel: [[ReadOnlyFirst]]?) { + self.arrayOfString = arrayOfString + self.arrayArrayOfInteger = arrayArrayOfInteger + self.arrayArrayOfModel = arrayArrayOfModel } + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encodeArrayIfPresent(arrayOfString, forKey: "array_of_string") + try container.encodeArrayIfPresent(arrayArrayOfInteger, forKey: "array_array_of_integer") + try container.encodeArrayIfPresent(arrayArrayOfModel, forKey: "array_array_of_model") + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + arrayOfString = try container.decodeArrayIfPresent(String.self, forKey: "array_of_string") + arrayArrayOfInteger = try container.decodeArrayIfPresent([Int64].self, forKey: "array_array_of_integer") + arrayArrayOfModel = try container.decodeArrayIfPresent([ReadOnlyFirst].self, forKey: "array_array_of_model") + } } + diff --git a/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/Capitalization.swift b/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/Capitalization.swift index a39eda9087c..32ea816610e 100644 --- a/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/Capitalization.swift +++ b/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/Capitalization.swift @@ -8,6 +8,7 @@ import Foundation + open class Capitalization: Codable { public var smallCamel: String? @@ -18,16 +19,41 @@ open class Capitalization: Codable { /** Name of the pet */ public var ATT_NAME: String? - public init() {} - - private enum CodingKeys: String, CodingKey { - case smallCamel = "smallCamel" - case capitalCamel = "CapitalCamel" - case smallSnake = "small_Snake" - case capitalSnake = "Capital_Snake" - case sCAETHFlowPoints = "SCA_ETH_Flow_Points" - case ATT_NAME = "ATT_NAME" + public init(smallCamel: String?, capitalCamel: String?, smallSnake: String?, capitalSnake: String?, sCAETHFlowPoints: String?, ATT_NAME: String?) { + self.smallCamel = smallCamel + self.capitalCamel = capitalCamel + self.smallSnake = smallSnake + self.capitalSnake = capitalSnake + self.sCAETHFlowPoints = sCAETHFlowPoints + self.ATT_NAME = ATT_NAME } + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encodeIfPresent(smallCamel, forKey: "smallCamel") + try container.encodeIfPresent(capitalCamel, forKey: "CapitalCamel") + try container.encodeIfPresent(smallSnake, forKey: "small_Snake") + try container.encodeIfPresent(capitalSnake, forKey: "Capital_Snake") + try container.encodeIfPresent(sCAETHFlowPoints, forKey: "SCA_ETH_Flow_Points") + try container.encodeIfPresent(ATT_NAME, forKey: "ATT_NAME") + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + smallCamel = try container.decodeIfPresent(String.self, forKey: "smallCamel") + capitalCamel = try container.decodeIfPresent(String.self, forKey: "CapitalCamel") + smallSnake = try container.decodeIfPresent(String.self, forKey: "small_Snake") + capitalSnake = try container.decodeIfPresent(String.self, forKey: "Capital_Snake") + sCAETHFlowPoints = try container.decodeIfPresent(String.self, forKey: "SCA_ETH_Flow_Points") + ATT_NAME = try container.decodeIfPresent(String.self, forKey: "ATT_NAME") + } } + diff --git a/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/Cat.swift b/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/Cat.swift index fdb090535aa..1354abdf4f0 100644 --- a/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/Cat.swift +++ b/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/Cat.swift @@ -8,15 +8,31 @@ import Foundation + open class Cat: Animal { public var declawed: Bool? - - - private enum CodingKeys: String, CodingKey { - case declawed = "declawed" + public init(declawed: Bool?) { + self.declawed = declawed } + // Encodable protocol methods + + public override func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encodeIfPresent(declawed, forKey: "declawed") + } + + // Decodable protocol methods + + public override required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + declawed = try container.decodeIfPresent(Bool.self, forKey: "declawed") + } } + diff --git a/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/Category.swift b/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/Category.swift index 684443a0649..4d631bf8273 100644 --- a/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/Category.swift +++ b/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/Category.swift @@ -8,17 +8,35 @@ import Foundation + open class Category: Codable { public var id: Int64? public var name: String? - public init() {} - - private enum CodingKeys: String, CodingKey { - case id = "id" - case name = "name" + public init(id: Int64?, name: String?) { + self.id = id + self.name = name } + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encodeIfPresent(id, forKey: "id") + try container.encodeIfPresent(name, forKey: "name") + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + id = try container.decodeIfPresent(Int64.self, forKey: "id") + name = try container.decodeIfPresent(String.self, forKey: "name") + } } + diff --git a/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/ClassModel.swift b/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/ClassModel.swift index a3d86c6c6f9..8d80e263370 100644 --- a/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/ClassModel.swift +++ b/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/ClassModel.swift @@ -9,15 +9,31 @@ import Foundation /** Model for testing model with \"_class\" property */ + open class ClassModel: Codable { public var _class: String? - public init() {} - - private enum CodingKeys: String, CodingKey { - case _class = "_class" + public init(_class: String?) { + self._class = _class } + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encodeIfPresent(_class, forKey: "_class") + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + _class = try container.decodeIfPresent(String.self, forKey: "_class") + } } + diff --git a/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/Client.swift b/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/Client.swift index 9d6d71b2367..3a74788606b 100644 --- a/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/Client.swift +++ b/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/Client.swift @@ -8,15 +8,31 @@ import Foundation + open class Client: Codable { public var client: String? - public init() {} - - private enum CodingKeys: String, CodingKey { - case client = "client" + public init(client: String?) { + self.client = client } + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encodeIfPresent(client, forKey: "client") + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + client = try container.decodeIfPresent(String.self, forKey: "client") + } } + diff --git a/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/Dog.swift b/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/Dog.swift index ffaab37e621..2835af6b0f9 100644 --- a/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/Dog.swift +++ b/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/Dog.swift @@ -8,15 +8,31 @@ import Foundation + open class Dog: Animal { public var breed: String? - - - private enum CodingKeys: String, CodingKey { - case breed = "breed" + public init(breed: String?) { + self.breed = breed } + // Encodable protocol methods + + public override func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encodeIfPresent(breed, forKey: "breed") + } + + // Decodable protocol methods + + public override required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + breed = try container.decodeIfPresent(String.self, forKey: "breed") + } } + diff --git a/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/EnumArrays.swift b/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/EnumArrays.swift index 9b2e72b9819..bb7960a7577 100644 --- a/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/EnumArrays.swift +++ b/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/EnumArrays.swift @@ -8,6 +8,7 @@ import Foundation + open class EnumArrays: Codable { public enum JustSymbol: String, Codable { @@ -21,12 +22,29 @@ open class EnumArrays: Codable { public var justSymbol: JustSymbol? public var arrayEnum: [ArrayEnum]? - public init() {} - - private enum CodingKeys: String, CodingKey { - case justSymbol = "just_symbol" - case arrayEnum = "array_enum" + public init(justSymbol: JustSymbol?, arrayEnum: [ArrayEnum]?) { + self.justSymbol = justSymbol + self.arrayEnum = arrayEnum } + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encodeIfPresent(justSymbol, forKey: "just_symbol") + try container.encodeArrayIfPresent(arrayEnum, forKey: "array_enum") + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + justSymbol = try container.decodeIfPresent(String.self, forKey: "just_symbol") + arrayEnum = try container.decodeArrayIfPresent(String.self, forKey: "array_enum") + } } + diff --git a/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/EnumTest.swift b/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/EnumTest.swift index 89dad808a5e..023f9a8209c 100644 --- a/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/EnumTest.swift +++ b/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/EnumTest.swift @@ -8,6 +8,7 @@ import Foundation + open class EnumTest: Codable { public enum EnumString: String, Codable { @@ -17,25 +18,46 @@ open class EnumTest: Codable { } public enum EnumInteger: Int, Codable { case _1 = 1 - case numberminus1 = -1 + case number1 = -1 } public enum EnumNumber: Double, Codable { case _11 = 1.1 - case numberminus12 = -1.2 + case number12 = -1.2 } public var enumString: EnumString? public var enumInteger: EnumInteger? public var enumNumber: EnumNumber? public var outerEnum: OuterEnum? - public init() {} - - private enum CodingKeys: String, CodingKey { - case enumString = "enum_string" - case enumInteger = "enum_integer" - case enumNumber = "enum_number" - case outerEnum = "outerEnum" + public init(enumString: EnumString?, enumInteger: EnumInteger?, enumNumber: EnumNumber?, outerEnum: OuterEnum?) { + self.enumString = enumString + self.enumInteger = enumInteger + self.enumNumber = enumNumber + self.outerEnum = outerEnum } + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encodeIfPresent(enumString, forKey: "enum_string") + try container.encodeIfPresent(enumInteger, forKey: "enum_integer") + try container.encodeIfPresent(enumNumber, forKey: "enum_number") + try container.encodeIfPresent(outerEnum, forKey: "outerEnum") + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + enumString = try container.decodeIfPresent(String.self, forKey: "enum_string") + enumInteger = try container.decodeIfPresent(Int.self, forKey: "enum_integer") + enumNumber = try container.decodeIfPresent(Double.self, forKey: "enum_number") + outerEnum = try container.decodeIfPresent(OuterEnum.self, forKey: "outerEnum") + } } + diff --git a/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/FormatTest.swift b/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/FormatTest.swift index d4a1e5f8e52..3423c30d9b9 100644 --- a/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/FormatTest.swift +++ b/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/FormatTest.swift @@ -8,39 +8,79 @@ import Foundation + open class FormatTest: Codable { public var integer: Int? public var int32: Int? public var int64: Int64? - public var number: Double? + public var number: Double public var float: Float? public var double: Double? public var string: String? - public var byte: Data? + public var byte: Data public var binary: Data? - public var date: Date? + public var date: Date public var dateTime: Date? public var uuid: UUID? - public var password: String? - - public init() {} + public var password: String - private enum CodingKeys: String, CodingKey { - case integer = "integer" - case int32 = "int32" - case int64 = "int64" - case number = "number" - case float = "float" - case double = "double" - case string = "string" - case byte = "byte" - case binary = "binary" - case date = "date" - case dateTime = "dateTime" - case uuid = "uuid" - case password = "password" + public init(integer: Int?, int32: Int?, int64: Int64?, number: Double, float: Float?, double: Double?, string: String?, byte: Data, binary: Data?, date: Date, dateTime: Date?, uuid: UUID?, password: String) { + self.integer = integer + self.int32 = int32 + self.int64 = int64 + self.number = number + self.float = float + self.double = double + self.string = string + self.byte = byte + self.binary = binary + self.date = date + self.dateTime = dateTime + self.uuid = uuid + self.password = password } + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encodeIfPresent(integer, forKey: "integer") + try container.encodeIfPresent(int32, forKey: "int32") + try container.encodeIfPresent(int64, forKey: "int64") + try container.encode(number, forKey: "number") + try container.encodeIfPresent(float, forKey: "float") + try container.encodeIfPresent(double, forKey: "double") + try container.encodeIfPresent(string, forKey: "string") + try container.encode(byte, forKey: "byte") + try container.encodeIfPresent(binary, forKey: "binary") + try container.encode(date, forKey: "date") + try container.encodeIfPresent(dateTime, forKey: "dateTime") + try container.encodeIfPresent(uuid, forKey: "uuid") + try container.encode(password, forKey: "password") + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + integer = try container.decodeIfPresent(Int.self, forKey: "integer") + int32 = try container.decodeIfPresent(Int.self, forKey: "int32") + int64 = try container.decodeIfPresent(Int64.self, forKey: "int64") + number = try container.decode(Double.self, forKey: "number") + float = try container.decodeIfPresent(Float.self, forKey: "float") + double = try container.decodeIfPresent(Double.self, forKey: "double") + string = try container.decodeIfPresent(String.self, forKey: "string") + byte = try container.decode(Data.self, forKey: "byte") + binary = try container.decodeIfPresent(Data.self, forKey: "binary") + date = try container.decode(Date.self, forKey: "date") + dateTime = try container.decodeIfPresent(Date.self, forKey: "dateTime") + uuid = try container.decodeIfPresent(UUID.self, forKey: "uuid") + password = try container.decode(String.self, forKey: "password") + } } + diff --git a/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/HasOnlyReadOnly.swift b/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/HasOnlyReadOnly.swift index f3f4f794975..226ffe44b08 100644 --- a/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/HasOnlyReadOnly.swift +++ b/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/HasOnlyReadOnly.swift @@ -8,17 +8,35 @@ import Foundation + open class HasOnlyReadOnly: Codable { public var bar: String? public var foo: String? - public init() {} - - private enum CodingKeys: String, CodingKey { - case bar = "bar" - case foo = "foo" + public init(bar: String?, foo: String?) { + self.bar = bar + self.foo = foo } + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encodeIfPresent(bar, forKey: "bar") + try container.encodeIfPresent(foo, forKey: "foo") + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + bar = try container.decodeIfPresent(String.self, forKey: "bar") + foo = try container.decodeIfPresent(String.self, forKey: "foo") + } } + diff --git a/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/List.swift b/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/List.swift index 4062dc0fef9..5f4068ffbeb 100644 --- a/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/List.swift +++ b/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/List.swift @@ -8,15 +8,31 @@ import Foundation + open class List: Codable { public var _123List: String? - public init() {} - - private enum CodingKeys: String, CodingKey { - case _123List = "123-list" + public init(_123List: String?) { + self._123List = _123List } + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encodeIfPresent(_123List, forKey: "123-list") + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + _123List = try container.decodeIfPresent(String.self, forKey: "123-list") + } } + diff --git a/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/MapTest.swift b/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/MapTest.swift index 1ccfa4e4e75..36f31fc1a44 100644 --- a/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/MapTest.swift +++ b/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/MapTest.swift @@ -8,6 +8,7 @@ import Foundation + open class MapTest: Codable { public enum MapOfEnumString: String, Codable { @@ -17,12 +18,29 @@ open class MapTest: Codable { public var mapMapOfString: [String:[String:String]]? public var mapOfEnumString: [String:String]? - public init() {} - - private enum CodingKeys: String, CodingKey { - case mapMapOfString = "map_map_of_string" - case mapOfEnumString = "map_of_enum_string" + public init(mapMapOfString: [String:[String:String]]?, mapOfEnumString: [String:String]?) { + self.mapMapOfString = mapMapOfString + self.mapOfEnumString = mapOfEnumString } + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encodeIfPresent(mapMapOfString, forKey: "map_map_of_string") + try container.encodeIfPresent(mapOfEnumString, forKey: "map_of_enum_string") + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + mapMapOfString = try container.decodeIfPresent([String:[String:String]].self, forKey: "map_map_of_string") + mapOfEnumString = try container.decodeIfPresent([String:String].self, forKey: "map_of_enum_string") + } } + diff --git a/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/MixedPropertiesAndAdditionalPropertiesClass.swift b/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/MixedPropertiesAndAdditionalPropertiesClass.swift index 801890006a0..0f475c175d2 100644 --- a/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/MixedPropertiesAndAdditionalPropertiesClass.swift +++ b/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/MixedPropertiesAndAdditionalPropertiesClass.swift @@ -8,19 +8,39 @@ import Foundation + open class MixedPropertiesAndAdditionalPropertiesClass: Codable { public var uuid: UUID? public var dateTime: Date? public var map: [String:Animal]? - public init() {} - - private enum CodingKeys: String, CodingKey { - case uuid = "uuid" - case dateTime = "dateTime" - case map = "map" + public init(uuid: UUID?, dateTime: Date?, map: [String:Animal]?) { + self.uuid = uuid + self.dateTime = dateTime + self.map = map } + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encodeIfPresent(uuid, forKey: "uuid") + try container.encodeIfPresent(dateTime, forKey: "dateTime") + try container.encodeIfPresent(map, forKey: "map") + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + uuid = try container.decodeIfPresent(UUID.self, forKey: "uuid") + dateTime = try container.decodeIfPresent(Date.self, forKey: "dateTime") + map = try container.decodeIfPresent([String:Animal].self, forKey: "map") + } } + diff --git a/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/Model200Response.swift b/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/Model200Response.swift index 31e32d33583..6c671b5031d 100644 --- a/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/Model200Response.swift +++ b/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/Model200Response.swift @@ -9,17 +9,35 @@ import Foundation /** Model for testing model name starting with number */ + open class Model200Response: Codable { public var name: Int? public var _class: String? - public init() {} - - private enum CodingKeys: String, CodingKey { - case name = "name" - case _class = "class" + public init(name: Int?, _class: String?) { + self.name = name + self._class = _class } + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encodeIfPresent(name, forKey: "name") + try container.encodeIfPresent(_class, forKey: "class") + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + name = try container.decodeIfPresent(Int.self, forKey: "name") + _class = try container.decodeIfPresent(String.self, forKey: "class") + } } + diff --git a/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/Name.swift b/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/Name.swift index 3f44a95624f..873b77e3ab2 100644 --- a/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/Name.swift +++ b/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/Name.swift @@ -9,21 +9,43 @@ import Foundation /** Model for testing model name same as property name */ + open class Name: Codable { - public var name: Int? + public var name: Int public var snakeCase: Int? public var property: String? public var _123Number: Int? - public init() {} - - private enum CodingKeys: String, CodingKey { - case name = "name" - case snakeCase = "snake_case" - case property = "property" - case _123Number = "123Number" + public init(name: Int, snakeCase: Int?, property: String?, _123Number: Int?) { + self.name = name + self.snakeCase = snakeCase + self.property = property + self._123Number = _123Number } + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encode(name, forKey: "name") + try container.encodeIfPresent(snakeCase, forKey: "snake_case") + try container.encodeIfPresent(property, forKey: "property") + try container.encodeIfPresent(_123Number, forKey: "123Number") + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + name = try container.decode(Int.self, forKey: "name") + snakeCase = try container.decodeIfPresent(Int.self, forKey: "snake_case") + property = try container.decodeIfPresent(String.self, forKey: "property") + _123Number = try container.decodeIfPresent(Int.self, forKey: "123Number") + } } + diff --git a/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/NumberOnly.swift b/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/NumberOnly.swift index d3663be1e75..89921c2c9c6 100644 --- a/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/NumberOnly.swift +++ b/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/NumberOnly.swift @@ -8,15 +8,31 @@ import Foundation + open class NumberOnly: Codable { public var justNumber: Double? - public init() {} - - private enum CodingKeys: String, CodingKey { - case justNumber = "JustNumber" + public init(justNumber: Double?) { + self.justNumber = justNumber } + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encodeIfPresent(justNumber, forKey: "JustNumber") + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + justNumber = try container.decodeIfPresent(Double.self, forKey: "JustNumber") + } } + diff --git a/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/Order.swift b/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/Order.swift index e9b1a0a8c2f..fee9d6c9192 100644 --- a/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/Order.swift +++ b/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/Order.swift @@ -8,6 +8,7 @@ import Foundation + open class Order: Codable { public enum Status: String, Codable { @@ -23,16 +24,41 @@ open class Order: Codable { public var status: Status? public var complete: Bool? - public init() {} - - private enum CodingKeys: String, CodingKey { - case id = "id" - case petId = "petId" - case quantity = "quantity" - case shipDate = "shipDate" - case status = "status" - case complete = "complete" + public init(id: Int64?, petId: Int64?, quantity: Int?, shipDate: Date?, status: Status?, complete: Bool?) { + self.id = id + self.petId = petId + self.quantity = quantity + self.shipDate = shipDate + self.status = status + self.complete = complete } + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encodeIfPresent(id, forKey: "id") + try container.encodeIfPresent(petId, forKey: "petId") + try container.encodeIfPresent(quantity, forKey: "quantity") + try container.encodeIfPresent(shipDate, forKey: "shipDate") + try container.encodeIfPresent(status, forKey: "status") + try container.encodeIfPresent(complete, forKey: "complete") + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + id = try container.decodeIfPresent(Int64.self, forKey: "id") + petId = try container.decodeIfPresent(Int64.self, forKey: "petId") + quantity = try container.decodeIfPresent(Int.self, forKey: "quantity") + shipDate = try container.decodeIfPresent(Date.self, forKey: "shipDate") + status = try container.decodeIfPresent(String.self, forKey: "status") + complete = try container.decodeIfPresent(Bool.self, forKey: "complete") + } } + diff --git a/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/OuterBoolean.swift b/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/OuterBoolean.swift index 3c49ad29400..ce257737983 100644 --- a/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/OuterBoolean.swift +++ b/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/OuterBoolean.swift @@ -8,4 +8,25 @@ import Foundation -public typealias OuterBoolean = Bool + +open class OuterBoolean: Codable { + + + + + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + } +} + diff --git a/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/OuterComposite.swift b/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/OuterComposite.swift index b085a27a470..cf46c19e7f1 100644 --- a/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/OuterComposite.swift +++ b/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/OuterComposite.swift @@ -8,19 +8,39 @@ import Foundation + open class OuterComposite: Codable { public var myNumber: OuterNumber? public var myString: OuterString? public var myBoolean: OuterBoolean? - public init() {} - - private enum CodingKeys: String, CodingKey { - case myNumber = "my_number" - case myString = "my_string" - case myBoolean = "my_boolean" + public init(myNumber: OuterNumber?, myString: OuterString?, myBoolean: OuterBoolean?) { + self.myNumber = myNumber + self.myString = myString + self.myBoolean = myBoolean } + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encodeIfPresent(myNumber, forKey: "my_number") + try container.encodeIfPresent(myString, forKey: "my_string") + try container.encodeIfPresent(myBoolean, forKey: "my_boolean") + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + myNumber = try container.decodeIfPresent(OuterNumber.self, forKey: "my_number") + myString = try container.decodeIfPresent(OuterString.self, forKey: "my_string") + myBoolean = try container.decodeIfPresent(OuterBoolean.self, forKey: "my_boolean") + } } + diff --git a/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/OuterNumber.swift b/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/OuterNumber.swift index f285f4e5e29..3cd67121150 100644 --- a/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/OuterNumber.swift +++ b/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/OuterNumber.swift @@ -8,4 +8,25 @@ import Foundation -public typealias OuterNumber = Double + +open class OuterNumber: Codable { + + + + + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + } +} + diff --git a/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/OuterString.swift b/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/OuterString.swift index 9da794627d6..0d9f059b91c 100644 --- a/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/OuterString.swift +++ b/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/OuterString.swift @@ -8,4 +8,25 @@ import Foundation -public typealias OuterString = String + +open class OuterString: Codable { + + + + + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + } +} + diff --git a/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/Pet.swift b/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/Pet.swift index bf982f538ff..0622c110fd4 100644 --- a/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/Pet.swift +++ b/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/Pet.swift @@ -8,6 +8,7 @@ import Foundation + open class Pet: Codable { public enum Status: String, Codable { @@ -17,22 +18,47 @@ open class Pet: Codable { } public var id: Int64? public var category: Category? - public var name: String? - public var photoUrls: [String]? + public var name: String + public var photoUrls: [String] public var tags: [Tag]? /** pet status in the store */ public var status: Status? - public init() {} - - private enum CodingKeys: String, CodingKey { - case id = "id" - case category = "category" - case name = "name" - case photoUrls = "photoUrls" - case tags = "tags" - case status = "status" + public init(id: Int64?, category: Category?, name: String, photoUrls: [String], tags: [Tag]?, status: Status?) { + self.id = id + self.category = category + self.name = name + self.photoUrls = photoUrls + self.tags = tags + self.status = status } + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encodeIfPresent(id, forKey: "id") + try container.encodeIfPresent(category, forKey: "category") + try container.encode(name, forKey: "name") + try container.encodeArray(photoUrls, forKey: "photoUrls") + try container.encodeArrayIfPresent(tags, forKey: "tags") + try container.encodeIfPresent(status, forKey: "status") + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + id = try container.decodeIfPresent(Int64.self, forKey: "id") + category = try container.decodeIfPresent(Category.self, forKey: "category") + name = try container.decode(String.self, forKey: "name") + photoUrls = try container.decodeArray(String.self, forKey: "photoUrls") + tags = try container.decodeArrayIfPresent(Tag.self, forKey: "tags") + status = try container.decodeIfPresent(String.self, forKey: "status") + } } + diff --git a/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/ReadOnlyFirst.swift b/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/ReadOnlyFirst.swift index 5a09771ea4b..e608e6845b2 100644 --- a/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/ReadOnlyFirst.swift +++ b/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/ReadOnlyFirst.swift @@ -8,17 +8,35 @@ import Foundation + open class ReadOnlyFirst: Codable { public var bar: String? public var baz: String? - public init() {} - - private enum CodingKeys: String, CodingKey { - case bar = "bar" - case baz = "baz" + public init(bar: String?, baz: String?) { + self.bar = bar + self.baz = baz } + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encodeIfPresent(bar, forKey: "bar") + try container.encodeIfPresent(baz, forKey: "baz") + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + bar = try container.decodeIfPresent(String.self, forKey: "bar") + baz = try container.decodeIfPresent(String.self, forKey: "baz") + } } + diff --git a/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/Return.swift b/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/Return.swift index 22b9e0174a1..6429c137f3a 100644 --- a/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/Return.swift +++ b/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/Return.swift @@ -9,15 +9,31 @@ import Foundation /** Model for testing reserved words */ + open class Return: Codable { public var _return: Int? - public init() {} - - private enum CodingKeys: String, CodingKey { - case _return = "return" + public init(_return: Int?) { + self._return = _return } + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encodeIfPresent(_return, forKey: "return") + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + _return = try container.decodeIfPresent(Int.self, forKey: "return") + } } + diff --git a/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/SpecialModelName.swift b/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/SpecialModelName.swift index 8c0a8f79dc6..de8c76fa3a9 100644 --- a/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/SpecialModelName.swift +++ b/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/SpecialModelName.swift @@ -8,15 +8,31 @@ import Foundation + open class SpecialModelName: Codable { public var specialPropertyName: Int64? - public init() {} - - private enum CodingKeys: String, CodingKey { - case specialPropertyName = "$special[property.name]" + public init(specialPropertyName: Int64?) { + self.specialPropertyName = specialPropertyName } + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encodeIfPresent(specialPropertyName, forKey: "$special[property.name]") + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + specialPropertyName = try container.decodeIfPresent(Int64.self, forKey: "$special[property.name]") + } } + diff --git a/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/Tag.swift b/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/Tag.swift index feb6ab7c6cd..ab230b5f899 100644 --- a/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/Tag.swift +++ b/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/Tag.swift @@ -8,17 +8,35 @@ import Foundation + open class Tag: Codable { public var id: Int64? public var name: String? - public init() {} - - private enum CodingKeys: String, CodingKey { - case id = "id" - case name = "name" + public init(id: Int64?, name: String?) { + self.id = id + self.name = name } + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encodeIfPresent(id, forKey: "id") + try container.encodeIfPresent(name, forKey: "name") + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + id = try container.decodeIfPresent(Int64.self, forKey: "id") + name = try container.decodeIfPresent(String.self, forKey: "name") + } } + diff --git a/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/User.swift b/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/User.swift index 8fda8afb40e..17e6af33d5d 100644 --- a/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/User.swift +++ b/samples/client/petstore/swift4/default/PetstoreClient/Classes/Swaggers/Models/User.swift @@ -8,6 +8,7 @@ import Foundation + open class User: Codable { public var id: Int64? @@ -20,18 +21,47 @@ open class User: Codable { /** User Status */ public var userStatus: Int? - public init() {} - - private enum CodingKeys: String, CodingKey { - case id = "id" - case username = "username" - case firstName = "firstName" - case lastName = "lastName" - case email = "email" - case password = "password" - case phone = "phone" - case userStatus = "userStatus" + public init(id: Int64?, username: String?, firstName: String?, lastName: String?, email: String?, password: String?, phone: String?, userStatus: Int?) { + self.id = id + self.username = username + self.firstName = firstName + self.lastName = lastName + self.email = email + self.password = password + self.phone = phone + self.userStatus = userStatus } + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encodeIfPresent(id, forKey: "id") + try container.encodeIfPresent(username, forKey: "username") + try container.encodeIfPresent(firstName, forKey: "firstName") + try container.encodeIfPresent(lastName, forKey: "lastName") + try container.encodeIfPresent(email, forKey: "email") + try container.encodeIfPresent(password, forKey: "password") + try container.encodeIfPresent(phone, forKey: "phone") + try container.encodeIfPresent(userStatus, forKey: "userStatus") + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + id = try container.decodeIfPresent(Int64.self, forKey: "id") + username = try container.decodeIfPresent(String.self, forKey: "username") + firstName = try container.decodeIfPresent(String.self, forKey: "firstName") + lastName = try container.decodeIfPresent(String.self, forKey: "lastName") + email = try container.decodeIfPresent(String.self, forKey: "email") + password = try container.decodeIfPresent(String.self, forKey: "password") + phone = try container.decodeIfPresent(String.self, forKey: "phone") + userStatus = try container.decodeIfPresent(Int.self, forKey: "userStatus") + } } + diff --git a/samples/client/petstore/swift4/objcCompatible/.gitignore b/samples/client/petstore/swift4/objcCompatible/.gitignore new file mode 100644 index 00000000000..5e5d5cebcf4 --- /dev/null +++ b/samples/client/petstore/swift4/objcCompatible/.gitignore @@ -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 diff --git a/samples/client/petstore/swift4/objcCompatible/.swagger-codegen-ignore b/samples/client/petstore/swift4/objcCompatible/.swagger-codegen-ignore new file mode 100644 index 00000000000..c5fa491b4c5 --- /dev/null +++ b/samples/client/petstore/swift4/objcCompatible/.swagger-codegen-ignore @@ -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 diff --git a/samples/client/petstore/swift4/objcCompatible/.swagger-codegen/VERSION b/samples/client/petstore/swift4/objcCompatible/.swagger-codegen/VERSION new file mode 100644 index 00000000000..f9f7450d135 --- /dev/null +++ b/samples/client/petstore/swift4/objcCompatible/.swagger-codegen/VERSION @@ -0,0 +1 @@ +2.3.0-SNAPSHOT \ No newline at end of file diff --git a/samples/client/petstore/swift4/objcCompatible/Cartfile b/samples/client/petstore/swift4/objcCompatible/Cartfile new file mode 100644 index 00000000000..3d90db16891 --- /dev/null +++ b/samples/client/petstore/swift4/objcCompatible/Cartfile @@ -0,0 +1 @@ +github "Alamofire/Alamofire" >= 3.1.0 diff --git a/samples/client/petstore/swift4/objcCompatible/PetstoreClient.podspec b/samples/client/petstore/swift4/objcCompatible/PetstoreClient.podspec new file mode 100644 index 00000000000..7a28d478bf8 --- /dev/null +++ b/samples/client/petstore/swift4/objcCompatible/PetstoreClient.podspec @@ -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 diff --git a/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/APIHelper.swift b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/APIHelper.swift new file mode 100644 index 00000000000..b612ff90921 --- /dev/null +++ b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/APIHelper.swift @@ -0,0 +1,65 @@ +// 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 + URLQueryItem(name: item._key, value:"\(item._value!)") + } + if returnValues.count == 0 { + return nil + } + return returnValues + } + +} diff --git a/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/APIs.swift b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/APIs.swift new file mode 100644 index 00000000000..745d640ec1c --- /dev/null +++ b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/APIs.swift @@ -0,0 +1,61 @@ +// 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 RequestBuilder { + var credential: URLCredential? + var headers: [String:String] + let parameters: [String:Any]? + let isBody: Bool + let method: String + 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: [String: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 { + headers[header] = value + } + } + + open func execute(_ completion: @escaping (_ response: Response?, _ error: Error?) -> Void) { } + + 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 getNonDecodableBuilder() -> RequestBuilder.Type + func getBuilder() -> RequestBuilder.Type +} diff --git a/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/APIs/AnotherfakeAPI.swift b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/APIs/AnotherfakeAPI.swift new file mode 100644 index 00000000000..9c135bdce3a --- /dev/null +++ b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/APIs/AnotherfakeAPI.swift @@ -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 + */ + open class func testSpecialTagsWithRequestBuilder(body: Client) -> RequestBuilder { + let path = "/another-fake/dummy" + let URLString = PetstoreClientAPI.basePath + path + let parameters = JSONEncodingHelper.encodingParameters(forEncodableObject: body) + + let url = NSURLComponents(string: URLString) + + + let requestBuilder: RequestBuilder.Type = PetstoreClientAPI.requestBuilderFactory.getBuilder() + + return requestBuilder.init(method: "PATCH", URLString: (url?.string ?? URLString), parameters: parameters, isBody: true) + } + +} diff --git a/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/APIs/FakeAPI.swift b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/APIs/FakeAPI.swift new file mode 100644 index 00000000000..a111760bee0 --- /dev/null +++ b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/APIs/FakeAPI.swift @@ -0,0 +1,450 @@ +// +// FakeAPI.swift +// +// Generated by swagger-codegen +// https://github.com/swagger-api/swagger-codegen +// + +import Foundation +import Alamofire + + + +open class FakeAPI { + /** + + - 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: Error?) -> 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 + */ + open class func fakeOuterBooleanSerializeWithRequestBuilder(body: OuterBoolean? = nil) -> RequestBuilder { + let path = "/fake/outer/boolean" + let URLString = PetstoreClientAPI.basePath + path + let parameters = JSONEncodingHelper.encodingParameters(forEncodableObject: body) + + let url = NSURLComponents(string: URLString) + + + let requestBuilder: RequestBuilder.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: Error?) -> 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 + */ + open class func fakeOuterCompositeSerializeWithRequestBuilder(body: OuterComposite? = nil) -> RequestBuilder { + let path = "/fake/outer/composite" + let URLString = PetstoreClientAPI.basePath + path + let parameters = JSONEncodingHelper.encodingParameters(forEncodableObject: body) + + let url = NSURLComponents(string: URLString) + + + let requestBuilder: RequestBuilder.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: Error?) -> 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 + */ + open class func fakeOuterNumberSerializeWithRequestBuilder(body: OuterNumber? = nil) -> RequestBuilder { + let path = "/fake/outer/number" + let URLString = PetstoreClientAPI.basePath + path + let parameters = JSONEncodingHelper.encodingParameters(forEncodableObject: body) + + let url = NSURLComponents(string: URLString) + + + let requestBuilder: RequestBuilder.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: Error?) -> 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 + */ + open class func fakeOuterStringSerializeWithRequestBuilder(body: OuterString? = nil) -> RequestBuilder { + let path = "/fake/outer/string" + let URLString = PetstoreClientAPI.basePath + path + let parameters = JSONEncodingHelper.encodingParameters(forEncodableObject: body) + + let url = NSURLComponents(string: URLString) + + + let requestBuilder: RequestBuilder.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: Error?) -> 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 + */ + open class func testClientModelWithRequestBuilder(body: Client) -> RequestBuilder { + let path = "/fake" + let URLString = PetstoreClientAPI.basePath + path + let parameters = JSONEncodingHelper.encodingParameters(forEncodableObject: body) + + let url = NSURLComponents(string: URLString) + + + let requestBuilder: RequestBuilder.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: Int? = nil, int32: Int? = nil, int64: Int64? = nil, float: Float? = nil, string: String? = nil, binary: Data? = nil, date: Date? = nil, dateTime: Date? = nil, password: String? = nil, callback: String? = nil, completion: @escaping ((_ error: Error?) -> 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 + */ + open class func testEndpointParametersWithRequestBuilder(number: Double, double: Double, patternWithoutDelimiter: String, byte: Data, integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, float: Float? = nil, string: String? = nil, binary: Data? = nil, date: Date? = nil, dateTime: Date? = nil, password: String? = nil, callback: String? = nil) -> RequestBuilder { + 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.Type = PetstoreClientAPI.requestBuilderFactory.getNonDecodableBuilder() + + 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: Int { + 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: Error?) -> 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 + */ + 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 { + 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.Type = PetstoreClientAPI.requestBuilderFactory.getNonDecodableBuilder() + + 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: Error?) -> 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 + */ + open class func testJsonFormDataWithRequestBuilder(param: String, param2: String) -> RequestBuilder { + 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.Type = PetstoreClientAPI.requestBuilderFactory.getNonDecodableBuilder() + + return requestBuilder.init(method: "GET", URLString: (url?.string ?? URLString), parameters: parameters, isBody: false) + } + +} diff --git a/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/APIs/Fake_classname_tags123API.swift b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/APIs/Fake_classname_tags123API.swift new file mode 100644 index 00000000000..35c9e383fa2 --- /dev/null +++ b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/APIs/Fake_classname_tags123API.swift @@ -0,0 +1,54 @@ +// +// Fake_classname_tags123API.swift +// +// Generated by swagger-codegen +// https://github.com/swagger-api/swagger-codegen +// + +import Foundation +import Alamofire + + + +open class Fake_classname_tags123API { + /** + 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: Error?) -> 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 + */ + open class func testClassnameWithRequestBuilder(body: Client) -> RequestBuilder { + let path = "/fake_classname_test" + let URLString = PetstoreClientAPI.basePath + path + let parameters = JSONEncodingHelper.encodingParameters(forEncodableObject: body) + + let url = NSURLComponents(string: URLString) + + + let requestBuilder: RequestBuilder.Type = PetstoreClientAPI.requestBuilderFactory.getBuilder() + + return requestBuilder.init(method: "PATCH", URLString: (url?.string ?? URLString), parameters: parameters, isBody: true) + } + +} diff --git a/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/APIs/PetAPI.swift b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/APIs/PetAPI.swift new file mode 100644 index 00000000000..6a7425564aa --- /dev/null +++ b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/APIs/PetAPI.swift @@ -0,0 +1,588 @@ +// +// PetAPI.swift +// +// Generated by swagger-codegen +// https://github.com/swagger-api/swagger-codegen +// + +import Foundation +import Alamofire + + + +open class PetAPI { + /** + 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: Error?) -> 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 + */ + open class func addPetWithRequestBuilder(body: Pet) -> RequestBuilder { + let path = "/pet" + let URLString = PetstoreClientAPI.basePath + path + let parameters = JSONEncodingHelper.encodingParameters(forEncodableObject: body) + + let url = NSURLComponents(string: URLString) + + + let requestBuilder: RequestBuilder.Type = PetstoreClientAPI.requestBuilderFactory.getNonDecodableBuilder() + + 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: Error?) -> 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 + */ + open class func deletePetWithRequestBuilder(petId: Int64, apiKey: String? = nil) -> RequestBuilder { + var path = "/pet/{petId}" + path = path.replacingOccurrences(of: "{petId}", with: "\(petId)", 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.Type = PetstoreClientAPI.requestBuilderFactory.getNonDecodableBuilder() + + 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: Error?) -> 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= + 123456789 + doggie + + aeiou + + + + aeiou +}, {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= + 123456789 + doggie + + aeiou + + + + aeiou +}, {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: Error?) -> 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= + 123456789 + doggie + + aeiou + + + + aeiou +}, {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= + 123456789 + doggie + + aeiou + + + + aeiou +}, {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: Error?) -> 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= + 123456789 + doggie + + aeiou + + + + aeiou +}, {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= + 123456789 + doggie + + aeiou + + + + aeiou +}, {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 + */ + open class func getPetByIdWithRequestBuilder(petId: Int64) -> RequestBuilder { + var path = "/pet/{petId}" + path = path.replacingOccurrences(of: "{petId}", with: "\(petId)", options: .literal, range: nil) + let URLString = PetstoreClientAPI.basePath + path + let parameters: [String:Any]? = nil + + let url = NSURLComponents(string: URLString) + + + let requestBuilder: RequestBuilder.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: Error?) -> 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 + */ + open class func updatePetWithRequestBuilder(body: Pet) -> RequestBuilder { + let path = "/pet" + let URLString = PetstoreClientAPI.basePath + path + let parameters = JSONEncodingHelper.encodingParameters(forEncodableObject: body) + + let url = NSURLComponents(string: URLString) + + + let requestBuilder: RequestBuilder.Type = PetstoreClientAPI.requestBuilderFactory.getNonDecodableBuilder() + + 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: Error?) -> 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 + */ + open class func updatePetWithFormWithRequestBuilder(petId: Int64, name: String? = nil, status: String? = nil) -> RequestBuilder { + var path = "/pet/{petId}" + path = path.replacingOccurrences(of: "{petId}", with: "\(petId)", 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.Type = PetstoreClientAPI.requestBuilderFactory.getNonDecodableBuilder() + + 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: Error?) -> 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 + */ + open class func uploadFileWithRequestBuilder(petId: Int64, additionalMetadata: String? = nil, file: URL? = nil) -> RequestBuilder { + var path = "/pet/{petId}/uploadImage" + path = path.replacingOccurrences(of: "{petId}", with: "\(petId)", 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.Type = PetstoreClientAPI.requestBuilderFactory.getBuilder() + + return requestBuilder.init(method: "POST", URLString: (url?.string ?? URLString), parameters: parameters, isBody: false) + } + +} diff --git a/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/APIs/StoreAPI.swift b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/APIs/StoreAPI.swift new file mode 100644 index 00000000000..756ada76c42 --- /dev/null +++ b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/APIs/StoreAPI.swift @@ -0,0 +1,219 @@ +// +// StoreAPI.swift +// +// Generated by swagger-codegen +// https://github.com/swagger-api/swagger-codegen +// + +import Foundation +import Alamofire + + + +open class StoreAPI { + /** + 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: Error?) -> 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 + */ + open class func deleteOrderWithRequestBuilder(orderId: String) -> RequestBuilder { + var path = "/store/order/{order_id}" + path = path.replacingOccurrences(of: "{order_id}", with: "\(orderId)", options: .literal, range: nil) + let URLString = PetstoreClientAPI.basePath + path + let parameters: [String:Any]? = nil + + let url = NSURLComponents(string: URLString) + + + let requestBuilder: RequestBuilder.Type = PetstoreClientAPI.requestBuilderFactory.getNonDecodableBuilder() + + 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:Int]?,_ error: Error?) -> 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:Int]> + */ + open class func getInventoryWithRequestBuilder() -> RequestBuilder<[String:Int]> { + let path = "/store/inventory" + let URLString = PetstoreClientAPI.basePath + path + let parameters: [String:Any]? = nil + + let url = NSURLComponents(string: URLString) + + + let requestBuilder: RequestBuilder<[String:Int]>.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: Error?) -> 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= + 123456789 + 123456789 + 123 + 2000-01-23T04:56:07.000Z + aeiou + true +}, {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= + 123456789 + 123456789 + 123 + 2000-01-23T04:56:07.000Z + aeiou + true +}, {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 + */ + open class func getOrderByIdWithRequestBuilder(orderId: Int64) -> RequestBuilder { + var path = "/store/order/{order_id}" + path = path.replacingOccurrences(of: "{order_id}", with: "\(orderId)", options: .literal, range: nil) + let URLString = PetstoreClientAPI.basePath + path + let parameters: [String:Any]? = nil + + let url = NSURLComponents(string: URLString) + + + let requestBuilder: RequestBuilder.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: Error?) -> 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= + 123456789 + 123456789 + 123 + 2000-01-23T04:56:07.000Z + aeiou + true +}, {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= + 123456789 + 123456789 + 123 + 2000-01-23T04:56:07.000Z + aeiou + true +}, {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 + */ + open class func placeOrderWithRequestBuilder(body: Order) -> RequestBuilder { + let path = "/store/order" + let URLString = PetstoreClientAPI.basePath + path + let parameters = JSONEncodingHelper.encodingParameters(forEncodableObject: body) + + let url = NSURLComponents(string: URLString) + + + let requestBuilder: RequestBuilder.Type = PetstoreClientAPI.requestBuilderFactory.getBuilder() + + return requestBuilder.init(method: "POST", URLString: (url?.string ?? URLString), parameters: parameters, isBody: true) + } + +} diff --git a/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/APIs/UserAPI.swift b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/APIs/UserAPI.swift new file mode 100644 index 00000000000..cbc7bd93258 --- /dev/null +++ b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/APIs/UserAPI.swift @@ -0,0 +1,344 @@ +// +// UserAPI.swift +// +// Generated by swagger-codegen +// https://github.com/swagger-api/swagger-codegen +// + +import Foundation +import Alamofire + + + +open class UserAPI { + /** + 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: Error?) -> 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 + */ + open class func createUserWithRequestBuilder(body: User) -> RequestBuilder { + let path = "/user" + let URLString = PetstoreClientAPI.basePath + path + let parameters = JSONEncodingHelper.encodingParameters(forEncodableObject: body) + + let url = NSURLComponents(string: URLString) + + + let requestBuilder: RequestBuilder.Type = PetstoreClientAPI.requestBuilderFactory.getNonDecodableBuilder() + + 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: Error?) -> 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 + */ + open class func createUsersWithArrayInputWithRequestBuilder(body: [User]) -> RequestBuilder { + let path = "/user/createWithArray" + let URLString = PetstoreClientAPI.basePath + path + let parameters = JSONEncodingHelper.encodingParameters(forEncodableObject: body) + + let url = NSURLComponents(string: URLString) + + + let requestBuilder: RequestBuilder.Type = PetstoreClientAPI.requestBuilderFactory.getNonDecodableBuilder() + + 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: Error?) -> 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 + */ + open class func createUsersWithListInputWithRequestBuilder(body: [User]) -> RequestBuilder { + let path = "/user/createWithList" + let URLString = PetstoreClientAPI.basePath + path + let parameters = JSONEncodingHelper.encodingParameters(forEncodableObject: body) + + let url = NSURLComponents(string: URLString) + + + let requestBuilder: RequestBuilder.Type = PetstoreClientAPI.requestBuilderFactory.getNonDecodableBuilder() + + 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: Error?) -> 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 + */ + open class func deleteUserWithRequestBuilder(username: String) -> RequestBuilder { + var path = "/user/{username}" + path = path.replacingOccurrences(of: "{username}", with: "\(username)", options: .literal, range: nil) + let URLString = PetstoreClientAPI.basePath + path + let parameters: [String:Any]? = nil + + let url = NSURLComponents(string: URLString) + + + let requestBuilder: RequestBuilder.Type = PetstoreClientAPI.requestBuilderFactory.getNonDecodableBuilder() + + 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: Error?) -> 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= + 123456789 + aeiou + aeiou + aeiou + aeiou + aeiou + aeiou + 123 +}, {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= + 123456789 + aeiou + aeiou + aeiou + aeiou + aeiou + aeiou + 123 +}, {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 + */ + open class func getUserByNameWithRequestBuilder(username: String) -> RequestBuilder { + var path = "/user/{username}" + path = path.replacingOccurrences(of: "{username}", with: "\(username)", options: .literal, range: nil) + let URLString = PetstoreClientAPI.basePath + path + let parameters: [String:Any]? = nil + + let url = NSURLComponents(string: URLString) + + + let requestBuilder: RequestBuilder.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: Error?) -> 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(Int), X-Expires-After(Date)] + - responseHeaders: [X-Rate-Limit(Int), 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 + */ + open class func loginUserWithRequestBuilder(username: String, password: String) -> RequestBuilder { + 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.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: Error?) -> Void)) { + logoutUserWithRequestBuilder().execute { (response, error) -> Void in + completion(error); + } + } + + + /** + Logs out current logged in user session + - GET /user/logout + - + + - returns: RequestBuilder + */ + open class func logoutUserWithRequestBuilder() -> RequestBuilder { + let path = "/user/logout" + let URLString = PetstoreClientAPI.basePath + path + let parameters: [String:Any]? = nil + + let url = NSURLComponents(string: URLString) + + + let requestBuilder: RequestBuilder.Type = PetstoreClientAPI.requestBuilderFactory.getNonDecodableBuilder() + + 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: Error?) -> 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 + */ + open class func updateUserWithRequestBuilder(username: String, body: User) -> RequestBuilder { + var path = "/user/{username}" + path = path.replacingOccurrences(of: "{username}", with: "\(username)", options: .literal, range: nil) + let URLString = PetstoreClientAPI.basePath + path + let parameters = JSONEncodingHelper.encodingParameters(forEncodableObject: body) + + let url = NSURLComponents(string: URLString) + + + let requestBuilder: RequestBuilder.Type = PetstoreClientAPI.requestBuilderFactory.getNonDecodableBuilder() + + return requestBuilder.init(method: "PUT", URLString: (url?.string ?? URLString), parameters: parameters, isBody: true) + } + +} diff --git a/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/AlamofireImplementations.swift b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/AlamofireImplementations.swift new file mode 100644 index 00000000000..0d294aee4ce --- /dev/null +++ b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/AlamofireImplementations.swift @@ -0,0 +1,417 @@ +// AlamofireImplementations.swift +// +// Generated by swagger-codegen +// https://github.com/swagger-api/swagger-codegen +// + +import Foundation +import Alamofire + +class AlamofireRequestBuilderFactory: RequestBuilderFactory { + func getNonDecodableBuilder() -> RequestBuilder.Type { + return AlamofireRequestBuilder.self + } + + func getBuilder() -> RequestBuilder.Type { + return AlamofireDecodableRequestBuilder.self + } +} + +// Store manager to retain its reference +private var managerStore: [String: Alamofire.SessionManager] = [:] + +open class AlamofireRequestBuilder: RequestBuilder { + required public init(method: String, URLString: String, parameters: [String : 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, encoding: encoding, headers: headers) + } + + override open func execute(_ completion: @escaping (_ response: Response?, _ error: Error?) -> 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 ? JSONDataEncoding() : URLEncoding() + + let xMethod = Alamofire.HTTPMethod(rawValue: method) + let fileKeys = parameters == nil ? [] : parameters!.filter { $1 is NSURL } + .map { $0.0 } + + if fileKeys.count > 0 { + manager.upload(multipartFormData: { mpForm in + for (k, v) in self.parameters! { + 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.Error(415, nil, 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) + } + + } + + fileprivate func processRequest(request: DataRequest, _ managerId: String, _ completion: @escaping (_ response: Response?, _ error: Error?) -> Void) { + if let credential = self.credential { + request.authenticate(usingCredential: credential) + } + + let cleanupRequest = { + _ = managerStore.removeValue(forKey: managerId) + } + + let validatedRequest = request.validate() + + switch T.self { + case is String.Type: + validatedRequest.responseString(completionHandler: { (stringResponse) in + cleanupRequest() + + if stringResponse.result.isFailure { + completion( + nil, + ErrorResponse.Error(stringResponse.response?.statusCode ?? 500, stringResponse.data, stringResponse.result.error as Error!) + ) + return + } + + completion( + Response( + response: stringResponse.response!, + body: ((stringResponse.result.value ?? "") 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.Error(400, dataResponse.data, requestParserError)) + } catch let error { + completion(nil, ErrorResponse.Error(400, dataResponse.data, error)) + } + return + }) + case is Void.Type: + validatedRequest.responseData(completionHandler: { (voidResponse) in + cleanupRequest() + + if voidResponse.result.isFailure { + completion( + nil, + ErrorResponse.Error(voidResponse.response?.statusCode ?? 500, voidResponse.data, voidResponse.result.error!) + ) + return + } + + completion( + Response( + response: voidResponse.response!, + body: nil), + nil + ) + }) + default: + validatedRequest.responseData(completionHandler: { (dataResponse) in + cleanupRequest() + + if (dataResponse.result.isFailure) { + completion( + nil, + ErrorResponse.Error(dataResponse.response?.statusCode ?? 500, dataResponse.data, dataResponse.result.error!) + ) + return + } + + completion( + Response( + response: dataResponse.response!, + body: (dataResponse.data as! T) + ), + nil + ) + }) + } + } + + 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 +} + +public enum AlamofireDecodableRequestBuilderError: Error { + case emptyDataResponse + case nilHTTPResponse + case jsonDecoding(DecodingError) + case generalError(Error) +} + +open class AlamofireDecodableRequestBuilder: AlamofireRequestBuilder { + + override fileprivate func processRequest(request: DataRequest, _ managerId: String, _ completion: @escaping (_ response: Response?, _ error: Error?) -> Void) { + if let credential = self.credential { + request.authenticate(usingCredential: credential) + } + + let cleanupRequest = { + _ = managerStore.removeValue(forKey: managerId) + } + + let validatedRequest = request.validate() + + switch T.self { + case is String.Type: + validatedRequest.responseString(completionHandler: { (stringResponse) in + cleanupRequest() + + if stringResponse.result.isFailure { + completion( + nil, + ErrorResponse.Error(stringResponse.response?.statusCode ?? 500, stringResponse.data, 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.Error(voidResponse.response?.statusCode ?? 500, voidResponse.data, 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.Error(dataResponse.response?.statusCode ?? 500, dataResponse.data, dataResponse.result.error!) + ) + return + } + + completion( + Response( + response: dataResponse.response!, + body: (dataResponse.data as! T) + ), + nil + ) + }) + default: + validatedRequest.responseData(completionHandler: { (dataResponse: DataResponse) in + cleanupRequest() + + guard dataResponse.result.isSuccess else { + completion(nil, ErrorResponse.Error(dataResponse.response?.statusCode ?? 500, dataResponse.data, dataResponse.result.error!)) + return + } + + guard let data = dataResponse.data, !data.isEmpty else { + completion(nil, ErrorResponse.Error(-1, nil, AlamofireDecodableRequestBuilderError.emptyDataResponse)) + return + } + + guard let httpResponse = dataResponse.response else { + completion(nil, ErrorResponse.Error(-2, nil, AlamofireDecodableRequestBuilderError.nilHTTPResponse)) + return + } + + var responseObj: Response? = nil + + let decodeResult: (decodableObj: T?, error: Error?) = CodableHelper.decode(T.self, from: data) + if decodeResult.error == nil { + responseObj = Response(response: httpResponse, body: decodeResult.decodableObj) + } + + completion(responseObj, decodeResult.error) + }) + } + } + +} diff --git a/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/CodableHelper.swift b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/CodableHelper.swift new file mode 100644 index 00000000000..d56cb0e7348 --- /dev/null +++ b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/CodableHelper.swift @@ -0,0 +1,55 @@ +// +// CodableHelper.swift +// +// Generated by swagger-codegen +// https://github.com/swagger-api/swagger-codegen +// + +import Foundation + +public typealias EncodeResult = (data: Data?, error: Error?) + +open class CodableHelper { + + open class func decode(_ type: T.Type, from data: Data) -> (decodableObj: T?, error: Error?) where T : Decodable { + var returnedDecodable: T? = nil + var returnedError: Error? = nil + + let decoder = JSONDecoder() + decoder.dataDecodingStrategy = .base64 + if #available(iOS 10.0, *) { + decoder.dateDecodingStrategy = .iso8601 + } + + do { + returnedDecodable = try decoder.decode(type, from: data) + } catch { + returnedError = error + } + + return (returnedDecodable, returnedError) + } + + open class func encode(_ value: T, prettyPrint: Bool = false) -> EncodeResult where T : Encodable { + var returnedData: Data? + var returnedError: Error? = nil + + let encoder = JSONEncoder() + if prettyPrint { + encoder.outputFormatting = .prettyPrinted + } + encoder.dataEncodingStrategy = .base64 + if #available(iOS 10.0, *) { + encoder.dateEncodingStrategy = .iso8601 + } + + do { + returnedData = try encoder.encode(value) + } catch { + returnedError = error + } + + return (returnedData, returnedError) + } + +} diff --git a/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Configuration.swift b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Configuration.swift new file mode 100644 index 00000000000..c03a10b930c --- /dev/null +++ b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Configuration.swift @@ -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" + +} \ No newline at end of file diff --git a/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Extensions.swift b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Extensions.swift new file mode 100644 index 00000000000..9cac90e08d4 --- /dev/null +++ b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Extensions.swift @@ -0,0 +1,173 @@ +// 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(_ 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 + } +} + +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(_ values: [T], forKey key: Self.Key) throws where T : Encodable { + var arrayContainer = nestedUnkeyedContainer(forKey: key) + try arrayContainer.encode(contentsOf: values) + } + + public mutating func encodeArrayIfPresent(_ values: [T]?, forKey key: Self.Key) throws where T : Encodable { + if let values = values { + try encodeArray(values, forKey: key) + } + } + + public mutating func encodeMap(_ pairs: [Self.Key: T]) throws where T : Encodable { + for (key, value) in pairs { + try encode(value, forKey: key) + } + } + + public mutating func encodeMapIfPresent(_ pairs: [Self.Key: T]?) throws where T : Encodable { + if let pairs = pairs { + try encodeMap(pairs) + } + } + +} + +extension KeyedDecodingContainerProtocol { + + public func decodeArray(_ 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(_ 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(_ type: T.Type, excludedKeys: Set) 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 + } + +} + + diff --git a/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/JSONEncodableEncoding.swift b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/JSONEncodableEncoding.swift new file mode 100644 index 00000000000..472e955ee8e --- /dev/null +++ b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/JSONEncodableEncoding.swift @@ -0,0 +1,54 @@ +// +// JSONDataEncoding.swift +// +// Generated by swagger-codegen +// https://github.com/swagger-api/swagger-codegen +// + +import Foundation +import Alamofire + +public struct JSONDataEncoding: ParameterEncoding { + + // MARK: Properties + + private static let jsonDataKey = "jsonData" + + // MARK: Encoding + + /// Creates a URL request by encoding parameters and applying them onto an existing request. + /// + /// - parameter urlRequest: The request to have parameters applied. + /// - parameter parameters: The parameters to apply. This should have a single key/value + /// pair with "jsonData" as the key and a Data object as the value. + /// + /// - throws: An `Error` if the encoding process encounters an error. + /// + /// - returns: The encoded request. + public func encode(_ urlRequest: URLRequestConvertible, with parameters: Parameters?) throws -> URLRequest { + var urlRequest = try urlRequest.asURLRequest() + + guard let jsonData = parameters?[JSONDataEncoding.jsonDataKey] as? Data, !jsonData.isEmpty else { + return urlRequest + } + + if urlRequest.value(forHTTPHeaderField: "Content-Type") == nil { + urlRequest.setValue("application/json", forHTTPHeaderField: "Content-Type") + } + + urlRequest.httpBody = jsonData + + return urlRequest + } + + public static func encodingParameters(jsonData: Data?) -> Parameters? { + var returnedParams: Parameters? = nil + if let jsonData = jsonData, !jsonData.isEmpty { + var params = Parameters() + params[jsonDataKey] = jsonData + returnedParams = params + } + return returnedParams + } + +} diff --git a/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/JSONEncodingHelper.swift b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/JSONEncodingHelper.swift new file mode 100644 index 00000000000..4cf4ac206af --- /dev/null +++ b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/JSONEncodingHelper.swift @@ -0,0 +1,27 @@ +// +// JSONEncodingHelper.swift +// +// Generated by swagger-codegen +// https://github.com/swagger-api/swagger-codegen +// + +import Foundation +import Alamofire + +open class JSONEncodingHelper { + + open class func encodingParameters(forEncodableObject encodableObj: T?) -> Parameters? { + var params: Parameters? = nil + + // Encode the Encodable object + if let encodableObj = encodableObj { + let encodeResult = CodableHelper.encode(encodableObj, prettyPrint: true) + if encodeResult.error == nil { + params = JSONDataEncoding.encodingParameters(jsonData: encodeResult.data) + } + } + + return params + } + +} diff --git a/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models.swift b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models.swift new file mode 100644 index 00000000000..2c19b321582 --- /dev/null +++ b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models.swift @@ -0,0 +1,36 @@ +// Models.swift +// +// Generated by swagger-codegen +// https://github.com/swagger-api/swagger-codegen +// + +import Foundation + +protocol JSONEncodable { + func encodeToJSON() -> Any +} + +public enum ErrorResponse : Error { + case Error(Int, Data?, Error) +} + +open class Response { + open let statusCode: Int + open let header: [String: String] + open let body: T? + + public init(statusCode: Int, header: [String: String], body: T?) { + self.statusCode = statusCode + self.header = header + self.body = body + } + + public convenience init(response: HTTPURLResponse, body: T?) { + let rawHeader = response.allHeaderFields + var header = [String:String]() + for (key, value) in rawHeader { + header[key as! String] = value as? String + } + self.init(statusCode: response.statusCode, header: header, body: body) + } +} diff --git a/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/AdditionalPropertiesClass.swift b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/AdditionalPropertiesClass.swift new file mode 100644 index 00000000000..57e6d1f76e1 --- /dev/null +++ b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/AdditionalPropertiesClass.swift @@ -0,0 +1,42 @@ +// +// AdditionalPropertiesClass.swift +// +// Generated by swagger-codegen +// https://github.com/swagger-api/swagger-codegen +// + +import Foundation + + + +open class AdditionalPropertiesClass: Codable { + + public var mapProperty: [String:String]? + public var mapOfMapProperty: [String:[String:String]]? + + + 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) + + 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") + } +} + diff --git a/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/Animal.swift b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/Animal.swift new file mode 100644 index 00000000000..fd48bfb9b4c --- /dev/null +++ b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/Animal.swift @@ -0,0 +1,42 @@ +// +// Animal.swift +// +// Generated by swagger-codegen +// https://github.com/swagger-api/swagger-codegen +// + +import Foundation + + + +open class Animal: Codable { + + public var className: String + public var color: String? + + + 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) + + 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") + } +} + diff --git a/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/AnimalFarm.swift b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/AnimalFarm.swift new file mode 100644 index 00000000000..68308364894 --- /dev/null +++ b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/AnimalFarm.swift @@ -0,0 +1,11 @@ +// +// AnimalFarm.swift +// +// Generated by swagger-codegen +// https://github.com/swagger-api/swagger-codegen +// + +import Foundation + + +public typealias AnimalFarm = [Animal] diff --git a/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/ApiResponse.swift b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/ApiResponse.swift new file mode 100644 index 00000000000..179d2683331 --- /dev/null +++ b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/ApiResponse.swift @@ -0,0 +1,51 @@ +// +// ApiResponse.swift +// +// Generated by swagger-codegen +// https://github.com/swagger-api/swagger-codegen +// + +import Foundation + + + +open class ApiResponse: Codable { + + public var code: Int? + public var codeNum: NSNumber? { + get { + return code.map({ return NSNumber(value: $0) }) + } + } + public var type: String? + public var message: String? + + + 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) + + 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") + } +} + diff --git a/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/ArrayOfArrayOfNumberOnly.swift b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/ArrayOfArrayOfNumberOnly.swift new file mode 100644 index 00000000000..0b3c86516c4 --- /dev/null +++ b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/ArrayOfArrayOfNumberOnly.swift @@ -0,0 +1,38 @@ +// +// ArrayOfArrayOfNumberOnly.swift +// +// Generated by swagger-codegen +// https://github.com/swagger-api/swagger-codegen +// + +import Foundation + + + +open class ArrayOfArrayOfNumberOnly: Codable { + + public var arrayArrayNumber: [[Double]]? + + + public init(arrayArrayNumber: [[Double]]?) { + self.arrayArrayNumber = arrayArrayNumber + } + + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + 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") + } +} + diff --git a/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/ArrayOfNumberOnly.swift b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/ArrayOfNumberOnly.swift new file mode 100644 index 00000000000..733fda10ef4 --- /dev/null +++ b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/ArrayOfNumberOnly.swift @@ -0,0 +1,38 @@ +// +// ArrayOfNumberOnly.swift +// +// Generated by swagger-codegen +// https://github.com/swagger-api/swagger-codegen +// + +import Foundation + + + +open class ArrayOfNumberOnly: Codable { + + public var arrayNumber: [Double]? + + + public init(arrayNumber: [Double]?) { + self.arrayNumber = arrayNumber + } + + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + 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") + } +} + diff --git a/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/ArrayTest.swift b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/ArrayTest.swift new file mode 100644 index 00000000000..fd948816d28 --- /dev/null +++ b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/ArrayTest.swift @@ -0,0 +1,46 @@ +// +// ArrayTest.swift +// +// Generated by swagger-codegen +// https://github.com/swagger-api/swagger-codegen +// + +import Foundation + + + +open class ArrayTest: Codable { + + public var arrayOfString: [String]? + public var arrayArrayOfInteger: [[Int64]]? + public var arrayArrayOfModel: [[ReadOnlyFirst]]? + + + public init(arrayOfString: [String]?, arrayArrayOfInteger: [[Int64]]?, arrayArrayOfModel: [[ReadOnlyFirst]]?) { + self.arrayOfString = arrayOfString + self.arrayArrayOfInteger = arrayArrayOfInteger + self.arrayArrayOfModel = arrayArrayOfModel + } + + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encodeArrayIfPresent(arrayOfString, forKey: "array_of_string") + try container.encodeArrayIfPresent(arrayArrayOfInteger, forKey: "array_array_of_integer") + try container.encodeArrayIfPresent(arrayArrayOfModel, forKey: "array_array_of_model") + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + arrayOfString = try container.decodeArrayIfPresent(String.self, forKey: "array_of_string") + arrayArrayOfInteger = try container.decodeArrayIfPresent([Int64].self, forKey: "array_array_of_integer") + arrayArrayOfModel = try container.decodeArrayIfPresent([ReadOnlyFirst].self, forKey: "array_array_of_model") + } +} + diff --git a/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/Capitalization.swift b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/Capitalization.swift new file mode 100644 index 00000000000..32ea816610e --- /dev/null +++ b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/Capitalization.swift @@ -0,0 +1,59 @@ +// +// Capitalization.swift +// +// Generated by swagger-codegen +// https://github.com/swagger-api/swagger-codegen +// + +import Foundation + + + +open class Capitalization: Codable { + + 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(smallCamel: String?, capitalCamel: String?, smallSnake: String?, capitalSnake: String?, sCAETHFlowPoints: String?, ATT_NAME: String?) { + self.smallCamel = smallCamel + self.capitalCamel = capitalCamel + self.smallSnake = smallSnake + self.capitalSnake = capitalSnake + self.sCAETHFlowPoints = sCAETHFlowPoints + self.ATT_NAME = ATT_NAME + } + + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encodeIfPresent(smallCamel, forKey: "smallCamel") + try container.encodeIfPresent(capitalCamel, forKey: "CapitalCamel") + try container.encodeIfPresent(smallSnake, forKey: "small_Snake") + try container.encodeIfPresent(capitalSnake, forKey: "Capital_Snake") + try container.encodeIfPresent(sCAETHFlowPoints, forKey: "SCA_ETH_Flow_Points") + try container.encodeIfPresent(ATT_NAME, forKey: "ATT_NAME") + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + smallCamel = try container.decodeIfPresent(String.self, forKey: "smallCamel") + capitalCamel = try container.decodeIfPresent(String.self, forKey: "CapitalCamel") + smallSnake = try container.decodeIfPresent(String.self, forKey: "small_Snake") + capitalSnake = try container.decodeIfPresent(String.self, forKey: "Capital_Snake") + sCAETHFlowPoints = try container.decodeIfPresent(String.self, forKey: "SCA_ETH_Flow_Points") + ATT_NAME = try container.decodeIfPresent(String.self, forKey: "ATT_NAME") + } +} + diff --git a/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/Cat.swift b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/Cat.swift new file mode 100644 index 00000000000..95dc0e89fed --- /dev/null +++ b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/Cat.swift @@ -0,0 +1,43 @@ +// +// 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) }) + } + } + + + public init(declawed: Bool?) { + self.declawed = declawed + } + + // Encodable protocol methods + + public override func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encodeIfPresent(declawed, forKey: "declawed") + } + + // Decodable protocol methods + + public override required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + declawed = try container.decodeIfPresent(Bool.self, forKey: "declawed") + } +} + diff --git a/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/Category.swift b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/Category.swift new file mode 100644 index 00000000000..86f3f99f359 --- /dev/null +++ b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/Category.swift @@ -0,0 +1,47 @@ +// +// Category.swift +// +// Generated by swagger-codegen +// https://github.com/swagger-api/swagger-codegen +// + +import Foundation + + + +open class Category: Codable { + + public var id: Int64? + public var idNum: NSNumber? { + get { + return id.map({ return NSNumber(value: $0) }) + } + } + public var name: String? + + + public init(id: Int64?, name: String?) { + self.id = id + self.name = name + } + + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encodeIfPresent(id, forKey: "id") + try container.encodeIfPresent(name, forKey: "name") + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + id = try container.decodeIfPresent(Int64.self, forKey: "id") + name = try container.decodeIfPresent(String.self, forKey: "name") + } +} + diff --git a/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/ClassModel.swift b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/ClassModel.swift new file mode 100644 index 00000000000..8d80e263370 --- /dev/null +++ b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/ClassModel.swift @@ -0,0 +1,39 @@ +// +// 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: Codable { + + public var _class: String? + + + public init(_class: String?) { + self._class = _class + } + + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encodeIfPresent(_class, forKey: "_class") + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + _class = try container.decodeIfPresent(String.self, forKey: "_class") + } +} + diff --git a/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/Client.swift b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/Client.swift new file mode 100644 index 00000000000..3a74788606b --- /dev/null +++ b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/Client.swift @@ -0,0 +1,38 @@ +// +// Client.swift +// +// Generated by swagger-codegen +// https://github.com/swagger-api/swagger-codegen +// + +import Foundation + + + +open class Client: Codable { + + public var client: String? + + + public init(client: String?) { + self.client = client + } + + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encodeIfPresent(client, forKey: "client") + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + client = try container.decodeIfPresent(String.self, forKey: "client") + } +} + diff --git a/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/Dog.swift b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/Dog.swift new file mode 100644 index 00000000000..2835af6b0f9 --- /dev/null +++ b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/Dog.swift @@ -0,0 +1,38 @@ +// +// Dog.swift +// +// Generated by swagger-codegen +// https://github.com/swagger-api/swagger-codegen +// + +import Foundation + + + +open class Dog: Animal { + + public var breed: String? + + + public init(breed: String?) { + self.breed = breed + } + + // Encodable protocol methods + + public override func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encodeIfPresent(breed, forKey: "breed") + } + + // Decodable protocol methods + + public override required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + breed = try container.decodeIfPresent(String.self, forKey: "breed") + } +} + diff --git a/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/EnumArrays.swift b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/EnumArrays.swift new file mode 100644 index 00000000000..bb7960a7577 --- /dev/null +++ b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/EnumArrays.swift @@ -0,0 +1,50 @@ +// +// EnumArrays.swift +// +// Generated by swagger-codegen +// https://github.com/swagger-api/swagger-codegen +// + +import Foundation + + + +open class EnumArrays: Codable { + + public enum JustSymbol: String, Codable { + case greaterThanOrEqualTo = ">=" + case dollar = "$" + } + public enum ArrayEnum: String, Codable { + case fish = "fish" + case crab = "crab" + } + public var justSymbol: JustSymbol? + public var arrayEnum: [ArrayEnum]? + + + public init(justSymbol: JustSymbol?, arrayEnum: [ArrayEnum]?) { + self.justSymbol = justSymbol + self.arrayEnum = arrayEnum + } + + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encodeIfPresent(justSymbol, forKey: "just_symbol") + try container.encodeArrayIfPresent(arrayEnum, forKey: "array_enum") + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + justSymbol = try container.decodeIfPresent(String.self, forKey: "just_symbol") + arrayEnum = try container.decodeArrayIfPresent(String.self, forKey: "array_enum") + } +} + diff --git a/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/EnumClass.swift b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/EnumClass.swift new file mode 100644 index 00000000000..d0889a3520a --- /dev/null +++ b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/EnumClass.swift @@ -0,0 +1,16 @@ +// +// EnumClass.swift +// +// Generated by swagger-codegen +// https://github.com/swagger-api/swagger-codegen +// + +import Foundation + + +public enum EnumClass: String, Codable { + case abc = "_abc" + case efg = "-efg" + case xyz = "(xyz)" + +} diff --git a/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/EnumTest.swift b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/EnumTest.swift new file mode 100644 index 00000000000..023f9a8209c --- /dev/null +++ b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/EnumTest.swift @@ -0,0 +1,63 @@ +// +// EnumTest.swift +// +// Generated by swagger-codegen +// https://github.com/swagger-api/swagger-codegen +// + +import Foundation + + + +open class EnumTest: Codable { + + public enum EnumString: String, Codable { + case upper = "UPPER" + case lower = "lower" + case empty = "" + } + public enum EnumInteger: Int, Codable { + case _1 = 1 + case number1 = -1 + } + public enum EnumNumber: Double, Codable { + 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(enumString: EnumString?, enumInteger: EnumInteger?, enumNumber: EnumNumber?, outerEnum: OuterEnum?) { + self.enumString = enumString + self.enumInteger = enumInteger + self.enumNumber = enumNumber + self.outerEnum = outerEnum + } + + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encodeIfPresent(enumString, forKey: "enum_string") + try container.encodeIfPresent(enumInteger, forKey: "enum_integer") + try container.encodeIfPresent(enumNumber, forKey: "enum_number") + try container.encodeIfPresent(outerEnum, forKey: "outerEnum") + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + enumString = try container.decodeIfPresent(String.self, forKey: "enum_string") + enumInteger = try container.decodeIfPresent(Int.self, forKey: "enum_integer") + enumNumber = try container.decodeIfPresent(Double.self, forKey: "enum_number") + outerEnum = try container.decodeIfPresent(OuterEnum.self, forKey: "outerEnum") + } +} + diff --git a/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/FormatTest.swift b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/FormatTest.swift new file mode 100644 index 00000000000..a59ece71da9 --- /dev/null +++ b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/FormatTest.swift @@ -0,0 +1,116 @@ +// +// FormatTest.swift +// +// Generated by swagger-codegen +// https://github.com/swagger-api/swagger-codegen +// + +import Foundation + + + +open class FormatTest: Codable { + + public var integer: Int? + public var integerNum: NSNumber? { + get { + return integer.map({ return NSNumber(value: $0) }) + } + } + public var int32: Int? + 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: Date + public var dateTime: Date? + public var uuid: UUID? + public var password: String + + + public init(integer: Int?, int32: Int?, int64: Int64?, number: Double, float: Float?, double: Double?, string: String?, byte: Data, binary: Data?, date: Date, dateTime: Date?, uuid: UUID?, password: String) { + self.integer = integer + self.int32 = int32 + self.int64 = int64 + self.number = number + self.float = float + self.double = double + self.string = string + self.byte = byte + self.binary = binary + self.date = date + self.dateTime = dateTime + self.uuid = uuid + self.password = password + } + + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encodeIfPresent(integer, forKey: "integer") + try container.encodeIfPresent(int32, forKey: "int32") + try container.encodeIfPresent(int64, forKey: "int64") + try container.encode(number, forKey: "number") + try container.encodeIfPresent(float, forKey: "float") + try container.encodeIfPresent(double, forKey: "double") + try container.encodeIfPresent(string, forKey: "string") + try container.encode(byte, forKey: "byte") + try container.encodeIfPresent(binary, forKey: "binary") + try container.encode(date, forKey: "date") + try container.encodeIfPresent(dateTime, forKey: "dateTime") + try container.encodeIfPresent(uuid, forKey: "uuid") + try container.encode(password, forKey: "password") + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + integer = try container.decodeIfPresent(Int.self, forKey: "integer") + int32 = try container.decodeIfPresent(Int.self, forKey: "int32") + int64 = try container.decodeIfPresent(Int64.self, forKey: "int64") + number = try container.decode(Double.self, forKey: "number") + float = try container.decodeIfPresent(Float.self, forKey: "float") + double = try container.decodeIfPresent(Double.self, forKey: "double") + string = try container.decodeIfPresent(String.self, forKey: "string") + byte = try container.decode(Data.self, forKey: "byte") + binary = try container.decodeIfPresent(Data.self, forKey: "binary") + date = try container.decode(Date.self, forKey: "date") + dateTime = try container.decodeIfPresent(Date.self, forKey: "dateTime") + uuid = try container.decodeIfPresent(UUID.self, forKey: "uuid") + password = try container.decode(String.self, forKey: "password") + } +} + diff --git a/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/HasOnlyReadOnly.swift b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/HasOnlyReadOnly.swift new file mode 100644 index 00000000000..226ffe44b08 --- /dev/null +++ b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/HasOnlyReadOnly.swift @@ -0,0 +1,42 @@ +// +// HasOnlyReadOnly.swift +// +// Generated by swagger-codegen +// https://github.com/swagger-api/swagger-codegen +// + +import Foundation + + + +open class HasOnlyReadOnly: Codable { + + public var bar: String? + public var foo: String? + + + public init(bar: String?, foo: String?) { + self.bar = bar + self.foo = foo + } + + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encodeIfPresent(bar, forKey: "bar") + try container.encodeIfPresent(foo, forKey: "foo") + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + bar = try container.decodeIfPresent(String.self, forKey: "bar") + foo = try container.decodeIfPresent(String.self, forKey: "foo") + } +} + diff --git a/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/List.swift b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/List.swift new file mode 100644 index 00000000000..5f4068ffbeb --- /dev/null +++ b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/List.swift @@ -0,0 +1,38 @@ +// +// List.swift +// +// Generated by swagger-codegen +// https://github.com/swagger-api/swagger-codegen +// + +import Foundation + + + +open class List: Codable { + + public var _123List: String? + + + public init(_123List: String?) { + self._123List = _123List + } + + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encodeIfPresent(_123List, forKey: "123-list") + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + _123List = try container.decodeIfPresent(String.self, forKey: "123-list") + } +} + diff --git a/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/MapTest.swift b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/MapTest.swift new file mode 100644 index 00000000000..36f31fc1a44 --- /dev/null +++ b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/MapTest.swift @@ -0,0 +1,46 @@ +// +// MapTest.swift +// +// Generated by swagger-codegen +// https://github.com/swagger-api/swagger-codegen +// + +import Foundation + + + +open class MapTest: Codable { + + public enum MapOfEnumString: String, Codable { + case upper = "UPPER" + case lower = "lower" + } + public var mapMapOfString: [String:[String:String]]? + public var mapOfEnumString: [String:String]? + + + public init(mapMapOfString: [String:[String:String]]?, mapOfEnumString: [String:String]?) { + self.mapMapOfString = mapMapOfString + self.mapOfEnumString = mapOfEnumString + } + + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encodeIfPresent(mapMapOfString, forKey: "map_map_of_string") + try container.encodeIfPresent(mapOfEnumString, forKey: "map_of_enum_string") + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + mapMapOfString = try container.decodeIfPresent([String:[String:String]].self, forKey: "map_map_of_string") + mapOfEnumString = try container.decodeIfPresent([String:String].self, forKey: "map_of_enum_string") + } +} + diff --git a/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/MixedPropertiesAndAdditionalPropertiesClass.swift b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/MixedPropertiesAndAdditionalPropertiesClass.swift new file mode 100644 index 00000000000..0f475c175d2 --- /dev/null +++ b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/MixedPropertiesAndAdditionalPropertiesClass.swift @@ -0,0 +1,46 @@ +// +// MixedPropertiesAndAdditionalPropertiesClass.swift +// +// Generated by swagger-codegen +// https://github.com/swagger-api/swagger-codegen +// + +import Foundation + + + +open class MixedPropertiesAndAdditionalPropertiesClass: Codable { + + public var uuid: UUID? + public var dateTime: Date? + public var map: [String:Animal]? + + + public init(uuid: UUID?, dateTime: Date?, map: [String:Animal]?) { + self.uuid = uuid + self.dateTime = dateTime + self.map = map + } + + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encodeIfPresent(uuid, forKey: "uuid") + try container.encodeIfPresent(dateTime, forKey: "dateTime") + try container.encodeIfPresent(map, forKey: "map") + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + uuid = try container.decodeIfPresent(UUID.self, forKey: "uuid") + dateTime = try container.decodeIfPresent(Date.self, forKey: "dateTime") + map = try container.decodeIfPresent([String:Animal].self, forKey: "map") + } +} + diff --git a/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/Model200Response.swift b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/Model200Response.swift new file mode 100644 index 00000000000..770fff458c3 --- /dev/null +++ b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/Model200Response.swift @@ -0,0 +1,48 @@ +// +// 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: Codable { + + public var name: Int? + public var nameNum: NSNumber? { + get { + return name.map({ return NSNumber(value: $0) }) + } + } + public var _class: String? + + + public init(name: Int?, _class: String?) { + self.name = name + self._class = _class + } + + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encodeIfPresent(name, forKey: "name") + try container.encodeIfPresent(_class, forKey: "class") + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + name = try container.decodeIfPresent(Int.self, forKey: "name") + _class = try container.decodeIfPresent(String.self, forKey: "class") + } +} + diff --git a/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/Name.swift b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/Name.swift new file mode 100644 index 00000000000..87d61fd934a --- /dev/null +++ b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/Name.swift @@ -0,0 +1,66 @@ +// +// 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: Codable { + + public var name: Int + public var nameNum: NSNumber? { + get { + return name.map({ return NSNumber(value: $0) }) + } + } + public var snakeCase: Int? + public var snakeCaseNum: NSNumber? { + get { + return snakeCase.map({ return NSNumber(value: $0) }) + } + } + public var property: String? + public var _123Number: Int? + public var _123NumberNum: NSNumber? { + get { + return _123Number.map({ return NSNumber(value: $0) }) + } + } + + + public init(name: Int, snakeCase: Int?, property: String?, _123Number: Int?) { + self.name = name + self.snakeCase = snakeCase + self.property = property + self._123Number = _123Number + } + + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encode(name, forKey: "name") + try container.encodeIfPresent(snakeCase, forKey: "snake_case") + try container.encodeIfPresent(property, forKey: "property") + try container.encodeIfPresent(_123Number, forKey: "123Number") + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + name = try container.decode(Int.self, forKey: "name") + snakeCase = try container.decodeIfPresent(Int.self, forKey: "snake_case") + property = try container.decodeIfPresent(String.self, forKey: "property") + _123Number = try container.decodeIfPresent(Int.self, forKey: "123Number") + } +} + diff --git a/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/NumberOnly.swift b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/NumberOnly.swift new file mode 100644 index 00000000000..70d1c4bc178 --- /dev/null +++ b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/NumberOnly.swift @@ -0,0 +1,43 @@ +// +// NumberOnly.swift +// +// Generated by swagger-codegen +// https://github.com/swagger-api/swagger-codegen +// + +import Foundation + + + +open class NumberOnly: Codable { + + public var justNumber: Double? + public var justNumberNum: NSNumber? { + get { + return justNumber.map({ return NSNumber(value: $0) }) + } + } + + + public init(justNumber: Double?) { + self.justNumber = justNumber + } + + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encodeIfPresent(justNumber, forKey: "JustNumber") + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + justNumber = try container.decodeIfPresent(Double.self, forKey: "JustNumber") + } +} + diff --git a/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/Order.swift b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/Order.swift new file mode 100644 index 00000000000..cc8e7676973 --- /dev/null +++ b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/Order.swift @@ -0,0 +1,84 @@ +// +// Order.swift +// +// Generated by swagger-codegen +// https://github.com/swagger-api/swagger-codegen +// + +import Foundation + + + +open class Order: Codable { + + public enum Status: String, Codable { + 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: Int? + 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(id: Int64?, petId: Int64?, quantity: Int?, shipDate: Date?, status: Status?, complete: Bool?) { + self.id = id + self.petId = petId + self.quantity = quantity + self.shipDate = shipDate + self.status = status + self.complete = complete + } + + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encodeIfPresent(id, forKey: "id") + try container.encodeIfPresent(petId, forKey: "petId") + try container.encodeIfPresent(quantity, forKey: "quantity") + try container.encodeIfPresent(shipDate, forKey: "shipDate") + try container.encodeIfPresent(status, forKey: "status") + try container.encodeIfPresent(complete, forKey: "complete") + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + id = try container.decodeIfPresent(Int64.self, forKey: "id") + petId = try container.decodeIfPresent(Int64.self, forKey: "petId") + quantity = try container.decodeIfPresent(Int.self, forKey: "quantity") + shipDate = try container.decodeIfPresent(Date.self, forKey: "shipDate") + status = try container.decodeIfPresent(String.self, forKey: "status") + complete = try container.decodeIfPresent(Bool.self, forKey: "complete") + } +} + diff --git a/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/OuterBoolean.swift b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/OuterBoolean.swift new file mode 100644 index 00000000000..ce257737983 --- /dev/null +++ b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/OuterBoolean.swift @@ -0,0 +1,32 @@ +// +// OuterBoolean.swift +// +// Generated by swagger-codegen +// https://github.com/swagger-api/swagger-codegen +// + +import Foundation + + + +open class OuterBoolean: Codable { + + + + + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + } +} + diff --git a/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/OuterComposite.swift b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/OuterComposite.swift new file mode 100644 index 00000000000..cf46c19e7f1 --- /dev/null +++ b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/OuterComposite.swift @@ -0,0 +1,46 @@ +// +// OuterComposite.swift +// +// Generated by swagger-codegen +// https://github.com/swagger-api/swagger-codegen +// + +import Foundation + + + +open class OuterComposite: Codable { + + public var myNumber: OuterNumber? + public var myString: OuterString? + public var myBoolean: OuterBoolean? + + + public init(myNumber: OuterNumber?, myString: OuterString?, myBoolean: OuterBoolean?) { + self.myNumber = myNumber + self.myString = myString + self.myBoolean = myBoolean + } + + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encodeIfPresent(myNumber, forKey: "my_number") + try container.encodeIfPresent(myString, forKey: "my_string") + try container.encodeIfPresent(myBoolean, forKey: "my_boolean") + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + myNumber = try container.decodeIfPresent(OuterNumber.self, forKey: "my_number") + myString = try container.decodeIfPresent(OuterString.self, forKey: "my_string") + myBoolean = try container.decodeIfPresent(OuterBoolean.self, forKey: "my_boolean") + } +} + diff --git a/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/OuterEnum.swift b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/OuterEnum.swift new file mode 100644 index 00000000000..d6222d2b1c4 --- /dev/null +++ b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/OuterEnum.swift @@ -0,0 +1,16 @@ +// +// OuterEnum.swift +// +// Generated by swagger-codegen +// https://github.com/swagger-api/swagger-codegen +// + +import Foundation + + +public enum OuterEnum: String, Codable { + case placed = "placed" + case approved = "approved" + case delivered = "delivered" + +} diff --git a/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/OuterNumber.swift b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/OuterNumber.swift new file mode 100644 index 00000000000..3cd67121150 --- /dev/null +++ b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/OuterNumber.swift @@ -0,0 +1,32 @@ +// +// OuterNumber.swift +// +// Generated by swagger-codegen +// https://github.com/swagger-api/swagger-codegen +// + +import Foundation + + + +open class OuterNumber: Codable { + + + + + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + } +} + diff --git a/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/OuterString.swift b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/OuterString.swift new file mode 100644 index 00000000000..0d9f059b91c --- /dev/null +++ b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/OuterString.swift @@ -0,0 +1,32 @@ +// +// OuterString.swift +// +// Generated by swagger-codegen +// https://github.com/swagger-api/swagger-codegen +// + +import Foundation + + + +open class OuterString: Codable { + + + + + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + } +} + diff --git a/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/Pet.swift b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/Pet.swift new file mode 100644 index 00000000000..4554246b888 --- /dev/null +++ b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/Pet.swift @@ -0,0 +1,69 @@ +// +// Pet.swift +// +// Generated by swagger-codegen +// https://github.com/swagger-api/swagger-codegen +// + +import Foundation + + + +open class Pet: Codable { + + public enum Status: String, Codable { + 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(id: Int64?, category: Category?, name: String, photoUrls: [String], tags: [Tag]?, status: Status?) { + self.id = id + self.category = category + self.name = name + self.photoUrls = photoUrls + self.tags = tags + self.status = status + } + + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encodeIfPresent(id, forKey: "id") + try container.encodeIfPresent(category, forKey: "category") + try container.encode(name, forKey: "name") + try container.encodeArray(photoUrls, forKey: "photoUrls") + try container.encodeArrayIfPresent(tags, forKey: "tags") + try container.encodeIfPresent(status, forKey: "status") + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + id = try container.decodeIfPresent(Int64.self, forKey: "id") + category = try container.decodeIfPresent(Category.self, forKey: "category") + name = try container.decode(String.self, forKey: "name") + photoUrls = try container.decodeArray(String.self, forKey: "photoUrls") + tags = try container.decodeArrayIfPresent(Tag.self, forKey: "tags") + status = try container.decodeIfPresent(String.self, forKey: "status") + } +} + diff --git a/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/ReadOnlyFirst.swift b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/ReadOnlyFirst.swift new file mode 100644 index 00000000000..e608e6845b2 --- /dev/null +++ b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/ReadOnlyFirst.swift @@ -0,0 +1,42 @@ +// +// ReadOnlyFirst.swift +// +// Generated by swagger-codegen +// https://github.com/swagger-api/swagger-codegen +// + +import Foundation + + + +open class ReadOnlyFirst: Codable { + + public var bar: String? + public var baz: String? + + + public init(bar: String?, baz: String?) { + self.bar = bar + self.baz = baz + } + + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encodeIfPresent(bar, forKey: "bar") + try container.encodeIfPresent(baz, forKey: "baz") + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + bar = try container.decodeIfPresent(String.self, forKey: "bar") + baz = try container.decodeIfPresent(String.self, forKey: "baz") + } +} + diff --git a/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/Return.swift b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/Return.swift new file mode 100644 index 00000000000..842500cc9e2 --- /dev/null +++ b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/Return.swift @@ -0,0 +1,44 @@ +// +// Return.swift +// +// Generated by swagger-codegen +// https://github.com/swagger-api/swagger-codegen +// + +import Foundation + + +/** Model for testing reserved words */ + +open class Return: Codable { + + public var _return: Int? + public var _returnNum: NSNumber? { + get { + return _return.map({ return NSNumber(value: $0) }) + } + } + + + public init(_return: Int?) { + self._return = _return + } + + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encodeIfPresent(_return, forKey: "return") + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + _return = try container.decodeIfPresent(Int.self, forKey: "return") + } +} + diff --git a/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/SpecialModelName.swift b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/SpecialModelName.swift new file mode 100644 index 00000000000..3038695b3bd --- /dev/null +++ b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/SpecialModelName.swift @@ -0,0 +1,43 @@ +// +// SpecialModelName.swift +// +// Generated by swagger-codegen +// https://github.com/swagger-api/swagger-codegen +// + +import Foundation + + + +open class SpecialModelName: Codable { + + public var specialPropertyName: Int64? + public var specialPropertyNameNum: NSNumber? { + get { + return specialPropertyName.map({ return NSNumber(value: $0) }) + } + } + + + public init(specialPropertyName: Int64?) { + self.specialPropertyName = specialPropertyName + } + + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encodeIfPresent(specialPropertyName, forKey: "$special[property.name]") + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + specialPropertyName = try container.decodeIfPresent(Int64.self, forKey: "$special[property.name]") + } +} + diff --git a/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/Tag.swift b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/Tag.swift new file mode 100644 index 00000000000..ff0a3f30cfd --- /dev/null +++ b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/Tag.swift @@ -0,0 +1,47 @@ +// +// Tag.swift +// +// Generated by swagger-codegen +// https://github.com/swagger-api/swagger-codegen +// + +import Foundation + + + +open class Tag: Codable { + + public var id: Int64? + public var idNum: NSNumber? { + get { + return id.map({ return NSNumber(value: $0) }) + } + } + public var name: String? + + + public init(id: Int64?, name: String?) { + self.id = id + self.name = name + } + + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encodeIfPresent(id, forKey: "id") + try container.encodeIfPresent(name, forKey: "name") + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + id = try container.decodeIfPresent(Int64.self, forKey: "id") + name = try container.decodeIfPresent(String.self, forKey: "name") + } +} + diff --git a/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/User.swift b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/User.swift new file mode 100644 index 00000000000..dc81aff50a1 --- /dev/null +++ b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/Swaggers/Models/User.swift @@ -0,0 +1,77 @@ +// +// User.swift +// +// Generated by swagger-codegen +// https://github.com/swagger-api/swagger-codegen +// + +import Foundation + + + +open class User: Codable { + + 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: Int? + public var userStatusNum: NSNumber? { + get { + return userStatus.map({ return NSNumber(value: $0) }) + } + } + + + public init(id: Int64?, username: String?, firstName: String?, lastName: String?, email: String?, password: String?, phone: String?, userStatus: Int?) { + self.id = id + self.username = username + self.firstName = firstName + self.lastName = lastName + self.email = email + self.password = password + self.phone = phone + self.userStatus = userStatus + } + + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encodeIfPresent(id, forKey: "id") + try container.encodeIfPresent(username, forKey: "username") + try container.encodeIfPresent(firstName, forKey: "firstName") + try container.encodeIfPresent(lastName, forKey: "lastName") + try container.encodeIfPresent(email, forKey: "email") + try container.encodeIfPresent(password, forKey: "password") + try container.encodeIfPresent(phone, forKey: "phone") + try container.encodeIfPresent(userStatus, forKey: "userStatus") + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + id = try container.decodeIfPresent(Int64.self, forKey: "id") + username = try container.decodeIfPresent(String.self, forKey: "username") + firstName = try container.decodeIfPresent(String.self, forKey: "firstName") + lastName = try container.decodeIfPresent(String.self, forKey: "lastName") + email = try container.decodeIfPresent(String.self, forKey: "email") + password = try container.decodeIfPresent(String.self, forKey: "password") + phone = try container.decodeIfPresent(String.self, forKey: "phone") + userStatus = try container.decodeIfPresent(Int.self, forKey: "userStatus") + } +} + diff --git a/samples/client/petstore/swift4/objcCompatible/git_push.sh b/samples/client/petstore/swift4/objcCompatible/git_push.sh new file mode 100644 index 00000000000..ed374619b13 --- /dev/null +++ b/samples/client/petstore/swift4/objcCompatible/git_push.sh @@ -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' + diff --git a/samples/client/petstore/swift4/promisekit/PetstoreClient.podspec b/samples/client/petstore/swift4/promisekit/PetstoreClient.podspec index c7fe7969a40..586be868c71 100644 --- a/samples/client/petstore/swift4/promisekit/PetstoreClient.podspec +++ b/samples/client/petstore/swift4/promisekit/PetstoreClient.podspec @@ -10,5 +10,5 @@ Pod::Spec.new do |s| s.summary = 'PetstoreClient' s.source_files = 'PetstoreClient/Classes/**/*.swift' s.dependency 'PromiseKit/CorePromise', '~> 4.4.0' - s.dependency 'Alamofire', '~> 4.5' + s.dependency 'Alamofire', '~> 4.5.0' end diff --git a/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/APIs/AnotherfakeAPI.swift b/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/APIs/AnotherfakeAPI.swift new file mode 100644 index 00000000000..c0ef57a2874 --- /dev/null +++ b/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/APIs/AnotherfakeAPI.swift @@ -0,0 +1,70 @@ +// +// AnotherfakeAPI.swift +// +// Generated by swagger-codegen +// https://github.com/swagger-api/swagger-codegen +// + +import Foundation +import Alamofire +import PromiseKit + + + +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 + + - parameter body: (body) client model + - returns: Promise + */ + open class func testSpecialTags( body: Client) -> Promise { + let deferred = Promise.pending() + testSpecialTags(body: body) { data, error in + if let error = error { + deferred.reject(error) + } else { + deferred.fulfill(data!) + } + } + return deferred.promise + } + + /** + 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 + */ + open class func testSpecialTagsWithRequestBuilder(body: Client) -> RequestBuilder { + let path = "/another-fake/dummy" + let URLString = PetstoreClientAPI.basePath + path + let parameters = JSONEncodingHelper.encodingParameters(forEncodableObject: body) + + let url = NSURLComponents(string: URLString) + + + let requestBuilder: RequestBuilder.Type = PetstoreClientAPI.requestBuilderFactory.getBuilder() + + return requestBuilder.init(method: "PATCH", URLString: (url?.string ?? URLString), parameters: parameters, isBody: true) + } + +} diff --git a/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/APIs/FakeAPI.swift b/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/APIs/FakeAPI.swift index faf17cc514d..2716cd9834b 100644 --- a/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/APIs/FakeAPI.swift +++ b/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/APIs/FakeAPI.swift @@ -439,7 +439,7 @@ open class FakeAPI { */ public enum EnumQueryInteger_testEnumParameters: Int { case _1 = 1 - case numberminus2 = -2 + case number2 = -2 } /** @@ -447,7 +447,7 @@ open class FakeAPI { */ public enum EnumQueryDouble_testEnumParameters: Double { case _11 = 1.1 - case numberminus12 = -1.2 + case number12 = -1.2 } /** diff --git a/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Extensions.swift b/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Extensions.swift index d672b1f7993..31d63e53fe6 100644 --- a/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Extensions.swift +++ b/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Extensions.swift @@ -85,6 +85,92 @@ 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(_ values: [T], forKey key: Self.Key) throws where T : Encodable { + var arrayContainer = nestedUnkeyedContainer(forKey: key) + try arrayContainer.encode(contentsOf: values) + } + + public mutating func encodeArrayIfPresent(_ values: [T]?, forKey key: Self.Key) throws where T : Encodable { + if let values = values { + try encodeArray(values, forKey: key) + } + } + + public mutating func encodeMap(_ pairs: [Self.Key: T]) throws where T : Encodable { + for (key, value) in pairs { + try encode(value, forKey: key) + } + } + + public mutating func encodeMapIfPresent(_ pairs: [Self.Key: T]?) throws where T : Encodable { + if let pairs = pairs { + try encodeMap(pairs) + } + } + +} + +extension KeyedDecodingContainerProtocol { + + public func decodeArray(_ 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(_ 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(_ type: T.Type, excludedKeys: Set) 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 + } + +} + extension RequestBuilder { public func execute() -> Promise> { let deferred = Promise>.pending() diff --git a/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/AdditionalPropertiesClass.swift b/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/AdditionalPropertiesClass.swift index b18644a34e3..57e6d1f76e1 100644 --- a/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/AdditionalPropertiesClass.swift +++ b/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/AdditionalPropertiesClass.swift @@ -8,17 +8,35 @@ import Foundation + open class AdditionalPropertiesClass: Codable { public var mapProperty: [String:String]? public var mapOfMapProperty: [String:[String:String]]? - public init() {} - - private enum CodingKeys: String, CodingKey { - case mapProperty = "map_property" - case mapOfMapProperty = "map_of_map_property" + 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) + + 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") + } } + diff --git a/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/Animal.swift b/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/Animal.swift index 1c0cc68a298..fd48bfb9b4c 100644 --- a/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/Animal.swift +++ b/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/Animal.swift @@ -8,17 +8,35 @@ import Foundation + open class Animal: Codable { - public var className: String? + public var className: String public var color: String? - public init() {} - - private enum CodingKeys: String, CodingKey { - case className = "className" - case color = "color" + 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) + + 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") + } } + diff --git a/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/ApiResponse.swift b/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/ApiResponse.swift index 842755fb3c4..de8b7ec6ebd 100644 --- a/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/ApiResponse.swift +++ b/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/ApiResponse.swift @@ -8,19 +8,39 @@ import Foundation + open class ApiResponse: Codable { public var code: Int? public var type: String? public var message: String? - public init() {} - - private enum CodingKeys: String, CodingKey { - case code = "code" - case type = "type" - case message = "message" + 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) + + 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") + } } + diff --git a/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/ArrayOfArrayOfNumberOnly.swift b/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/ArrayOfArrayOfNumberOnly.swift index 9f7ee34099c..0b3c86516c4 100644 --- a/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/ArrayOfArrayOfNumberOnly.swift +++ b/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/ArrayOfArrayOfNumberOnly.swift @@ -8,15 +8,31 @@ import Foundation + open class ArrayOfArrayOfNumberOnly: Codable { public var arrayArrayNumber: [[Double]]? - public init() {} - - private enum CodingKeys: String, CodingKey { - case arrayArrayNumber = "ArrayArrayNumber" + public init(arrayArrayNumber: [[Double]]?) { + self.arrayArrayNumber = arrayArrayNumber } + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + 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") + } } + diff --git a/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/ArrayOfNumberOnly.swift b/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/ArrayOfNumberOnly.swift index fba11ceb708..733fda10ef4 100644 --- a/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/ArrayOfNumberOnly.swift +++ b/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/ArrayOfNumberOnly.swift @@ -8,15 +8,31 @@ import Foundation + open class ArrayOfNumberOnly: Codable { public var arrayNumber: [Double]? - public init() {} - - private enum CodingKeys: String, CodingKey { - case arrayNumber = "ArrayNumber" + public init(arrayNumber: [Double]?) { + self.arrayNumber = arrayNumber } + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + 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") + } } + diff --git a/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/ArrayTest.swift b/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/ArrayTest.swift index bdf244f5e0a..fd948816d28 100644 --- a/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/ArrayTest.swift +++ b/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/ArrayTest.swift @@ -8,19 +8,39 @@ import Foundation + open class ArrayTest: Codable { public var arrayOfString: [String]? public var arrayArrayOfInteger: [[Int64]]? public var arrayArrayOfModel: [[ReadOnlyFirst]]? - public init() {} - - private enum CodingKeys: String, CodingKey { - case arrayOfString = "array_of_string" - case arrayArrayOfInteger = "array_array_of_integer" - case arrayArrayOfModel = "array_array_of_model" + public init(arrayOfString: [String]?, arrayArrayOfInteger: [[Int64]]?, arrayArrayOfModel: [[ReadOnlyFirst]]?) { + self.arrayOfString = arrayOfString + self.arrayArrayOfInteger = arrayArrayOfInteger + self.arrayArrayOfModel = arrayArrayOfModel } + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encodeArrayIfPresent(arrayOfString, forKey: "array_of_string") + try container.encodeArrayIfPresent(arrayArrayOfInteger, forKey: "array_array_of_integer") + try container.encodeArrayIfPresent(arrayArrayOfModel, forKey: "array_array_of_model") + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + arrayOfString = try container.decodeArrayIfPresent(String.self, forKey: "array_of_string") + arrayArrayOfInteger = try container.decodeArrayIfPresent([Int64].self, forKey: "array_array_of_integer") + arrayArrayOfModel = try container.decodeArrayIfPresent([ReadOnlyFirst].self, forKey: "array_array_of_model") + } } + diff --git a/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/Capitalization.swift b/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/Capitalization.swift index a39eda9087c..32ea816610e 100644 --- a/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/Capitalization.swift +++ b/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/Capitalization.swift @@ -8,6 +8,7 @@ import Foundation + open class Capitalization: Codable { public var smallCamel: String? @@ -18,16 +19,41 @@ open class Capitalization: Codable { /** Name of the pet */ public var ATT_NAME: String? - public init() {} - - private enum CodingKeys: String, CodingKey { - case smallCamel = "smallCamel" - case capitalCamel = "CapitalCamel" - case smallSnake = "small_Snake" - case capitalSnake = "Capital_Snake" - case sCAETHFlowPoints = "SCA_ETH_Flow_Points" - case ATT_NAME = "ATT_NAME" + public init(smallCamel: String?, capitalCamel: String?, smallSnake: String?, capitalSnake: String?, sCAETHFlowPoints: String?, ATT_NAME: String?) { + self.smallCamel = smallCamel + self.capitalCamel = capitalCamel + self.smallSnake = smallSnake + self.capitalSnake = capitalSnake + self.sCAETHFlowPoints = sCAETHFlowPoints + self.ATT_NAME = ATT_NAME } + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encodeIfPresent(smallCamel, forKey: "smallCamel") + try container.encodeIfPresent(capitalCamel, forKey: "CapitalCamel") + try container.encodeIfPresent(smallSnake, forKey: "small_Snake") + try container.encodeIfPresent(capitalSnake, forKey: "Capital_Snake") + try container.encodeIfPresent(sCAETHFlowPoints, forKey: "SCA_ETH_Flow_Points") + try container.encodeIfPresent(ATT_NAME, forKey: "ATT_NAME") + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + smallCamel = try container.decodeIfPresent(String.self, forKey: "smallCamel") + capitalCamel = try container.decodeIfPresent(String.self, forKey: "CapitalCamel") + smallSnake = try container.decodeIfPresent(String.self, forKey: "small_Snake") + capitalSnake = try container.decodeIfPresent(String.self, forKey: "Capital_Snake") + sCAETHFlowPoints = try container.decodeIfPresent(String.self, forKey: "SCA_ETH_Flow_Points") + ATT_NAME = try container.decodeIfPresent(String.self, forKey: "ATT_NAME") + } } + diff --git a/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/Cat.swift b/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/Cat.swift index fdb090535aa..1354abdf4f0 100644 --- a/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/Cat.swift +++ b/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/Cat.swift @@ -8,15 +8,31 @@ import Foundation + open class Cat: Animal { public var declawed: Bool? - - - private enum CodingKeys: String, CodingKey { - case declawed = "declawed" + public init(declawed: Bool?) { + self.declawed = declawed } + // Encodable protocol methods + + public override func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encodeIfPresent(declawed, forKey: "declawed") + } + + // Decodable protocol methods + + public override required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + declawed = try container.decodeIfPresent(Bool.self, forKey: "declawed") + } } + diff --git a/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/Category.swift b/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/Category.swift index 684443a0649..4d631bf8273 100644 --- a/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/Category.swift +++ b/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/Category.swift @@ -8,17 +8,35 @@ import Foundation + open class Category: Codable { public var id: Int64? public var name: String? - public init() {} - - private enum CodingKeys: String, CodingKey { - case id = "id" - case name = "name" + public init(id: Int64?, name: String?) { + self.id = id + self.name = name } + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encodeIfPresent(id, forKey: "id") + try container.encodeIfPresent(name, forKey: "name") + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + id = try container.decodeIfPresent(Int64.self, forKey: "id") + name = try container.decodeIfPresent(String.self, forKey: "name") + } } + diff --git a/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/ClassModel.swift b/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/ClassModel.swift index a3d86c6c6f9..8d80e263370 100644 --- a/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/ClassModel.swift +++ b/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/ClassModel.swift @@ -9,15 +9,31 @@ import Foundation /** Model for testing model with \"_class\" property */ + open class ClassModel: Codable { public var _class: String? - public init() {} - - private enum CodingKeys: String, CodingKey { - case _class = "_class" + public init(_class: String?) { + self._class = _class } + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encodeIfPresent(_class, forKey: "_class") + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + _class = try container.decodeIfPresent(String.self, forKey: "_class") + } } + diff --git a/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/Client.swift b/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/Client.swift index 9d6d71b2367..3a74788606b 100644 --- a/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/Client.swift +++ b/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/Client.swift @@ -8,15 +8,31 @@ import Foundation + open class Client: Codable { public var client: String? - public init() {} - - private enum CodingKeys: String, CodingKey { - case client = "client" + public init(client: String?) { + self.client = client } + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encodeIfPresent(client, forKey: "client") + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + client = try container.decodeIfPresent(String.self, forKey: "client") + } } + diff --git a/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/Dog.swift b/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/Dog.swift index ffaab37e621..2835af6b0f9 100644 --- a/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/Dog.swift +++ b/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/Dog.swift @@ -8,15 +8,31 @@ import Foundation + open class Dog: Animal { public var breed: String? - - - private enum CodingKeys: String, CodingKey { - case breed = "breed" + public init(breed: String?) { + self.breed = breed } + // Encodable protocol methods + + public override func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encodeIfPresent(breed, forKey: "breed") + } + + // Decodable protocol methods + + public override required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + breed = try container.decodeIfPresent(String.self, forKey: "breed") + } } + diff --git a/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/EnumArrays.swift b/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/EnumArrays.swift index 9b2e72b9819..bb7960a7577 100644 --- a/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/EnumArrays.swift +++ b/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/EnumArrays.swift @@ -8,6 +8,7 @@ import Foundation + open class EnumArrays: Codable { public enum JustSymbol: String, Codable { @@ -21,12 +22,29 @@ open class EnumArrays: Codable { public var justSymbol: JustSymbol? public var arrayEnum: [ArrayEnum]? - public init() {} - - private enum CodingKeys: String, CodingKey { - case justSymbol = "just_symbol" - case arrayEnum = "array_enum" + public init(justSymbol: JustSymbol?, arrayEnum: [ArrayEnum]?) { + self.justSymbol = justSymbol + self.arrayEnum = arrayEnum } + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encodeIfPresent(justSymbol, forKey: "just_symbol") + try container.encodeArrayIfPresent(arrayEnum, forKey: "array_enum") + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + justSymbol = try container.decodeIfPresent(String.self, forKey: "just_symbol") + arrayEnum = try container.decodeArrayIfPresent(String.self, forKey: "array_enum") + } } + diff --git a/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/EnumTest.swift b/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/EnumTest.swift index 89dad808a5e..023f9a8209c 100644 --- a/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/EnumTest.swift +++ b/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/EnumTest.swift @@ -8,6 +8,7 @@ import Foundation + open class EnumTest: Codable { public enum EnumString: String, Codable { @@ -17,25 +18,46 @@ open class EnumTest: Codable { } public enum EnumInteger: Int, Codable { case _1 = 1 - case numberminus1 = -1 + case number1 = -1 } public enum EnumNumber: Double, Codable { case _11 = 1.1 - case numberminus12 = -1.2 + case number12 = -1.2 } public var enumString: EnumString? public var enumInteger: EnumInteger? public var enumNumber: EnumNumber? public var outerEnum: OuterEnum? - public init() {} - - private enum CodingKeys: String, CodingKey { - case enumString = "enum_string" - case enumInteger = "enum_integer" - case enumNumber = "enum_number" - case outerEnum = "outerEnum" + public init(enumString: EnumString?, enumInteger: EnumInteger?, enumNumber: EnumNumber?, outerEnum: OuterEnum?) { + self.enumString = enumString + self.enumInteger = enumInteger + self.enumNumber = enumNumber + self.outerEnum = outerEnum } + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encodeIfPresent(enumString, forKey: "enum_string") + try container.encodeIfPresent(enumInteger, forKey: "enum_integer") + try container.encodeIfPresent(enumNumber, forKey: "enum_number") + try container.encodeIfPresent(outerEnum, forKey: "outerEnum") + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + enumString = try container.decodeIfPresent(String.self, forKey: "enum_string") + enumInteger = try container.decodeIfPresent(Int.self, forKey: "enum_integer") + enumNumber = try container.decodeIfPresent(Double.self, forKey: "enum_number") + outerEnum = try container.decodeIfPresent(OuterEnum.self, forKey: "outerEnum") + } } + diff --git a/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/FormatTest.swift b/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/FormatTest.swift index d4a1e5f8e52..3423c30d9b9 100644 --- a/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/FormatTest.swift +++ b/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/FormatTest.swift @@ -8,39 +8,79 @@ import Foundation + open class FormatTest: Codable { public var integer: Int? public var int32: Int? public var int64: Int64? - public var number: Double? + public var number: Double public var float: Float? public var double: Double? public var string: String? - public var byte: Data? + public var byte: Data public var binary: Data? - public var date: Date? + public var date: Date public var dateTime: Date? public var uuid: UUID? - public var password: String? - - public init() {} + public var password: String - private enum CodingKeys: String, CodingKey { - case integer = "integer" - case int32 = "int32" - case int64 = "int64" - case number = "number" - case float = "float" - case double = "double" - case string = "string" - case byte = "byte" - case binary = "binary" - case date = "date" - case dateTime = "dateTime" - case uuid = "uuid" - case password = "password" + public init(integer: Int?, int32: Int?, int64: Int64?, number: Double, float: Float?, double: Double?, string: String?, byte: Data, binary: Data?, date: Date, dateTime: Date?, uuid: UUID?, password: String) { + self.integer = integer + self.int32 = int32 + self.int64 = int64 + self.number = number + self.float = float + self.double = double + self.string = string + self.byte = byte + self.binary = binary + self.date = date + self.dateTime = dateTime + self.uuid = uuid + self.password = password } + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encodeIfPresent(integer, forKey: "integer") + try container.encodeIfPresent(int32, forKey: "int32") + try container.encodeIfPresent(int64, forKey: "int64") + try container.encode(number, forKey: "number") + try container.encodeIfPresent(float, forKey: "float") + try container.encodeIfPresent(double, forKey: "double") + try container.encodeIfPresent(string, forKey: "string") + try container.encode(byte, forKey: "byte") + try container.encodeIfPresent(binary, forKey: "binary") + try container.encode(date, forKey: "date") + try container.encodeIfPresent(dateTime, forKey: "dateTime") + try container.encodeIfPresent(uuid, forKey: "uuid") + try container.encode(password, forKey: "password") + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + integer = try container.decodeIfPresent(Int.self, forKey: "integer") + int32 = try container.decodeIfPresent(Int.self, forKey: "int32") + int64 = try container.decodeIfPresent(Int64.self, forKey: "int64") + number = try container.decode(Double.self, forKey: "number") + float = try container.decodeIfPresent(Float.self, forKey: "float") + double = try container.decodeIfPresent(Double.self, forKey: "double") + string = try container.decodeIfPresent(String.self, forKey: "string") + byte = try container.decode(Data.self, forKey: "byte") + binary = try container.decodeIfPresent(Data.self, forKey: "binary") + date = try container.decode(Date.self, forKey: "date") + dateTime = try container.decodeIfPresent(Date.self, forKey: "dateTime") + uuid = try container.decodeIfPresent(UUID.self, forKey: "uuid") + password = try container.decode(String.self, forKey: "password") + } } + diff --git a/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/HasOnlyReadOnly.swift b/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/HasOnlyReadOnly.swift index f3f4f794975..226ffe44b08 100644 --- a/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/HasOnlyReadOnly.swift +++ b/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/HasOnlyReadOnly.swift @@ -8,17 +8,35 @@ import Foundation + open class HasOnlyReadOnly: Codable { public var bar: String? public var foo: String? - public init() {} - - private enum CodingKeys: String, CodingKey { - case bar = "bar" - case foo = "foo" + public init(bar: String?, foo: String?) { + self.bar = bar + self.foo = foo } + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encodeIfPresent(bar, forKey: "bar") + try container.encodeIfPresent(foo, forKey: "foo") + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + bar = try container.decodeIfPresent(String.self, forKey: "bar") + foo = try container.decodeIfPresent(String.self, forKey: "foo") + } } + diff --git a/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/List.swift b/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/List.swift index 4062dc0fef9..5f4068ffbeb 100644 --- a/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/List.swift +++ b/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/List.swift @@ -8,15 +8,31 @@ import Foundation + open class List: Codable { public var _123List: String? - public init() {} - - private enum CodingKeys: String, CodingKey { - case _123List = "123-list" + public init(_123List: String?) { + self._123List = _123List } + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encodeIfPresent(_123List, forKey: "123-list") + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + _123List = try container.decodeIfPresent(String.self, forKey: "123-list") + } } + diff --git a/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/MapTest.swift b/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/MapTest.swift index 1ccfa4e4e75..36f31fc1a44 100644 --- a/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/MapTest.swift +++ b/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/MapTest.swift @@ -8,6 +8,7 @@ import Foundation + open class MapTest: Codable { public enum MapOfEnumString: String, Codable { @@ -17,12 +18,29 @@ open class MapTest: Codable { public var mapMapOfString: [String:[String:String]]? public var mapOfEnumString: [String:String]? - public init() {} - - private enum CodingKeys: String, CodingKey { - case mapMapOfString = "map_map_of_string" - case mapOfEnumString = "map_of_enum_string" + public init(mapMapOfString: [String:[String:String]]?, mapOfEnumString: [String:String]?) { + self.mapMapOfString = mapMapOfString + self.mapOfEnumString = mapOfEnumString } + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encodeIfPresent(mapMapOfString, forKey: "map_map_of_string") + try container.encodeIfPresent(mapOfEnumString, forKey: "map_of_enum_string") + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + mapMapOfString = try container.decodeIfPresent([String:[String:String]].self, forKey: "map_map_of_string") + mapOfEnumString = try container.decodeIfPresent([String:String].self, forKey: "map_of_enum_string") + } } + diff --git a/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/MixedPropertiesAndAdditionalPropertiesClass.swift b/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/MixedPropertiesAndAdditionalPropertiesClass.swift index 801890006a0..0f475c175d2 100644 --- a/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/MixedPropertiesAndAdditionalPropertiesClass.swift +++ b/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/MixedPropertiesAndAdditionalPropertiesClass.swift @@ -8,19 +8,39 @@ import Foundation + open class MixedPropertiesAndAdditionalPropertiesClass: Codable { public var uuid: UUID? public var dateTime: Date? public var map: [String:Animal]? - public init() {} - - private enum CodingKeys: String, CodingKey { - case uuid = "uuid" - case dateTime = "dateTime" - case map = "map" + public init(uuid: UUID?, dateTime: Date?, map: [String:Animal]?) { + self.uuid = uuid + self.dateTime = dateTime + self.map = map } + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encodeIfPresent(uuid, forKey: "uuid") + try container.encodeIfPresent(dateTime, forKey: "dateTime") + try container.encodeIfPresent(map, forKey: "map") + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + uuid = try container.decodeIfPresent(UUID.self, forKey: "uuid") + dateTime = try container.decodeIfPresent(Date.self, forKey: "dateTime") + map = try container.decodeIfPresent([String:Animal].self, forKey: "map") + } } + diff --git a/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/Model200Response.swift b/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/Model200Response.swift index 31e32d33583..6c671b5031d 100644 --- a/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/Model200Response.swift +++ b/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/Model200Response.swift @@ -9,17 +9,35 @@ import Foundation /** Model for testing model name starting with number */ + open class Model200Response: Codable { public var name: Int? public var _class: String? - public init() {} - - private enum CodingKeys: String, CodingKey { - case name = "name" - case _class = "class" + public init(name: Int?, _class: String?) { + self.name = name + self._class = _class } + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encodeIfPresent(name, forKey: "name") + try container.encodeIfPresent(_class, forKey: "class") + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + name = try container.decodeIfPresent(Int.self, forKey: "name") + _class = try container.decodeIfPresent(String.self, forKey: "class") + } } + diff --git a/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/Name.swift b/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/Name.swift index 3f44a95624f..873b77e3ab2 100644 --- a/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/Name.swift +++ b/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/Name.swift @@ -9,21 +9,43 @@ import Foundation /** Model for testing model name same as property name */ + open class Name: Codable { - public var name: Int? + public var name: Int public var snakeCase: Int? public var property: String? public var _123Number: Int? - public init() {} - - private enum CodingKeys: String, CodingKey { - case name = "name" - case snakeCase = "snake_case" - case property = "property" - case _123Number = "123Number" + public init(name: Int, snakeCase: Int?, property: String?, _123Number: Int?) { + self.name = name + self.snakeCase = snakeCase + self.property = property + self._123Number = _123Number } + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encode(name, forKey: "name") + try container.encodeIfPresent(snakeCase, forKey: "snake_case") + try container.encodeIfPresent(property, forKey: "property") + try container.encodeIfPresent(_123Number, forKey: "123Number") + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + name = try container.decode(Int.self, forKey: "name") + snakeCase = try container.decodeIfPresent(Int.self, forKey: "snake_case") + property = try container.decodeIfPresent(String.self, forKey: "property") + _123Number = try container.decodeIfPresent(Int.self, forKey: "123Number") + } } + diff --git a/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/NumberOnly.swift b/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/NumberOnly.swift index d3663be1e75..89921c2c9c6 100644 --- a/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/NumberOnly.swift +++ b/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/NumberOnly.swift @@ -8,15 +8,31 @@ import Foundation + open class NumberOnly: Codable { public var justNumber: Double? - public init() {} - - private enum CodingKeys: String, CodingKey { - case justNumber = "JustNumber" + public init(justNumber: Double?) { + self.justNumber = justNumber } + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encodeIfPresent(justNumber, forKey: "JustNumber") + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + justNumber = try container.decodeIfPresent(Double.self, forKey: "JustNumber") + } } + diff --git a/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/Order.swift b/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/Order.swift index e9b1a0a8c2f..fee9d6c9192 100644 --- a/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/Order.swift +++ b/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/Order.swift @@ -8,6 +8,7 @@ import Foundation + open class Order: Codable { public enum Status: String, Codable { @@ -23,16 +24,41 @@ open class Order: Codable { public var status: Status? public var complete: Bool? - public init() {} - - private enum CodingKeys: String, CodingKey { - case id = "id" - case petId = "petId" - case quantity = "quantity" - case shipDate = "shipDate" - case status = "status" - case complete = "complete" + public init(id: Int64?, petId: Int64?, quantity: Int?, shipDate: Date?, status: Status?, complete: Bool?) { + self.id = id + self.petId = petId + self.quantity = quantity + self.shipDate = shipDate + self.status = status + self.complete = complete } + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encodeIfPresent(id, forKey: "id") + try container.encodeIfPresent(petId, forKey: "petId") + try container.encodeIfPresent(quantity, forKey: "quantity") + try container.encodeIfPresent(shipDate, forKey: "shipDate") + try container.encodeIfPresent(status, forKey: "status") + try container.encodeIfPresent(complete, forKey: "complete") + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + id = try container.decodeIfPresent(Int64.self, forKey: "id") + petId = try container.decodeIfPresent(Int64.self, forKey: "petId") + quantity = try container.decodeIfPresent(Int.self, forKey: "quantity") + shipDate = try container.decodeIfPresent(Date.self, forKey: "shipDate") + status = try container.decodeIfPresent(String.self, forKey: "status") + complete = try container.decodeIfPresent(Bool.self, forKey: "complete") + } } + diff --git a/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/OuterBoolean.swift b/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/OuterBoolean.swift index 3c49ad29400..ce257737983 100644 --- a/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/OuterBoolean.swift +++ b/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/OuterBoolean.swift @@ -8,4 +8,25 @@ import Foundation -public typealias OuterBoolean = Bool + +open class OuterBoolean: Codable { + + + + + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + } +} + diff --git a/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/OuterComposite.swift b/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/OuterComposite.swift index b085a27a470..cf46c19e7f1 100644 --- a/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/OuterComposite.swift +++ b/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/OuterComposite.swift @@ -8,19 +8,39 @@ import Foundation + open class OuterComposite: Codable { public var myNumber: OuterNumber? public var myString: OuterString? public var myBoolean: OuterBoolean? - public init() {} - - private enum CodingKeys: String, CodingKey { - case myNumber = "my_number" - case myString = "my_string" - case myBoolean = "my_boolean" + public init(myNumber: OuterNumber?, myString: OuterString?, myBoolean: OuterBoolean?) { + self.myNumber = myNumber + self.myString = myString + self.myBoolean = myBoolean } + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encodeIfPresent(myNumber, forKey: "my_number") + try container.encodeIfPresent(myString, forKey: "my_string") + try container.encodeIfPresent(myBoolean, forKey: "my_boolean") + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + myNumber = try container.decodeIfPresent(OuterNumber.self, forKey: "my_number") + myString = try container.decodeIfPresent(OuterString.self, forKey: "my_string") + myBoolean = try container.decodeIfPresent(OuterBoolean.self, forKey: "my_boolean") + } } + diff --git a/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/OuterNumber.swift b/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/OuterNumber.swift index f285f4e5e29..3cd67121150 100644 --- a/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/OuterNumber.swift +++ b/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/OuterNumber.swift @@ -8,4 +8,25 @@ import Foundation -public typealias OuterNumber = Double + +open class OuterNumber: Codable { + + + + + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + } +} + diff --git a/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/OuterString.swift b/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/OuterString.swift index 9da794627d6..0d9f059b91c 100644 --- a/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/OuterString.swift +++ b/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/OuterString.swift @@ -8,4 +8,25 @@ import Foundation -public typealias OuterString = String + +open class OuterString: Codable { + + + + + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + } +} + diff --git a/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/Pet.swift b/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/Pet.swift index bf982f538ff..0622c110fd4 100644 --- a/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/Pet.swift +++ b/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/Pet.swift @@ -8,6 +8,7 @@ import Foundation + open class Pet: Codable { public enum Status: String, Codable { @@ -17,22 +18,47 @@ open class Pet: Codable { } public var id: Int64? public var category: Category? - public var name: String? - public var photoUrls: [String]? + public var name: String + public var photoUrls: [String] public var tags: [Tag]? /** pet status in the store */ public var status: Status? - public init() {} - - private enum CodingKeys: String, CodingKey { - case id = "id" - case category = "category" - case name = "name" - case photoUrls = "photoUrls" - case tags = "tags" - case status = "status" + public init(id: Int64?, category: Category?, name: String, photoUrls: [String], tags: [Tag]?, status: Status?) { + self.id = id + self.category = category + self.name = name + self.photoUrls = photoUrls + self.tags = tags + self.status = status } + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encodeIfPresent(id, forKey: "id") + try container.encodeIfPresent(category, forKey: "category") + try container.encode(name, forKey: "name") + try container.encodeArray(photoUrls, forKey: "photoUrls") + try container.encodeArrayIfPresent(tags, forKey: "tags") + try container.encodeIfPresent(status, forKey: "status") + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + id = try container.decodeIfPresent(Int64.self, forKey: "id") + category = try container.decodeIfPresent(Category.self, forKey: "category") + name = try container.decode(String.self, forKey: "name") + photoUrls = try container.decodeArray(String.self, forKey: "photoUrls") + tags = try container.decodeArrayIfPresent(Tag.self, forKey: "tags") + status = try container.decodeIfPresent(String.self, forKey: "status") + } } + diff --git a/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/ReadOnlyFirst.swift b/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/ReadOnlyFirst.swift index 5a09771ea4b..e608e6845b2 100644 --- a/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/ReadOnlyFirst.swift +++ b/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/ReadOnlyFirst.swift @@ -8,17 +8,35 @@ import Foundation + open class ReadOnlyFirst: Codable { public var bar: String? public var baz: String? - public init() {} - - private enum CodingKeys: String, CodingKey { - case bar = "bar" - case baz = "baz" + public init(bar: String?, baz: String?) { + self.bar = bar + self.baz = baz } + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encodeIfPresent(bar, forKey: "bar") + try container.encodeIfPresent(baz, forKey: "baz") + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + bar = try container.decodeIfPresent(String.self, forKey: "bar") + baz = try container.decodeIfPresent(String.self, forKey: "baz") + } } + diff --git a/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/Return.swift b/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/Return.swift index 22b9e0174a1..6429c137f3a 100644 --- a/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/Return.swift +++ b/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/Return.swift @@ -9,15 +9,31 @@ import Foundation /** Model for testing reserved words */ + open class Return: Codable { public var _return: Int? - public init() {} - - private enum CodingKeys: String, CodingKey { - case _return = "return" + public init(_return: Int?) { + self._return = _return } + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encodeIfPresent(_return, forKey: "return") + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + _return = try container.decodeIfPresent(Int.self, forKey: "return") + } } + diff --git a/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/SpecialModelName.swift b/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/SpecialModelName.swift index 8c0a8f79dc6..de8c76fa3a9 100644 --- a/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/SpecialModelName.swift +++ b/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/SpecialModelName.swift @@ -8,15 +8,31 @@ import Foundation + open class SpecialModelName: Codable { public var specialPropertyName: Int64? - public init() {} - - private enum CodingKeys: String, CodingKey { - case specialPropertyName = "$special[property.name]" + public init(specialPropertyName: Int64?) { + self.specialPropertyName = specialPropertyName } + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encodeIfPresent(specialPropertyName, forKey: "$special[property.name]") + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + specialPropertyName = try container.decodeIfPresent(Int64.self, forKey: "$special[property.name]") + } } + diff --git a/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/Tag.swift b/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/Tag.swift index feb6ab7c6cd..ab230b5f899 100644 --- a/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/Tag.swift +++ b/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/Tag.swift @@ -8,17 +8,35 @@ import Foundation + open class Tag: Codable { public var id: Int64? public var name: String? - public init() {} - - private enum CodingKeys: String, CodingKey { - case id = "id" - case name = "name" + public init(id: Int64?, name: String?) { + self.id = id + self.name = name } + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encodeIfPresent(id, forKey: "id") + try container.encodeIfPresent(name, forKey: "name") + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + id = try container.decodeIfPresent(Int64.self, forKey: "id") + name = try container.decodeIfPresent(String.self, forKey: "name") + } } + diff --git a/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/User.swift b/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/User.swift index 8fda8afb40e..17e6af33d5d 100644 --- a/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/User.swift +++ b/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/Swaggers/Models/User.swift @@ -8,6 +8,7 @@ import Foundation + open class User: Codable { public var id: Int64? @@ -20,18 +21,47 @@ open class User: Codable { /** User Status */ public var userStatus: Int? - public init() {} - - private enum CodingKeys: String, CodingKey { - case id = "id" - case username = "username" - case firstName = "firstName" - case lastName = "lastName" - case email = "email" - case password = "password" - case phone = "phone" - case userStatus = "userStatus" + public init(id: Int64?, username: String?, firstName: String?, lastName: String?, email: String?, password: String?, phone: String?, userStatus: Int?) { + self.id = id + self.username = username + self.firstName = firstName + self.lastName = lastName + self.email = email + self.password = password + self.phone = phone + self.userStatus = userStatus } + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encodeIfPresent(id, forKey: "id") + try container.encodeIfPresent(username, forKey: "username") + try container.encodeIfPresent(firstName, forKey: "firstName") + try container.encodeIfPresent(lastName, forKey: "lastName") + try container.encodeIfPresent(email, forKey: "email") + try container.encodeIfPresent(password, forKey: "password") + try container.encodeIfPresent(phone, forKey: "phone") + try container.encodeIfPresent(userStatus, forKey: "userStatus") + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + id = try container.decodeIfPresent(Int64.self, forKey: "id") + username = try container.decodeIfPresent(String.self, forKey: "username") + firstName = try container.decodeIfPresent(String.self, forKey: "firstName") + lastName = try container.decodeIfPresent(String.self, forKey: "lastName") + email = try container.decodeIfPresent(String.self, forKey: "email") + password = try container.decodeIfPresent(String.self, forKey: "password") + phone = try container.decodeIfPresent(String.self, forKey: "phone") + userStatus = try container.decodeIfPresent(Int.self, forKey: "userStatus") + } } + diff --git a/samples/client/petstore/swift4/rxswift/PetstoreClient.podspec b/samples/client/petstore/swift4/rxswift/PetstoreClient.podspec index 5591aa3de99..64c4a5e4fea 100644 --- a/samples/client/petstore/swift4/rxswift/PetstoreClient.podspec +++ b/samples/client/petstore/swift4/rxswift/PetstoreClient.podspec @@ -10,5 +10,5 @@ Pod::Spec.new do |s| s.summary = 'PetstoreClient' s.source_files = 'PetstoreClient/Classes/**/*.swift' s.dependency 'RxSwift', '~> 3.4.1' - s.dependency 'Alamofire', '~> 4.5' + s.dependency 'Alamofire', '~> 4.5.0' end diff --git a/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/APIs/AnotherfakeAPI.swift b/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/APIs/AnotherfakeAPI.swift new file mode 100644 index 00000000000..40ee161bd37 --- /dev/null +++ b/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/APIs/AnotherfakeAPI.swift @@ -0,0 +1,72 @@ +// +// AnotherfakeAPI.swift +// +// Generated by swagger-codegen +// https://github.com/swagger-api/swagger-codegen +// + +import Foundation +import Alamofire +import RxSwift + + + +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 + + - parameter body: (body) client model + - returns: Observable + */ + open class func testSpecialTags(body: Client) -> Observable { + return Observable.create { observer -> Disposable in + testSpecialTags(body: body) { data, error in + if let error = error { + observer.on(.error(error as Error)) + } else { + observer.on(.next(data!)) + } + observer.on(.completed) + } + return Disposables.create() + } + } + + /** + 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 + */ + open class func testSpecialTagsWithRequestBuilder(body: Client) -> RequestBuilder { + let path = "/another-fake/dummy" + let URLString = PetstoreClientAPI.basePath + path + let parameters = JSONEncodingHelper.encodingParameters(forEncodableObject: body) + + let url = NSURLComponents(string: URLString) + + + let requestBuilder: RequestBuilder.Type = PetstoreClientAPI.requestBuilderFactory.getBuilder() + + return requestBuilder.init(method: "PATCH", URLString: (url?.string ?? URLString), parameters: parameters, isBody: true) + } + +} diff --git a/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/APIs/FakeAPI.swift b/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/APIs/FakeAPI.swift index d5c6beab25e..d045954a7c6 100644 --- a/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/APIs/FakeAPI.swift +++ b/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/APIs/FakeAPI.swift @@ -451,7 +451,7 @@ open class FakeAPI { */ public enum EnumQueryInteger_testEnumParameters: Int { case _1 = 1 - case numberminus2 = -2 + case number2 = -2 } /** @@ -459,7 +459,7 @@ open class FakeAPI { */ public enum EnumQueryDouble_testEnumParameters: Double { case _11 = 1.1 - case numberminus12 = -1.2 + case number12 = -1.2 } /** diff --git a/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Extensions.swift b/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Extensions.swift index 202b47449d8..9cac90e08d4 100644 --- a/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Extensions.swift +++ b/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Extensions.swift @@ -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(_ values: [T], forKey key: Self.Key) throws where T : Encodable { + var arrayContainer = nestedUnkeyedContainer(forKey: key) + try arrayContainer.encode(contentsOf: values) + } + + public mutating func encodeArrayIfPresent(_ values: [T]?, forKey key: Self.Key) throws where T : Encodable { + if let values = values { + try encodeArray(values, forKey: key) + } + } + + public mutating func encodeMap(_ pairs: [Self.Key: T]) throws where T : Encodable { + for (key, value) in pairs { + try encode(value, forKey: key) + } + } + + public mutating func encodeMapIfPresent(_ pairs: [Self.Key: T]?) throws where T : Encodable { + if let pairs = pairs { + try encodeMap(pairs) + } + } + +} + +extension KeyedDecodingContainerProtocol { + + public func decodeArray(_ 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(_ 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(_ type: T.Type, excludedKeys: Set) 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 + } + +} + diff --git a/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/AdditionalPropertiesClass.swift b/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/AdditionalPropertiesClass.swift index b18644a34e3..57e6d1f76e1 100644 --- a/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/AdditionalPropertiesClass.swift +++ b/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/AdditionalPropertiesClass.swift @@ -8,17 +8,35 @@ import Foundation + open class AdditionalPropertiesClass: Codable { public var mapProperty: [String:String]? public var mapOfMapProperty: [String:[String:String]]? - public init() {} - - private enum CodingKeys: String, CodingKey { - case mapProperty = "map_property" - case mapOfMapProperty = "map_of_map_property" + 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) + + 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") + } } + diff --git a/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/Animal.swift b/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/Animal.swift index 1c0cc68a298..fd48bfb9b4c 100644 --- a/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/Animal.swift +++ b/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/Animal.swift @@ -8,17 +8,35 @@ import Foundation + open class Animal: Codable { - public var className: String? + public var className: String public var color: String? - public init() {} - - private enum CodingKeys: String, CodingKey { - case className = "className" - case color = "color" + 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) + + 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") + } } + diff --git a/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/ApiResponse.swift b/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/ApiResponse.swift index 842755fb3c4..de8b7ec6ebd 100644 --- a/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/ApiResponse.swift +++ b/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/ApiResponse.swift @@ -8,19 +8,39 @@ import Foundation + open class ApiResponse: Codable { public var code: Int? public var type: String? public var message: String? - public init() {} - - private enum CodingKeys: String, CodingKey { - case code = "code" - case type = "type" - case message = "message" + 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) + + 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") + } } + diff --git a/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/ArrayOfArrayOfNumberOnly.swift b/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/ArrayOfArrayOfNumberOnly.swift index 9f7ee34099c..0b3c86516c4 100644 --- a/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/ArrayOfArrayOfNumberOnly.swift +++ b/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/ArrayOfArrayOfNumberOnly.swift @@ -8,15 +8,31 @@ import Foundation + open class ArrayOfArrayOfNumberOnly: Codable { public var arrayArrayNumber: [[Double]]? - public init() {} - - private enum CodingKeys: String, CodingKey { - case arrayArrayNumber = "ArrayArrayNumber" + public init(arrayArrayNumber: [[Double]]?) { + self.arrayArrayNumber = arrayArrayNumber } + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + 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") + } } + diff --git a/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/ArrayOfNumberOnly.swift b/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/ArrayOfNumberOnly.swift index fba11ceb708..733fda10ef4 100644 --- a/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/ArrayOfNumberOnly.swift +++ b/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/ArrayOfNumberOnly.swift @@ -8,15 +8,31 @@ import Foundation + open class ArrayOfNumberOnly: Codable { public var arrayNumber: [Double]? - public init() {} - - private enum CodingKeys: String, CodingKey { - case arrayNumber = "ArrayNumber" + public init(arrayNumber: [Double]?) { + self.arrayNumber = arrayNumber } + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + 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") + } } + diff --git a/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/ArrayTest.swift b/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/ArrayTest.swift index bdf244f5e0a..fd948816d28 100644 --- a/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/ArrayTest.swift +++ b/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/ArrayTest.swift @@ -8,19 +8,39 @@ import Foundation + open class ArrayTest: Codable { public var arrayOfString: [String]? public var arrayArrayOfInteger: [[Int64]]? public var arrayArrayOfModel: [[ReadOnlyFirst]]? - public init() {} - - private enum CodingKeys: String, CodingKey { - case arrayOfString = "array_of_string" - case arrayArrayOfInteger = "array_array_of_integer" - case arrayArrayOfModel = "array_array_of_model" + public init(arrayOfString: [String]?, arrayArrayOfInteger: [[Int64]]?, arrayArrayOfModel: [[ReadOnlyFirst]]?) { + self.arrayOfString = arrayOfString + self.arrayArrayOfInteger = arrayArrayOfInteger + self.arrayArrayOfModel = arrayArrayOfModel } + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encodeArrayIfPresent(arrayOfString, forKey: "array_of_string") + try container.encodeArrayIfPresent(arrayArrayOfInteger, forKey: "array_array_of_integer") + try container.encodeArrayIfPresent(arrayArrayOfModel, forKey: "array_array_of_model") + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + arrayOfString = try container.decodeArrayIfPresent(String.self, forKey: "array_of_string") + arrayArrayOfInteger = try container.decodeArrayIfPresent([Int64].self, forKey: "array_array_of_integer") + arrayArrayOfModel = try container.decodeArrayIfPresent([ReadOnlyFirst].self, forKey: "array_array_of_model") + } } + diff --git a/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/Capitalization.swift b/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/Capitalization.swift index a39eda9087c..32ea816610e 100644 --- a/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/Capitalization.swift +++ b/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/Capitalization.swift @@ -8,6 +8,7 @@ import Foundation + open class Capitalization: Codable { public var smallCamel: String? @@ -18,16 +19,41 @@ open class Capitalization: Codable { /** Name of the pet */ public var ATT_NAME: String? - public init() {} - - private enum CodingKeys: String, CodingKey { - case smallCamel = "smallCamel" - case capitalCamel = "CapitalCamel" - case smallSnake = "small_Snake" - case capitalSnake = "Capital_Snake" - case sCAETHFlowPoints = "SCA_ETH_Flow_Points" - case ATT_NAME = "ATT_NAME" + public init(smallCamel: String?, capitalCamel: String?, smallSnake: String?, capitalSnake: String?, sCAETHFlowPoints: String?, ATT_NAME: String?) { + self.smallCamel = smallCamel + self.capitalCamel = capitalCamel + self.smallSnake = smallSnake + self.capitalSnake = capitalSnake + self.sCAETHFlowPoints = sCAETHFlowPoints + self.ATT_NAME = ATT_NAME } + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encodeIfPresent(smallCamel, forKey: "smallCamel") + try container.encodeIfPresent(capitalCamel, forKey: "CapitalCamel") + try container.encodeIfPresent(smallSnake, forKey: "small_Snake") + try container.encodeIfPresent(capitalSnake, forKey: "Capital_Snake") + try container.encodeIfPresent(sCAETHFlowPoints, forKey: "SCA_ETH_Flow_Points") + try container.encodeIfPresent(ATT_NAME, forKey: "ATT_NAME") + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + smallCamel = try container.decodeIfPresent(String.self, forKey: "smallCamel") + capitalCamel = try container.decodeIfPresent(String.self, forKey: "CapitalCamel") + smallSnake = try container.decodeIfPresent(String.self, forKey: "small_Snake") + capitalSnake = try container.decodeIfPresent(String.self, forKey: "Capital_Snake") + sCAETHFlowPoints = try container.decodeIfPresent(String.self, forKey: "SCA_ETH_Flow_Points") + ATT_NAME = try container.decodeIfPresent(String.self, forKey: "ATT_NAME") + } } + diff --git a/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/Cat.swift b/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/Cat.swift index fdb090535aa..1354abdf4f0 100644 --- a/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/Cat.swift +++ b/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/Cat.swift @@ -8,15 +8,31 @@ import Foundation + open class Cat: Animal { public var declawed: Bool? - - - private enum CodingKeys: String, CodingKey { - case declawed = "declawed" + public init(declawed: Bool?) { + self.declawed = declawed } + // Encodable protocol methods + + public override func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encodeIfPresent(declawed, forKey: "declawed") + } + + // Decodable protocol methods + + public override required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + declawed = try container.decodeIfPresent(Bool.self, forKey: "declawed") + } } + diff --git a/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/Category.swift b/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/Category.swift index 684443a0649..4d631bf8273 100644 --- a/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/Category.swift +++ b/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/Category.swift @@ -8,17 +8,35 @@ import Foundation + open class Category: Codable { public var id: Int64? public var name: String? - public init() {} - - private enum CodingKeys: String, CodingKey { - case id = "id" - case name = "name" + public init(id: Int64?, name: String?) { + self.id = id + self.name = name } + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encodeIfPresent(id, forKey: "id") + try container.encodeIfPresent(name, forKey: "name") + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + id = try container.decodeIfPresent(Int64.self, forKey: "id") + name = try container.decodeIfPresent(String.self, forKey: "name") + } } + diff --git a/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/ClassModel.swift b/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/ClassModel.swift index a3d86c6c6f9..8d80e263370 100644 --- a/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/ClassModel.swift +++ b/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/ClassModel.swift @@ -9,15 +9,31 @@ import Foundation /** Model for testing model with \"_class\" property */ + open class ClassModel: Codable { public var _class: String? - public init() {} - - private enum CodingKeys: String, CodingKey { - case _class = "_class" + public init(_class: String?) { + self._class = _class } + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encodeIfPresent(_class, forKey: "_class") + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + _class = try container.decodeIfPresent(String.self, forKey: "_class") + } } + diff --git a/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/Client.swift b/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/Client.swift index 9d6d71b2367..3a74788606b 100644 --- a/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/Client.swift +++ b/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/Client.swift @@ -8,15 +8,31 @@ import Foundation + open class Client: Codable { public var client: String? - public init() {} - - private enum CodingKeys: String, CodingKey { - case client = "client" + public init(client: String?) { + self.client = client } + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encodeIfPresent(client, forKey: "client") + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + client = try container.decodeIfPresent(String.self, forKey: "client") + } } + diff --git a/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/Dog.swift b/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/Dog.swift index ffaab37e621..2835af6b0f9 100644 --- a/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/Dog.swift +++ b/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/Dog.swift @@ -8,15 +8,31 @@ import Foundation + open class Dog: Animal { public var breed: String? - - - private enum CodingKeys: String, CodingKey { - case breed = "breed" + public init(breed: String?) { + self.breed = breed } + // Encodable protocol methods + + public override func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encodeIfPresent(breed, forKey: "breed") + } + + // Decodable protocol methods + + public override required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + breed = try container.decodeIfPresent(String.self, forKey: "breed") + } } + diff --git a/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/EnumArrays.swift b/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/EnumArrays.swift index 9b2e72b9819..bb7960a7577 100644 --- a/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/EnumArrays.swift +++ b/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/EnumArrays.swift @@ -8,6 +8,7 @@ import Foundation + open class EnumArrays: Codable { public enum JustSymbol: String, Codable { @@ -21,12 +22,29 @@ open class EnumArrays: Codable { public var justSymbol: JustSymbol? public var arrayEnum: [ArrayEnum]? - public init() {} - - private enum CodingKeys: String, CodingKey { - case justSymbol = "just_symbol" - case arrayEnum = "array_enum" + public init(justSymbol: JustSymbol?, arrayEnum: [ArrayEnum]?) { + self.justSymbol = justSymbol + self.arrayEnum = arrayEnum } + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encodeIfPresent(justSymbol, forKey: "just_symbol") + try container.encodeArrayIfPresent(arrayEnum, forKey: "array_enum") + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + justSymbol = try container.decodeIfPresent(String.self, forKey: "just_symbol") + arrayEnum = try container.decodeArrayIfPresent(String.self, forKey: "array_enum") + } } + diff --git a/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/EnumTest.swift b/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/EnumTest.swift index 89dad808a5e..023f9a8209c 100644 --- a/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/EnumTest.swift +++ b/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/EnumTest.swift @@ -8,6 +8,7 @@ import Foundation + open class EnumTest: Codable { public enum EnumString: String, Codable { @@ -17,25 +18,46 @@ open class EnumTest: Codable { } public enum EnumInteger: Int, Codable { case _1 = 1 - case numberminus1 = -1 + case number1 = -1 } public enum EnumNumber: Double, Codable { case _11 = 1.1 - case numberminus12 = -1.2 + case number12 = -1.2 } public var enumString: EnumString? public var enumInteger: EnumInteger? public var enumNumber: EnumNumber? public var outerEnum: OuterEnum? - public init() {} - - private enum CodingKeys: String, CodingKey { - case enumString = "enum_string" - case enumInteger = "enum_integer" - case enumNumber = "enum_number" - case outerEnum = "outerEnum" + public init(enumString: EnumString?, enumInteger: EnumInteger?, enumNumber: EnumNumber?, outerEnum: OuterEnum?) { + self.enumString = enumString + self.enumInteger = enumInteger + self.enumNumber = enumNumber + self.outerEnum = outerEnum } + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encodeIfPresent(enumString, forKey: "enum_string") + try container.encodeIfPresent(enumInteger, forKey: "enum_integer") + try container.encodeIfPresent(enumNumber, forKey: "enum_number") + try container.encodeIfPresent(outerEnum, forKey: "outerEnum") + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + enumString = try container.decodeIfPresent(String.self, forKey: "enum_string") + enumInteger = try container.decodeIfPresent(Int.self, forKey: "enum_integer") + enumNumber = try container.decodeIfPresent(Double.self, forKey: "enum_number") + outerEnum = try container.decodeIfPresent(OuterEnum.self, forKey: "outerEnum") + } } + diff --git a/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/FormatTest.swift b/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/FormatTest.swift index d4a1e5f8e52..3423c30d9b9 100644 --- a/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/FormatTest.swift +++ b/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/FormatTest.swift @@ -8,39 +8,79 @@ import Foundation + open class FormatTest: Codable { public var integer: Int? public var int32: Int? public var int64: Int64? - public var number: Double? + public var number: Double public var float: Float? public var double: Double? public var string: String? - public var byte: Data? + public var byte: Data public var binary: Data? - public var date: Date? + public var date: Date public var dateTime: Date? public var uuid: UUID? - public var password: String? - - public init() {} + public var password: String - private enum CodingKeys: String, CodingKey { - case integer = "integer" - case int32 = "int32" - case int64 = "int64" - case number = "number" - case float = "float" - case double = "double" - case string = "string" - case byte = "byte" - case binary = "binary" - case date = "date" - case dateTime = "dateTime" - case uuid = "uuid" - case password = "password" + public init(integer: Int?, int32: Int?, int64: Int64?, number: Double, float: Float?, double: Double?, string: String?, byte: Data, binary: Data?, date: Date, dateTime: Date?, uuid: UUID?, password: String) { + self.integer = integer + self.int32 = int32 + self.int64 = int64 + self.number = number + self.float = float + self.double = double + self.string = string + self.byte = byte + self.binary = binary + self.date = date + self.dateTime = dateTime + self.uuid = uuid + self.password = password } + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encodeIfPresent(integer, forKey: "integer") + try container.encodeIfPresent(int32, forKey: "int32") + try container.encodeIfPresent(int64, forKey: "int64") + try container.encode(number, forKey: "number") + try container.encodeIfPresent(float, forKey: "float") + try container.encodeIfPresent(double, forKey: "double") + try container.encodeIfPresent(string, forKey: "string") + try container.encode(byte, forKey: "byte") + try container.encodeIfPresent(binary, forKey: "binary") + try container.encode(date, forKey: "date") + try container.encodeIfPresent(dateTime, forKey: "dateTime") + try container.encodeIfPresent(uuid, forKey: "uuid") + try container.encode(password, forKey: "password") + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + integer = try container.decodeIfPresent(Int.self, forKey: "integer") + int32 = try container.decodeIfPresent(Int.self, forKey: "int32") + int64 = try container.decodeIfPresent(Int64.self, forKey: "int64") + number = try container.decode(Double.self, forKey: "number") + float = try container.decodeIfPresent(Float.self, forKey: "float") + double = try container.decodeIfPresent(Double.self, forKey: "double") + string = try container.decodeIfPresent(String.self, forKey: "string") + byte = try container.decode(Data.self, forKey: "byte") + binary = try container.decodeIfPresent(Data.self, forKey: "binary") + date = try container.decode(Date.self, forKey: "date") + dateTime = try container.decodeIfPresent(Date.self, forKey: "dateTime") + uuid = try container.decodeIfPresent(UUID.self, forKey: "uuid") + password = try container.decode(String.self, forKey: "password") + } } + diff --git a/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/HasOnlyReadOnly.swift b/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/HasOnlyReadOnly.swift index f3f4f794975..226ffe44b08 100644 --- a/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/HasOnlyReadOnly.swift +++ b/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/HasOnlyReadOnly.swift @@ -8,17 +8,35 @@ import Foundation + open class HasOnlyReadOnly: Codable { public var bar: String? public var foo: String? - public init() {} - - private enum CodingKeys: String, CodingKey { - case bar = "bar" - case foo = "foo" + public init(bar: String?, foo: String?) { + self.bar = bar + self.foo = foo } + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encodeIfPresent(bar, forKey: "bar") + try container.encodeIfPresent(foo, forKey: "foo") + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + bar = try container.decodeIfPresent(String.self, forKey: "bar") + foo = try container.decodeIfPresent(String.self, forKey: "foo") + } } + diff --git a/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/List.swift b/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/List.swift index 4062dc0fef9..5f4068ffbeb 100644 --- a/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/List.swift +++ b/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/List.swift @@ -8,15 +8,31 @@ import Foundation + open class List: Codable { public var _123List: String? - public init() {} - - private enum CodingKeys: String, CodingKey { - case _123List = "123-list" + public init(_123List: String?) { + self._123List = _123List } + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encodeIfPresent(_123List, forKey: "123-list") + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + _123List = try container.decodeIfPresent(String.self, forKey: "123-list") + } } + diff --git a/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/MapTest.swift b/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/MapTest.swift index 1ccfa4e4e75..36f31fc1a44 100644 --- a/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/MapTest.swift +++ b/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/MapTest.swift @@ -8,6 +8,7 @@ import Foundation + open class MapTest: Codable { public enum MapOfEnumString: String, Codable { @@ -17,12 +18,29 @@ open class MapTest: Codable { public var mapMapOfString: [String:[String:String]]? public var mapOfEnumString: [String:String]? - public init() {} - - private enum CodingKeys: String, CodingKey { - case mapMapOfString = "map_map_of_string" - case mapOfEnumString = "map_of_enum_string" + public init(mapMapOfString: [String:[String:String]]?, mapOfEnumString: [String:String]?) { + self.mapMapOfString = mapMapOfString + self.mapOfEnumString = mapOfEnumString } + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encodeIfPresent(mapMapOfString, forKey: "map_map_of_string") + try container.encodeIfPresent(mapOfEnumString, forKey: "map_of_enum_string") + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + mapMapOfString = try container.decodeIfPresent([String:[String:String]].self, forKey: "map_map_of_string") + mapOfEnumString = try container.decodeIfPresent([String:String].self, forKey: "map_of_enum_string") + } } + diff --git a/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/MixedPropertiesAndAdditionalPropertiesClass.swift b/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/MixedPropertiesAndAdditionalPropertiesClass.swift index 801890006a0..0f475c175d2 100644 --- a/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/MixedPropertiesAndAdditionalPropertiesClass.swift +++ b/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/MixedPropertiesAndAdditionalPropertiesClass.swift @@ -8,19 +8,39 @@ import Foundation + open class MixedPropertiesAndAdditionalPropertiesClass: Codable { public var uuid: UUID? public var dateTime: Date? public var map: [String:Animal]? - public init() {} - - private enum CodingKeys: String, CodingKey { - case uuid = "uuid" - case dateTime = "dateTime" - case map = "map" + public init(uuid: UUID?, dateTime: Date?, map: [String:Animal]?) { + self.uuid = uuid + self.dateTime = dateTime + self.map = map } + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encodeIfPresent(uuid, forKey: "uuid") + try container.encodeIfPresent(dateTime, forKey: "dateTime") + try container.encodeIfPresent(map, forKey: "map") + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + uuid = try container.decodeIfPresent(UUID.self, forKey: "uuid") + dateTime = try container.decodeIfPresent(Date.self, forKey: "dateTime") + map = try container.decodeIfPresent([String:Animal].self, forKey: "map") + } } + diff --git a/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/Model200Response.swift b/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/Model200Response.swift index 31e32d33583..6c671b5031d 100644 --- a/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/Model200Response.swift +++ b/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/Model200Response.swift @@ -9,17 +9,35 @@ import Foundation /** Model for testing model name starting with number */ + open class Model200Response: Codable { public var name: Int? public var _class: String? - public init() {} - - private enum CodingKeys: String, CodingKey { - case name = "name" - case _class = "class" + public init(name: Int?, _class: String?) { + self.name = name + self._class = _class } + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encodeIfPresent(name, forKey: "name") + try container.encodeIfPresent(_class, forKey: "class") + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + name = try container.decodeIfPresent(Int.self, forKey: "name") + _class = try container.decodeIfPresent(String.self, forKey: "class") + } } + diff --git a/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/Name.swift b/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/Name.swift index 3f44a95624f..873b77e3ab2 100644 --- a/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/Name.swift +++ b/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/Name.swift @@ -9,21 +9,43 @@ import Foundation /** Model for testing model name same as property name */ + open class Name: Codable { - public var name: Int? + public var name: Int public var snakeCase: Int? public var property: String? public var _123Number: Int? - public init() {} - - private enum CodingKeys: String, CodingKey { - case name = "name" - case snakeCase = "snake_case" - case property = "property" - case _123Number = "123Number" + public init(name: Int, snakeCase: Int?, property: String?, _123Number: Int?) { + self.name = name + self.snakeCase = snakeCase + self.property = property + self._123Number = _123Number } + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encode(name, forKey: "name") + try container.encodeIfPresent(snakeCase, forKey: "snake_case") + try container.encodeIfPresent(property, forKey: "property") + try container.encodeIfPresent(_123Number, forKey: "123Number") + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + name = try container.decode(Int.self, forKey: "name") + snakeCase = try container.decodeIfPresent(Int.self, forKey: "snake_case") + property = try container.decodeIfPresent(String.self, forKey: "property") + _123Number = try container.decodeIfPresent(Int.self, forKey: "123Number") + } } + diff --git a/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/NumberOnly.swift b/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/NumberOnly.swift index d3663be1e75..89921c2c9c6 100644 --- a/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/NumberOnly.swift +++ b/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/NumberOnly.swift @@ -8,15 +8,31 @@ import Foundation + open class NumberOnly: Codable { public var justNumber: Double? - public init() {} - - private enum CodingKeys: String, CodingKey { - case justNumber = "JustNumber" + public init(justNumber: Double?) { + self.justNumber = justNumber } + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encodeIfPresent(justNumber, forKey: "JustNumber") + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + justNumber = try container.decodeIfPresent(Double.self, forKey: "JustNumber") + } } + diff --git a/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/Order.swift b/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/Order.swift index e9b1a0a8c2f..fee9d6c9192 100644 --- a/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/Order.swift +++ b/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/Order.swift @@ -8,6 +8,7 @@ import Foundation + open class Order: Codable { public enum Status: String, Codable { @@ -23,16 +24,41 @@ open class Order: Codable { public var status: Status? public var complete: Bool? - public init() {} - - private enum CodingKeys: String, CodingKey { - case id = "id" - case petId = "petId" - case quantity = "quantity" - case shipDate = "shipDate" - case status = "status" - case complete = "complete" + public init(id: Int64?, petId: Int64?, quantity: Int?, shipDate: Date?, status: Status?, complete: Bool?) { + self.id = id + self.petId = petId + self.quantity = quantity + self.shipDate = shipDate + self.status = status + self.complete = complete } + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encodeIfPresent(id, forKey: "id") + try container.encodeIfPresent(petId, forKey: "petId") + try container.encodeIfPresent(quantity, forKey: "quantity") + try container.encodeIfPresent(shipDate, forKey: "shipDate") + try container.encodeIfPresent(status, forKey: "status") + try container.encodeIfPresent(complete, forKey: "complete") + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + id = try container.decodeIfPresent(Int64.self, forKey: "id") + petId = try container.decodeIfPresent(Int64.self, forKey: "petId") + quantity = try container.decodeIfPresent(Int.self, forKey: "quantity") + shipDate = try container.decodeIfPresent(Date.self, forKey: "shipDate") + status = try container.decodeIfPresent(String.self, forKey: "status") + complete = try container.decodeIfPresent(Bool.self, forKey: "complete") + } } + diff --git a/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/OuterBoolean.swift b/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/OuterBoolean.swift index 3c49ad29400..ce257737983 100644 --- a/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/OuterBoolean.swift +++ b/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/OuterBoolean.swift @@ -8,4 +8,25 @@ import Foundation -public typealias OuterBoolean = Bool + +open class OuterBoolean: Codable { + + + + + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + } +} + diff --git a/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/OuterComposite.swift b/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/OuterComposite.swift index b085a27a470..cf46c19e7f1 100644 --- a/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/OuterComposite.swift +++ b/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/OuterComposite.swift @@ -8,19 +8,39 @@ import Foundation + open class OuterComposite: Codable { public var myNumber: OuterNumber? public var myString: OuterString? public var myBoolean: OuterBoolean? - public init() {} - - private enum CodingKeys: String, CodingKey { - case myNumber = "my_number" - case myString = "my_string" - case myBoolean = "my_boolean" + public init(myNumber: OuterNumber?, myString: OuterString?, myBoolean: OuterBoolean?) { + self.myNumber = myNumber + self.myString = myString + self.myBoolean = myBoolean } + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encodeIfPresent(myNumber, forKey: "my_number") + try container.encodeIfPresent(myString, forKey: "my_string") + try container.encodeIfPresent(myBoolean, forKey: "my_boolean") + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + myNumber = try container.decodeIfPresent(OuterNumber.self, forKey: "my_number") + myString = try container.decodeIfPresent(OuterString.self, forKey: "my_string") + myBoolean = try container.decodeIfPresent(OuterBoolean.self, forKey: "my_boolean") + } } + diff --git a/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/OuterNumber.swift b/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/OuterNumber.swift index f285f4e5e29..3cd67121150 100644 --- a/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/OuterNumber.swift +++ b/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/OuterNumber.swift @@ -8,4 +8,25 @@ import Foundation -public typealias OuterNumber = Double + +open class OuterNumber: Codable { + + + + + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + } +} + diff --git a/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/OuterString.swift b/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/OuterString.swift index 9da794627d6..0d9f059b91c 100644 --- a/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/OuterString.swift +++ b/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/OuterString.swift @@ -8,4 +8,25 @@ import Foundation -public typealias OuterString = String + +open class OuterString: Codable { + + + + + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + } +} + diff --git a/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/Pet.swift b/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/Pet.swift index bf982f538ff..0622c110fd4 100644 --- a/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/Pet.swift +++ b/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/Pet.swift @@ -8,6 +8,7 @@ import Foundation + open class Pet: Codable { public enum Status: String, Codable { @@ -17,22 +18,47 @@ open class Pet: Codable { } public var id: Int64? public var category: Category? - public var name: String? - public var photoUrls: [String]? + public var name: String + public var photoUrls: [String] public var tags: [Tag]? /** pet status in the store */ public var status: Status? - public init() {} - - private enum CodingKeys: String, CodingKey { - case id = "id" - case category = "category" - case name = "name" - case photoUrls = "photoUrls" - case tags = "tags" - case status = "status" + public init(id: Int64?, category: Category?, name: String, photoUrls: [String], tags: [Tag]?, status: Status?) { + self.id = id + self.category = category + self.name = name + self.photoUrls = photoUrls + self.tags = tags + self.status = status } + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encodeIfPresent(id, forKey: "id") + try container.encodeIfPresent(category, forKey: "category") + try container.encode(name, forKey: "name") + try container.encodeArray(photoUrls, forKey: "photoUrls") + try container.encodeArrayIfPresent(tags, forKey: "tags") + try container.encodeIfPresent(status, forKey: "status") + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + id = try container.decodeIfPresent(Int64.self, forKey: "id") + category = try container.decodeIfPresent(Category.self, forKey: "category") + name = try container.decode(String.self, forKey: "name") + photoUrls = try container.decodeArray(String.self, forKey: "photoUrls") + tags = try container.decodeArrayIfPresent(Tag.self, forKey: "tags") + status = try container.decodeIfPresent(String.self, forKey: "status") + } } + diff --git a/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/ReadOnlyFirst.swift b/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/ReadOnlyFirst.swift index 5a09771ea4b..e608e6845b2 100644 --- a/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/ReadOnlyFirst.swift +++ b/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/ReadOnlyFirst.swift @@ -8,17 +8,35 @@ import Foundation + open class ReadOnlyFirst: Codable { public var bar: String? public var baz: String? - public init() {} - - private enum CodingKeys: String, CodingKey { - case bar = "bar" - case baz = "baz" + public init(bar: String?, baz: String?) { + self.bar = bar + self.baz = baz } + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encodeIfPresent(bar, forKey: "bar") + try container.encodeIfPresent(baz, forKey: "baz") + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + bar = try container.decodeIfPresent(String.self, forKey: "bar") + baz = try container.decodeIfPresent(String.self, forKey: "baz") + } } + diff --git a/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/Return.swift b/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/Return.swift index 22b9e0174a1..6429c137f3a 100644 --- a/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/Return.swift +++ b/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/Return.swift @@ -9,15 +9,31 @@ import Foundation /** Model for testing reserved words */ + open class Return: Codable { public var _return: Int? - public init() {} - - private enum CodingKeys: String, CodingKey { - case _return = "return" + public init(_return: Int?) { + self._return = _return } + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encodeIfPresent(_return, forKey: "return") + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + _return = try container.decodeIfPresent(Int.self, forKey: "return") + } } + diff --git a/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/SpecialModelName.swift b/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/SpecialModelName.swift index 8c0a8f79dc6..de8c76fa3a9 100644 --- a/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/SpecialModelName.swift +++ b/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/SpecialModelName.swift @@ -8,15 +8,31 @@ import Foundation + open class SpecialModelName: Codable { public var specialPropertyName: Int64? - public init() {} - - private enum CodingKeys: String, CodingKey { - case specialPropertyName = "$special[property.name]" + public init(specialPropertyName: Int64?) { + self.specialPropertyName = specialPropertyName } + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encodeIfPresent(specialPropertyName, forKey: "$special[property.name]") + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + specialPropertyName = try container.decodeIfPresent(Int64.self, forKey: "$special[property.name]") + } } + diff --git a/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/Tag.swift b/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/Tag.swift index feb6ab7c6cd..ab230b5f899 100644 --- a/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/Tag.swift +++ b/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/Tag.swift @@ -8,17 +8,35 @@ import Foundation + open class Tag: Codable { public var id: Int64? public var name: String? - public init() {} - - private enum CodingKeys: String, CodingKey { - case id = "id" - case name = "name" + public init(id: Int64?, name: String?) { + self.id = id + self.name = name } + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encodeIfPresent(id, forKey: "id") + try container.encodeIfPresent(name, forKey: "name") + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + id = try container.decodeIfPresent(Int64.self, forKey: "id") + name = try container.decodeIfPresent(String.self, forKey: "name") + } } + diff --git a/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/User.swift b/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/User.swift index 8fda8afb40e..17e6af33d5d 100644 --- a/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/User.swift +++ b/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/Swaggers/Models/User.swift @@ -8,6 +8,7 @@ import Foundation + open class User: Codable { public var id: Int64? @@ -20,18 +21,47 @@ open class User: Codable { /** User Status */ public var userStatus: Int? - public init() {} - - private enum CodingKeys: String, CodingKey { - case id = "id" - case username = "username" - case firstName = "firstName" - case lastName = "lastName" - case email = "email" - case password = "password" - case phone = "phone" - case userStatus = "userStatus" + public init(id: Int64?, username: String?, firstName: String?, lastName: String?, email: String?, password: String?, phone: String?, userStatus: Int?) { + self.id = id + self.username = username + self.firstName = firstName + self.lastName = lastName + self.email = email + self.password = password + self.phone = phone + self.userStatus = userStatus } + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: String.self) + + try container.encodeIfPresent(id, forKey: "id") + try container.encodeIfPresent(username, forKey: "username") + try container.encodeIfPresent(firstName, forKey: "firstName") + try container.encodeIfPresent(lastName, forKey: "lastName") + try container.encodeIfPresent(email, forKey: "email") + try container.encodeIfPresent(password, forKey: "password") + try container.encodeIfPresent(phone, forKey: "phone") + try container.encodeIfPresent(userStatus, forKey: "userStatus") + } + + // Decodable protocol methods + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: String.self) + + id = try container.decodeIfPresent(Int64.self, forKey: "id") + username = try container.decodeIfPresent(String.self, forKey: "username") + firstName = try container.decodeIfPresent(String.self, forKey: "firstName") + lastName = try container.decodeIfPresent(String.self, forKey: "lastName") + email = try container.decodeIfPresent(String.self, forKey: "email") + password = try container.decodeIfPresent(String.self, forKey: "password") + phone = try container.decodeIfPresent(String.self, forKey: "phone") + userStatus = try container.decodeIfPresent(Int.self, forKey: "userStatus") + } } + diff --git a/samples/client/test/swift4/default/TestClient/Classes/Swaggers/AlamofireImplementations.swift b/samples/client/test/swift4/default/TestClient/Classes/Swaggers/AlamofireImplementations.swift index b9d2a2727de..0d294aee4ce 100644 --- a/samples/client/test/swift4/default/TestClient/Classes/Swaggers/AlamofireImplementations.swift +++ b/samples/client/test/swift4/default/TestClient/Classes/Swaggers/AlamofireImplementations.swift @@ -142,6 +142,56 @@ open class AlamofireRequestBuilder: RequestBuilder { 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.Error(400, dataResponse.data, requestParserError)) + } catch let error { + completion(nil, ErrorResponse.Error(400, dataResponse.data, error)) + } + return + }) case is Void.Type: validatedRequest.responseData(completionHandler: { (voidResponse) in cleanupRequest() @@ -191,6 +241,66 @@ open class AlamofireRequestBuilder: RequestBuilder { } 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 } public enum AlamofireDecodableRequestBuilderError: Error { diff --git a/samples/client/test/swift4/default/TestClient/Classes/Swaggers/Models/AllPrimitives.swift b/samples/client/test/swift4/default/TestClient/Classes/Swaggers/Models/AllPrimitives.swift index 3ad6c11c2fb..b637b2013a5 100644 --- a/samples/client/test/swift4/default/TestClient/Classes/Swaggers/Models/AllPrimitives.swift +++ b/samples/client/test/swift4/default/TestClient/Classes/Swaggers/Models/AllPrimitives.swift @@ -44,6 +44,33 @@ open class AllPrimitives: Codable { public var myInlineStringEnum: MyInlineStringEnum? + public init(myInteger: Int?, myIntegerArray: [Int]?, myLong: Int64?, myLongArray: [Int64]?, myFloat: Float?, myFloatArray: [Float]?, myDouble: Double?, myDoubleArray: [Double]?, myString: String?, myStringArray: [String]?, myBytes: Data?, myBytesArray: [Data]?, myBoolean: Bool?, myBooleanArray: [Bool]?, myDate: Date?, myDateArray: [Date]?, myDateTime: Date?, myDateTimeArray: [Date]?, myFile: URL?, myFileArray: [URL]?, myUUID: UUID?, myUUIDArray: [UUID]?, myStringEnum: StringEnum?, myStringEnumArray: [StringEnum]?) { + self.myInteger = myInteger + self.myIntegerArray = myIntegerArray + self.myLong = myLong + self.myLongArray = myLongArray + self.myFloat = myFloat + self.myFloatArray = myFloatArray + self.myDouble = myDouble + self.myDoubleArray = myDoubleArray + self.myString = myString + self.myStringArray = myStringArray + self.myBytes = myBytes + self.myBytesArray = myBytesArray + self.myBoolean = myBoolean + self.myBooleanArray = myBooleanArray + self.myDate = myDate + self.myDateArray = myDateArray + self.myDateTime = myDateTime + self.myDateTimeArray = myDateTimeArray + self.myFile = myFile + self.myFileArray = myFileArray + self.myUUID = myUUID + self.myUUIDArray = myUUIDArray + self.myStringEnum = myStringEnum + self.myStringEnumArray = myStringEnumArray + } + // Encodable protocol methods public func encode(to encoder: Encoder) throws { diff --git a/samples/client/test/swift4/default/TestClient/Classes/Swaggers/Models/ErrorInfo.swift b/samples/client/test/swift4/default/TestClient/Classes/Swaggers/Models/ErrorInfo.swift index c313ada307f..141efe2646f 100644 --- a/samples/client/test/swift4/default/TestClient/Classes/Swaggers/Models/ErrorInfo.swift +++ b/samples/client/test/swift4/default/TestClient/Classes/Swaggers/Models/ErrorInfo.swift @@ -17,6 +17,12 @@ open class ErrorInfo: Codable { public var details: [String]? + public init(code: Int?, message: String?, details: [String]?) { + self.code = code + self.message = message + self.details = details + } + // Encodable protocol methods public func encode(to encoder: Encoder) throws { diff --git a/samples/client/test/swift4/default/TestClient/Classes/Swaggers/Models/GetAllModelsResult.swift b/samples/client/test/swift4/default/TestClient/Classes/Swaggers/Models/GetAllModelsResult.swift index 9708ce78e06..846ae99e358 100644 --- a/samples/client/test/swift4/default/TestClient/Classes/Swaggers/Models/GetAllModelsResult.swift +++ b/samples/client/test/swift4/default/TestClient/Classes/Swaggers/Models/GetAllModelsResult.swift @@ -17,6 +17,12 @@ open class GetAllModelsResult: Codable { public var myVariableNameTest: VariableNameTest? + public init(myPrimitiveArray: [AllPrimitives]?, myPrimitive: AllPrimitives?, myVariableNameTest: VariableNameTest?) { + self.myPrimitiveArray = myPrimitiveArray + self.myPrimitive = myPrimitive + self.myVariableNameTest = myVariableNameTest + } + // Encodable protocol methods public func encode(to encoder: Encoder) throws { diff --git a/samples/client/test/swift4/default/TestClient/Classes/Swaggers/Models/ModelWithIntAdditionalPropertiesOnly.swift b/samples/client/test/swift4/default/TestClient/Classes/Swaggers/Models/ModelWithIntAdditionalPropertiesOnly.swift index 25392820511..5e42dbc1cb4 100644 --- a/samples/client/test/swift4/default/TestClient/Classes/Swaggers/Models/ModelWithIntAdditionalPropertiesOnly.swift +++ b/samples/client/test/swift4/default/TestClient/Classes/Swaggers/Models/ModelWithIntAdditionalPropertiesOnly.swift @@ -28,6 +28,7 @@ open class ModelWithIntAdditionalPropertiesOnly: Codable { } } + // Encodable protocol methods public func encode(to encoder: Encoder) throws { diff --git a/samples/client/test/swift4/default/TestClient/Classes/Swaggers/Models/ModelWithPropertiesAndAdditionalProperties.swift b/samples/client/test/swift4/default/TestClient/Classes/Swaggers/Models/ModelWithPropertiesAndAdditionalProperties.swift index 67f73da1bd0..05b4140268f 100644 --- a/samples/client/test/swift4/default/TestClient/Classes/Swaggers/Models/ModelWithPropertiesAndAdditionalProperties.swift +++ b/samples/client/test/swift4/default/TestClient/Classes/Swaggers/Models/ModelWithPropertiesAndAdditionalProperties.swift @@ -36,6 +36,17 @@ open class ModelWithPropertiesAndAdditionalProperties: Codable { } } + public init(myIntegerReq: Int, myIntegerOpt: Int?, myPrimitiveReq: AllPrimitives, myPrimitiveOpt: AllPrimitives?, myStringArrayReq: [String], myStringArrayOpt: [String]?, myPrimitiveArrayReq: [AllPrimitives], myPrimitiveArrayOpt: [AllPrimitives]?) { + self.myIntegerReq = myIntegerReq + self.myIntegerOpt = myIntegerOpt + self.myPrimitiveReq = myPrimitiveReq + self.myPrimitiveOpt = myPrimitiveOpt + self.myStringArrayReq = myStringArrayReq + self.myStringArrayOpt = myStringArrayOpt + self.myPrimitiveArrayReq = myPrimitiveArrayReq + self.myPrimitiveArrayOpt = myPrimitiveArrayOpt + } + // Encodable protocol methods public func encode(to encoder: Encoder) throws { diff --git a/samples/client/test/swift4/default/TestClient/Classes/Swaggers/Models/ModelWithStringAdditionalPropertiesOnly.swift b/samples/client/test/swift4/default/TestClient/Classes/Swaggers/Models/ModelWithStringAdditionalPropertiesOnly.swift index 47ad742ae32..e38a59df6e4 100644 --- a/samples/client/test/swift4/default/TestClient/Classes/Swaggers/Models/ModelWithStringAdditionalPropertiesOnly.swift +++ b/samples/client/test/swift4/default/TestClient/Classes/Swaggers/Models/ModelWithStringAdditionalPropertiesOnly.swift @@ -28,6 +28,7 @@ open class ModelWithStringAdditionalPropertiesOnly: Codable { } } + // Encodable protocol methods public func encode(to encoder: Encoder) throws { diff --git a/samples/client/test/swift4/default/TestClient/Classes/Swaggers/Models/VariableNameTest.swift b/samples/client/test/swift4/default/TestClient/Classes/Swaggers/Models/VariableNameTest.swift index d2ec9840a37..188943c9efa 100644 --- a/samples/client/test/swift4/default/TestClient/Classes/Swaggers/Models/VariableNameTest.swift +++ b/samples/client/test/swift4/default/TestClient/Classes/Swaggers/Models/VariableNameTest.swift @@ -18,6 +18,11 @@ open class VariableNameTest: Codable { public var _for: String? + public init(exampleName: String?, _for: String?) { + self.exampleName = exampleName + self._for = _for + } + // Encodable protocol methods public func encode(to encoder: Encoder) throws {