-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
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
[REQ] [Swift5] POP proposal #8653
Comments
Follow. |
This looks like something interesting. |
Hi @4brunu , I already have some templates ready on my side but only for the Combine case, I didn't support all the cases because are out of scope for me right now. Furthermore I'm not a mustache-master and I'm not sure I followed the best practices. :-) I could start from there and then we can iterate to support all the cases, but the main question here is: is that of interested for the OpenAPI community? Thanks, |
Hey @wolfAle, I was curious about this, so I made a little draft to see how many changes that would imply, and it seams that protocols have some limitations, like methods with default parameters and around visibility modifiers, but after some changes this draft, kind of "work" for most cases. Could you please check if this is what you are proposing?
This is something that I have been struggling with too.
But to try not to get away from the main issue here, I see value in this proposal, but this would need to be behind a flag for the user's to choose between the current approach and this POP approach. |
Hi @4brunu , yeah, your draft looks ok! Of course with some iterations over it I believe we could further improve the outcome, but that's what I meant and what I've being using in the last year or so. :-) I'm happy to help you out with the implementation, if you'd like me to, but I'll have a few questions such as:
About Alamofire/PromiseKit: my feeling is that they are not needed anymore and it would save a lot of work to deprecate them, but that's not my call really. I'd be happy if there was a way to invite people to give a feedback on this thread, but I guess there isn't. :-/ |
And, BTW, it's a bit unclear to me what's the relationship between OpenAPI and Swagger right now. I thought that one was the evolution of the other, but I just found out that there's a (quite recent) Swagger version of the generator with the protocol approach: 🤔 |
Here is the reasoning behind the fork. Since the fork, the swift generators in swagger-codegen and openapi-generator started to diverge a bit in terms of feature set. Features in openapi-generator that are not present in swagger-codegen:
Features in swagger-codegen that are not present in openapi-generator:
This is my personal response, so VSCode or IntelliJ IDEA.
Not that I'm aware of, I learned it by comparison, but here are the docs. Instead of creating a new resources directory to support POP, I would prefer to create if elses the current resources, unless the changes are huge, but from the draft that I created it doesn't seem so. Your PR is more than welcome, and if you have questions, or want feedback on something, or need help in something, feel free to ping me 🙂 |
By the way, there is a huge PR should be merged soon #9625, and it will change a lot of files, so maybe you might want to wait for that PR to get merged before doing this, to avoid merge conflicts. |
Now that #9625 is merged, I think it's safe to start working on POP implementation 🙂 |
Hey @wolfAle, |
Hi @4brunu , honestly, didn't had any chance to work on this :-( Hopefully I'll find some free time to get to the bottom of it! Alessandro |
No problem, take your time 🙂 there is no pressure, I was just looking at some issue and remembered this one |
We don't have exactly this implemented, but now in the new swift 6 generator, it's possible to create instances of a class, and use instance methods instead of class methods, which makes it possible to create subclasses of the api files, with custom behaviour. Give it a try with the flag |
Hi guys,
I've been using the OpenAPI Generator for Swift 4/5 for a while now, quite happy with your work, thanks!
But after a while I struggled a bit whenever I needed to add some customisation on the generated code.
Mainly the issues I found were related to the fact that the methods are defined as
class func
.That makes it hard to:
SomethingSubclassAPI
that inherits from the generatedSomethingAPI
class and override the method. Then you would need to use the subclass around. Easy to do if that happens at the beginning of the project, much more complicated if you already used a lot the generated class aroundI then modified the templates to achieve something different.
From this:
To this:
This approach works quite well for me and it allows me to:
where
operatorAdditionally I have an autogenerated Mock version of the same protocols, that inherits from the original ones, that load content from a json in the bundle. This approach opens to the possibility of conforming to
AlertAPIPrototocol
in a target and toAlertAPIMockPrototocol
in another and being one a subprotocol to the other you can easily use polymorphism.This is just an example of what this approach can lead to. :-)
I'd love to see this approach implemented in the official OpenAPI Generator for swift, I think it could be useful for a lot of people.
Are you interested on discussing this further?
Thanks,
Alessandro
The text was updated successfully, but these errors were encountered: