Commit Graph

12 Commits

Author SHA1 Message Date
ehyche
a3d0f1d4bd Swift4: make generated models structs instead of classes (#7345)
* Split up model template into partials

* Change models from class to struct.

This fixes issue https://github.com/swagger-api/swagger-codegen/issues/6941.

In this change, we make our Swift4 generated model objects struct instead of class. However, in order to do this, we needed to handle the following edge cases:

* Inheritance and polymorphism (allOf)
  * With classes, we use inheritance. So therefore, the parent properties are ONLY on the parent generated class, and the model object which derives from the parent class picks up those properties through inheritance.
  * However, structs do not support inheritance. So we simply duplicate the parent allOf properties in the child struct.
* We have to handle the case where the property name on the struct may be different than the property name in the JSON. By default, the Codable protocol assumes that the JSON property name is the same as the struct property name. If they need to be different, then we generate a CodingKeys string enum, which contains the mapping between struct property name and JSON property name.
* additionalProperties. We cannot use the default Codable implementation for the additionalProperties, since it will look for an actual dictionary called "additionalProperties" in the JSON. Therefore, for model objects which have additionalProperties, we must generate our own implementation for the Decodable and Encodable protocols.

I have run ./bin/swift4-all.sh and ./bin/swift4-test.sh to re-generate all of the sources, and I have verified that the generated code in samples/clients/test/swift4/default builds and the unit tests pass.

* Update VERSION in .swagger-codegen

* Update generated code for swift4-test schema
2018-01-25 21:33:11 +08:00
ehyche
d2a2292d20 Update samples using latest codegen and templates (#7071) 2017-11-29 14:49:45 +08:00
Daiki Matsudate
a5e4abe5ec [Swift4]Update templates for swift 4 (#6921)
* update versions of dependencies on swift4 and swift3

* change syntax for swift4

* run petstore script

* change enum case from UpperCamel to lowerCamel

* remove unneeded break statements

* avoid wrapping conditionals in parentheses

* avoid force casting

* run pod update on petstore/swift4/rxswift

* update project for swift 4

* run swift4-petstore-all.sh

* fix compile error

* avoid use iso8601 date strategy for encoder / decoder

* resolve file references
2017-11-21 11:33:52 +08:00
Atanas Bozhkov
970de01bdf [Swift4] Add throw to reserved words (#6952)
* * Added `throw` to Swift4 Reserved words.

* * Regenerating Swift4 Petstore project
2017-11-15 21:45:30 +08:00
Dawid van Graan
5af788cb9f [Swift4] Allow for custom dateformatter to be used (#6672)
* Add a custom dateformat to be set

* Samples updated

* Update CodableHelper.swift

Change to correct format: decoder.dataDecodingStrategy = .base64

* Update CodableHelper.mustache

Add `decoder.dataDecodingStrategy = .base64` back

* Update CodableHelper.swift

Fix `decoder.dataDecodingStrategy = .base64`

* Update CodableHelper.swift

Fix `decoder.dataDecodingStrategy = .base64`
2017-11-13 22:15:43 +08:00
wing328
8b251555ac update php symfony petstore, remove spaces in empty line 2017-11-09 16:36:25 +08:00
ehyche
b716b378c4 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
2017-10-12 17:35:59 +08:00
ehyche
8067612e06 Handle when response is a file URL. (#6469)
This is the equivalent change in the swift4 module which was made in the swift3 module in this PR:

https://github.com/swagger-api/swagger-codegen/pull/6274

This updates AlamofireImplementations.mustache to handle when the response is an URL. It also makes changes in the generated sample code for:

* default configuration (no promisekit or rxswift)
* promisekit
* rxswift

Also, in order to build, the generated code needed to be updated with the change in CodableHelper which changes dataDecodingStrategy to ".base64" from its previous definition in earlier Xcode 9 betas.
*
2017-09-12 14:37:39 +08:00
jaz-ah
565844585e [Swift3/Swift4] update all cocoapods for swift3/swift4 (#6441)
* [Swift] update all cocoapods for swift3/swift4

* fix subspec specification
2017-09-07 00:56:48 +08:00
wing328
e60034ec7d update swift petstore samples 2017-08-04 01:01:19 +08:00
Hans-Christian Esperer
3cb36738b1 Fix issue #6212 POD Generated podfile doesn't include all generated swift files #6212 (#6220)
* Reference all generated swift files in the podfile

* Update test files
2017-08-04 00:46:01 +08:00
ehyche
2ce3365eaf Add a swift4 client generator (#6010)
* Add a swift4 client generator

* Updates per review comments:

- Changed Alamofire dependency from 4.0 to 4.5
- Added "Codable", "Encodable", and "Decodable" to list of reserved words in generator
- Ran "pod update" in default, promisekit, and rxswift samples test projects
2017-07-09 01:33:52 +08:00