Skip to content

[Swift 5] Model struct initializer should have parameters set to nil by default #10522

@saltwat5r

Description

@saltwat5r
Description

Hi!
As in the title - model struct initializers should have parameters set to nil by default.

Swagger-codegen version

3.0.22

Swagger declaration file content or url
{
    "swagger": "2.0",
    "definitions": {
        "Category": {
            "type": "object",
            "properties": {
                "id": {
                    "type": "integer",
                    "format": "int32",
                    "description": "category ID"
                },
                "name": {
                    "type": "string",
                    "description": "category name",
                    "example": "Home"
                }
            }
        }
    }
}
Command line used for generation

java -jar .../swagger-codegen-cli/target/swagger-codegen-cli.jar generate -l swift5 -i swagger.json -c config.json -o .

Steps to reproduce
Suggest a fix/enhancement

Generated code should look like below:

public struct Category: Codable {

    /** category ID */
    public var _id: Int?
    /** category name */
    public var name: String?

    public init(_id: Int? = nil, name: String? = nil) {
        self._id = _id
        self.name = name
    }
}

But currently looks like this:

public struct Category: Codable {

    /** category ID */
    public var _id: Int?
    /** category name */
    public var name: String?

    public init(_id: Int?, name: String?) {
        self._id = _id
        self.name = name
    }
}

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions