-
Notifications
You must be signed in to change notification settings - Fork 6k
[Swift] Add public initializer for modelObject. #7652
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Swift] Add public initializer for modelObject. #7652
Conversation
I found the same issue while testing 2.4.0 with the new struct models.
Thus we have to provide an initializer. Memberwise synthesized initializers are set to |
I tested your changes and they're pretty well working 🎉 . Thanks! |
I think this is make sense. when we converted from class to struct, maybe we forget that memberwise initializer in public struct disappear. unless we merged, they cannot initialize struct from outside. @wing328 This PR should be merged ASAP. Could you merge this PR? |
{{/isEnum}} | ||
{{/allVars}} | ||
|
||
{{#hasVars}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIT: should be as below for indent
{{/allVars}}
{{#hasVars}}
public init({{#allVars}}{{name}}: {{{datatypeWithEnum}}}{{^required}}?{{/required}}{{#hasMore}}, {{/hasMore}}{{/allVars}}) {
{{#allVars}}
self.{{name}} = {{name}}
{{/allVars}}
}
{{/hasVars}}
{{#additionalPropertiesType}}
The change looks reasonable to me. Merging it into master. |
PR checklist
./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\
.3.0.0
branch for changes related to OpenAPI spec 3.0. Default:master
.Description of the PR
#6941
Add explicit public initializer again for modelObject.mustache.
Initializers are no longer see from other Xcode targets after merged the above issue. Swift struct can omit explicit initializer, but is necessary if reference it from outer packages.
In my case, I usually generate a CocoaTouch Framework from generated codes and reuse it via Carthage.