Skip to content

Which languages support polymorphism? #4622

Open

Description

@boldtrn

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?

Activity

  1. boldtrn commented on Jan 24, 2017

    @boldtrn
    Author

    @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.

  2. wing328 commented on Jan 24, 2017

    @wing328
    Contributor

    @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?

  3. boldtrn commented on Jan 24, 2017

    @boldtrn
    Author

    @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.

  4. sixers commented on Feb 6, 2017

    @sixers

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

  5. wing328 commented on Feb 7, 2017

    @wing328
    Contributor

    @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.

  6. added this to the Future milestone on Feb 16, 2017
  7. cacti77 commented on Feb 16, 2017

    @cacti77

    @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.

  8. wing328 commented on Feb 20, 2017

    @wing328
    Contributor

    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)

  9. cacti77 commented on Feb 23, 2017

    @cacti77

    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.

  10. konopski commented on Mar 1, 2017

    @konopski
    Contributor

    @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.

  11. shauntarves commented on Jul 23, 2019

    @shauntarves

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

  12. dmccombs commented on Mar 6, 2020

    @dmccombs

    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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions