-
Notifications
You must be signed in to change notification settings - Fork 6k
Add polymorphism in the PHP client #1440
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
Conversation
@arnested thanks for the PR :) Do you mind running (I'll include the PHP unit test as part of the CI later...) |
I have pushed a regenerated version of the PHP petstore sample (SHA). There are also some other changes though - probably because the sample hasn't been regenerated in a while. I have rebased the pull request against latest master. I hadn't noticed the phpunit tests before. Thank you for pointing me towards them. The tests throw one error - but that error was also present prior to the pull request (I tested to be sure):
|
I submitted a fix for the test case error in #1451. |
The branch has been rebased on current master. Besides I managed to get polymorphism into the PHP client API part. The client API will now be able handle responses in all subclasses of a model and use the models The client API part requires a snapshot release of Swagger Parser because it contained a bug. Because of that I haven't merged the client API into this pull request. Instead it is located in a separate branch (based on top of this pull request). See the additional changes here: https://github.com/arnested/swagger-codegen/compare/php-polymorphism-model...arnested:php-polymorphism-client. Feedback on all this would be appreciated! |
Just a short reminder for when I look into this again. The discriminator property should probably/maybe not have a setter method and the getter method should probably/maybe just return the class name (via reflection or just hardcoded via the mustache templates). |
Hey folks! Is there any update on this? Should I expect this to be merged soon? Please let me know if there's anything I can help with to get this merged. Thanks! |
@wing328 did this look OK to you? |
Give me a couple of days to bring this up to date. I'll probably find time during the weekend. |
Thanks @arnested You may want to leverage the test spec (modules/swagger-codegen/src/test/resources/2_0/discriminatorTest.json) added via #2202 for discriminator support by updating the test case with it: https://github.com/swagger-api/swagger-codegen/pull/2202/files#diff-a5d745502133504837979497063fbfc1R47 |
Thank you for the pointer to #2202, @wing328. I hadn't noticed that one. I just pushed my current implementation to this pull request. My implementation includes inheritance in the PHP client models and adds polymorphism to the PHP client as well. My work also includes adding support for the discriminator but I will have to look closer into the work of #2202 to see whether I could use that implementation instead or if they don't touch the same area. My current version is rebased on master and so includes the change from #2202. At least it doesn't break my use cases with both implementations present at the same time. The work I just pushed to this pull request is what we are actually using to generate a PHP API client for our current project (launched to production two weeks ago). |
I had a look into #2202 and it implements part of what I was implementing in I adapted my implementation to take advantage of #2202. So what does this pull request really do now?
We have basically been using this implementation since November and I think it is ready to be merged. @emrahs, if you still have time to help out it would be nice if you could take this for spin and report back. I ran the phpunit test-suite and it succeeds. |
And I just added a test case ( |
@arnested thanks for the work and adding an test case in |
Add polymorphism in the PHP client
Add polymorphism in the PHP client
This pull request adds polymorphism in the PHP clients model part.
Models with an
allOf
definition will now be generated as proper class inheritance.Because I needed to separate the
$swaggerTypes
,$attributeMap
,$setters
, and$getters
static properties into the parent class and subclass I had to introduce static methods for accessing the complete array of those values instead of accessing them directly. This change uses PHP features only present in PHP 5.4 and later (I don't know what version is currently supported but PHP 5.3 is deprecated anyway).I also tried to introduce polymorphism in the PHP client api part but I'm stuck on how to access the value of the
discriminator
attribute inDefaultCodengen.java
sfromOperation()
method. Have a look at this code patch: https://github.com/arnested/swagger-codegen/commit/c8a6129eb62c898b347d5d20aecf2bc1557ece20. Any advice would be appreciated!