Support top level `oneOf` and `anyOf`
Describe the bug
If a top-level schema is defined using oneOf or anyOf, the generated model has no properties.
To Reproduce See this PR which adds a test case for the bug: https://github.com/triaxtec/openapi-python-client/pull/387
Expected behavior It should work the same way as it does for model properties, i.e., constructing a union type.
OpenAPI Spec File https://github.com/triaxtec/openapi-python-client/pull/387
Desktop (please complete the following information):
- OS: [e.g. macOS 10.15.1]
- Python Version: [e.g. 3.8.0]
- openapi-python-client version [e.g. 0.1.0]
cc @packyg @bowenwr @dtkav @adamrp
I guess on second thought here, it's unclear how we'd actually represent a model which is nothing other than a union of other models. Maybe the desired outcome of this ticket is simply to raise an error during code generation?
For oneOf we should probably make a type alias to Union[ThingOne, ThingTwo]. anyOf is a lot harder... my read of it is that it has to validate against at least one schema but can contain properties of other schemas. So we might have to generate several models, each of which has the requirements of one schema and optional fields from all of the others. Sounds messy.
I'd love to know how folks are actually using anyOf to get a better feel for how the implementation should shake out.
Openapi schemas can combine oneOf anyOf allOf and properties all in a single schema.
So I don't think that For oneOf we should probably make a type alias to Union[ThingOne, ThingTwo] would work for all cases.
What is the status for this issue? Because I am in a situation there I need it and would love to not create workarounds for it 😉