Skip to content

[BUG] [SWIFT] Array items cannot be nullable #22355

@dan-magnusson-lowes

Description

@dan-magnusson-lowes

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

In the Swift 6 codegen array item types cannot be nullable.

openapi-generator version

Latest: 7.17.0
Not a regression

OpenAPI declaration file content or url
        ArrayWithNullableItemsModel:
          required:
            - foo
          properties:
            foo:
              type: array
              items:
                type: string
                nullable: true
Generation Details

Expected:

public struct ArrayWithNullableItemsModel: Sendable, Codable, ParameterConvertible, Hashable {

    public var foo: [String?]

    public init(foo: [String?]) {
        self.foo = foo
    }
    ...
}

Actual:

public struct ArrayWithNullableItemsModel: Sendable, Codable, ParameterConvertible, Hashable {

    public var foo: [String]

    public init(foo: [String]) {
        self.foo = foo
    }
    ...
}
Steps to reproduce

See above.

Related issues/PRs

#19070 - Kotlin bug report
#19080 - Kotlin PR
#19157 - TypeScript PR

Suggest a fix

On line 742:

return ModelUtils.isSet(p) ? "Set<" + getTypeDeclaration(inner) + ">" : "[" + getTypeDeclaration(inner) + "]";

Account for nullable item schemas in the way the Kotlin generator does since PR 19080, with a getItemsTypeDeclaration(Schema items) function.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions