openapi-python-client icon indicating copy to clipboard operation
openapi-python-client copied to clipboard

Support discriminator for polymorphic types and support oneOf

Open bowenwr opened this issue 5 years ago • 1 comments

Is your feature request related to a problem? Please describe.

When an endpoint returns oneOf several different classes, currently it returns an empty object. Sample component snippet:

    ReturnedObject:
      oneOf:
        - $ref: '#/components/schemas/PolymorphicType'
        - $ref: '#/components/schemas/AnotherPolymorphicType'

Describe the solution you'd like

Support discriminators to be able to deserialize polymorphic types.

bowenwr avatar Oct 16 '20 14:10 bowenwr

I tested this with the latest code on main (roughly 0.7.0-rc.1) and it does attempt to generate proper responses now using the same code it would for unions inside a model (basically a series of try/except). So it's better than nothing, though for sure we still should add discriminators in a future version.

dbanty avatar Nov 14 '20 16:11 dbanty