swagger-api / swagger-api/swagger-codegen-generators
[swift 4] Default value for optional init params
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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