Skip to content

Conversation

@ehyche
Copy link
Contributor

@ehyche ehyche commented Nov 28, 2017

PR checklist

  • [x ] Read the contribution guidelines.
  • [ x] Ran the shell script under ./bin/ to update Petstore sample so that CIs can verify the change. (For instance, only need to run ./bin/{LANG}-petstore.sh and ./bin/security/{LANG}-petstore.sh if updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in .\bin\windows\.
  • [x ] Filed the PR against the correct branch: 3.0.0 branch for changes related to OpenAPI spec 3.0. Default: master.
  • [x ] Copied the technical committee to review the pull request if your PR is targeting a particular programming language.

Description of the PR

This change fixes this issue for swift4: #6746

I will submit a separate PR for swift3.

This should only be merged AFTER this PR is merged: #7071

Previously, when we had these three definitions:

    "ModelStringArray": {
      "type": "array",
      "description": "This defines an array of strings.",
      "items": {
        "type": "string"
      }
    },
    "ModelDoubleArray": {
      "type": "array",
      "description": "This defines an array of doubles.",
      "items": {
        "type": "number",
        "format": "double"
      }
    },
    "ModelErrorInfoArray": {
      "type": "array",
      "description": "This defines an array of ErrorInfo objects.",
      "items": {
        "$ref": "#/definitions/ErrorInfo"
      }
    },

then swift4 would generate the following:

public typealias ModelStringArray = []
public typealias ModelDoubleArray = []
public typealias ModelErrorInfoArray = [ErrorInfo]

and clearly only the generated code for ModelErrorInfoArray is correct. The problem was that our template had:

{{#isArrayModel}}
public typealias {{classname}} = [{{arrayModelType}}]
{{/isArrayModel}}

and arrayModelType is not present for primitives like String, Double, etc. However, the "parent" is always present and is correct. So I changed the template to:

{{#isArrayModel}}
public typealias {{classname}} = {{parent}}
{{/isArrayModel}}

@jaz-ah
Copy link
Contributor

jaz-ah commented Nov 29, 2017

@wing328 +1 thx @ehyche

@wing328 wing328 merged commit 76d3cb5 into swagger-api:master Dec 1, 2017
@wing328 wing328 added this to the v2.3.0 milestone Dec 1, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants