swagger-api / swagger-api/swagger-codegen-generators

[swift 4] Default value for optional init params

Open
#467 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
299
Forks
439
PR merge metrics
No merged PRs in 30d

Description

Hi.

Summary:

It would be really nice if Swift model objects had a default nil value for optional parameters so for model objects with many optional parameters we can create them more simply. There's a similar issue on the swagger-codegen repo https://github.com/swagger-api/swagger-codegen/issues/8365. This is a trivial, backwards compatible change to the swift handlebars template.

Details:

Currently the template generates code like this:

public struct Order: Codable {

    public var _id: Int64
    public var petId: Int64?

    public init(_id: Int64, petId: Int64?) { 
        self._id = _id
        self.petId = petId
    }
}

It would be really nice if it have default values to the optional init methods, like this:

public init(_id: Int64, petId: Int64? = nil) { 

This seems a trivial change in the template so any objections to a pull request?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the Swift 4 Handlebars template that generates model initializers. Update the optional-parameter handling so optional init parameters default to nil, then verify that generated Swift models use the requested initializer form without changing required parameters.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
tooling
Issue type
Feature
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.