Open inforeqd512 opened 6 years ago
Can you try the latest master? I remember there were PRs merged into master to improve interoperability with ObjC
The SNAPSHOT version of 2.3.0 (master) can be found in the README.
Thanks for your reply. Can you pls give an indication of when would 2.3.0 be available as a stable version.
Sorry no ETA. We hope to release it before year end.
Thanks for this. :-)
Ran the YAML against codegen Version 2.3.0 but the files still don't show the objective C compatibility annotations... Am I missing some codegen option that will turn it on?
You probably need the following option enabled:
objcCompatible
Add additional properties and methods for Objective-C compatibility (default: false)
Ref: java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar config-help -l swift4
this is how we tried it java -jar swagger-codegen-2.3.0.jar generate -c swift4-objc-comp.json -i petstore.yaml -l swift4
swift4-objc-comp.json { "objcCompatible":true }
tried it with a value of 1 still did not get the model classes with the objc compatibility annotations. Would it be possible for you to pls attach a sample that works?
Or maybe can you let me know some possible things I can try?
(I'll provide a reply later today. Very busy these days...)
gentle reminder only....
@inforeqd512 I would suggest you try the following:
1) Swift 3 Petstore client (objcCompatible): https://github.com/swagger-api/swagger-codegen/tree/master/samples/client/petstore/swift3/objcCompatible
2) Swift 4 Petstore client (objcCompatible): https://github.com/swagger-api/swagger-codegen/tree/master/samples/client/petstore/swift4/objcCompatible
If these work for you, then it's likely due to a problem when generating the Swift client in your machine.
by objective C compatibility I thought the codegen would generate the swift files with @objc @objcmembers keywords so that the functions/properties are exposed to objective c. At least for the model objects deserialised from the response. Is there a way to do this using config for objects that need to be bridged to objective C?
In your above code, also I could not see this happening....
@inforeqd512 what about customizing the Swift4 templates to add the @objcmembers
keywords and use the templates with the -d
option?
yes. was thinking about this as the last resort ... but wanted to avoid tampering with templates so we can just use the out of box implementations each time.. however will give this a go as it would be nice to know how to use this feature.
@inforeqd512 we can leverage the objcCompatible
option to add the @objcmembers
keywords. Something like this:
{{#objcCompatible}}
@objcmembers
{{/objcCompatible}}
I know this is an old item, but it's still open. Since this ticket was opened, there has also been an option added (useModelClasses
) but then taken away so that Swift4/5 always generates struct
instead of class
. However, #useModelClasses
still appears in the template files and is mentioned in the .java source files, but no longer seems to work as an option.
I'd like to propose making the following changes to Swift 4 and 5:
if objcCompatible
is true:
class
instead of struct
(old behavior of useModelClasses
)NSObject
(and Codable
)@objcMembers
objcCompatible
, which only generates xxxNum
computed properties with a type of NSNumber
for any boolean property types. We are not using these, but this is for backwards compatibility.An alternative would be to introduce another option named objcInterop
that would do these same things, preserving the existing behavior of objcCompatible
and keep useModelClasses
retired.
@wing328 / @inforeqd512 , if you're still listening, what do you think? I'm working on a PR for these changes now, since have some Objective-C classes that are unable to use the generated Swift classes as-is.
Description
We're looking to use Swagger codegen with SWG v3.0 to generate the model and api files. However, we need to use these with existing Objective C project eg. Need the model obejcts returned in the response to be stored in local model to be used with ObjC View controllers.
Swagger-codegen version
verion 2.2.3
Swagger declaration file content or url
any file will do. Nothing specific
Command line used for generation
plain generate commanf for -l swift4
Steps to reproduce
generate any SWG v3.0 file into swift classes
Related issues/PRs
Suggest a fix/enhancement
Along with declaring Codeable, which you already do, the model objects need to be subclassed from NSObject, have @objcMembers annotation etc.