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
This commit is contained in:
ehyche
2017-10-12 05:35:59 -04:00
committed by wing328
parent 590754f4f4
commit b716b378c4
177 changed files with 7610 additions and 579 deletions

View File

@@ -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 {