Skip to content
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

Which languages support polymorphism? #4622

Open
boldtrn opened this issue Jan 23, 2017 · 12 comments
Open

Which languages support polymorphism? #4622

boldtrn opened this issue Jan 23, 2017 · 12 comments

Comments

@boldtrn
Copy link

boldtrn commented Jan 23, 2017

Usecase:

My goal is to generate clients from a swagger spec in most of the available languages.

Problem:

My API requires to use polymorphism. So polymorphism seems to be not fully supported by the swagger-codegen yet? Is there an overview to see which language supports it or not. I think this would be really helpful (not only to me :)).

What I found out by reading issues is that: Java,PHP, Swift, and ObjC support polymorphism. It seems that Python does not support polymorphism. How about the other languages?

@dkdndes
Copy link

dkdndes commented Jan 23, 2017

@boldtrn
Copy link
Author

boldtrn commented Jan 24, 2017

@dkdndes Thanks for your response, but I was not referring to the general possibility of the language to support polymorphism, but if the swagger-codegen is able to create code from a swagger spec that uses polymorphism. This seems not to be true for every language so I was wondering if there might be a way to get an overview.

@wing328
Copy link
Contributor

wing328 commented Jan 24, 2017

@boldtrn I believe C# and Javascript have better support for polymorphism and I agree with your comment that some languages (e.g. Flash/Actionscript) do not have proper polymorphism support yet.

Which language(s) you would like to see polymorphism support? Is that something you can also help contribute?

@boldtrn
Copy link
Author

boldtrn commented Jan 24, 2017

@wing328 Thanks for your reply.

Which language(s) you would like to see polymorphism support?

Actually I'd love to generate clients for all available languages. So it would be great if at least all major languages would support polymorphism. I think if we had to skip some minor languages that would be fine. The alternative would be to model our API without polymorphism. This would make our API less powerful, but the essentials would still work.

Is that something you can also help contribute?

The languages I would feel comfortable to contribute something like this already support polymorphism. I think it might not be the best idea to contribute something like this to a language I don't know well enough. So I think for now I would go without polymorphism and accept that the API is less powerful.

@sixers
Copy link

sixers commented Feb 6, 2017

Do Python, Ruby & Scala have polymorphism support? If not, is anyone working on this?

@wing328
Copy link
Contributor

wing328 commented Feb 7, 2017

@sixers I don't think anyone is working on it and would suggest you to start with Python first. Thanks for offering help to add the polymorphism support.

@cacti77
Copy link

cacti77 commented Feb 16, 2017

@boldtrn Re the use case in your OP I wrote several REST APIs that used polymorphism in the Swagger Editor and then used the same to generate clients in Python and server stubs in Java Spring. But I ran into various issues with polymorphism and enums which resulted in significant rewrites of the APIs, making them larger and uglier in my opinion.

Frankly I was annoyed that the Swagger Editor doesn't highlight which languages or client/server options do not fully support the OpenAPI spec. Ideally the editor wouldn't have shown those languages at all, or put 'beta' next to their name to indicate their working status. To my mind a language client/server option shouldn't be listed in the editor unless it passes all the unit tests required for 100% compliance with the spec. Until something like this happens I'll be very wary of generating clients/server stubs in future - you simply can't assume they will meet the spec and your API's use of the spec.

I use Apache Thrift for cross-language comms as well and that has a helpful matrix showing where support is less than 100% and what issues are outstanding - https://wiki.apache.org/thrift/LibraryFeatures?action=show&redirect=LanguageSupport . Admittedly that looks out of date but it would be good if Swagger could have a web page with a similar matrix.

@wing328
Copy link
Contributor

wing328 commented Feb 20, 2017

Admittedly that looks out of date but it would be good if Swagger could have a web page with a similar matrix.

Totally agreed. We'd a look at https://kangax.github.io/compat-table/es6/ before and started with a Google spreadsheeet but that didn't go well.

I'll try to folk https://kangax.github.io/compat-table/es6/ and put something together after the 2.3.0 release.

Ideally the editor wouldn't have shown those languages at all, or put 'beta' next to their name to indicate their working status.

Agreed. Some language generators (especially the new one) are less mature than the others. Putting "Beta" or "Alpha" next to it will help manage user expectations. (currently, some generators do have "beta" in the help text, example, but that's not shown in Swagger Editor or other tools that leverage Swagger Codgen for code/doc generation)

@cacti77
Copy link

cacti77 commented Feb 23, 2017

Thanks @wing328; I'm glad you see the need to set users' expectations here, so others don't experience the same disillusionment with Swagger that I went through!

I appreciate that a feature/issue matrix is difficult to keep up to date manually. I can imagine it might be possible to auto-populate such a table based on code coverage analysis and the automated raising of issues when unit tests fail in certain areas. But it would probably be difficult to tune and rely on the output of such a system without at least some human oversight.

@konopski
Copy link
Contributor

konopski commented Mar 1, 2017

@sixers regarding scala inheritance support
PR #4729 implements java client code generation for retrofit based calls - it can be reused for scala projects as well.

@shauntarves
Copy link

Any progress on this issue? python code generation still does not properly support polymorphism at least through the $ref approach recommended for openapi 3.

@dmccombs
Copy link

dmccombs commented Mar 6, 2020

Does the golang output of swagger-codegen support discriminator polymorphism?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants