Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Support top level oneOf and anyOf #388

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

Closed
forest-benchling opened this issue Apr 14, 2021 · 5 comments
Closed

Support top level oneOf and anyOf #388

forest-benchling opened this issue Apr 14, 2021 · 5 comments
Labels
✨ enhancement New feature or improvement 🍭 OpenAPI Compliance Supporting a new bit of the OpenAPI spec

Comments

@forest-benchling
Copy link
Collaborator

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: #387

Expected behavior
It should work the same way as it does for model properties, i.e., constructing a union type.

OpenAPI Spec File
#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]
@forest-benchling forest-benchling added the 🐞bug Something isn't working label Apr 14, 2021
@forest-benchling
Copy link
Collaborator Author

cc @packyg @bowenwr @dtkav @adamrp

@forest-benchling
Copy link
Collaborator Author

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?

@dbanty dbanty added this to the 0.10.6 milestone Oct 17, 2021
@dbanty dbanty modified the milestones: 0.10.6, 0.10.7, 0.10.8 Oct 25, 2021
@dbanty
Copy link
Collaborator

dbanty commented Dec 18, 2021

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.

@dbanty dbanty removed this from the 0.10.8 milestone Dec 18, 2021
@dbanty dbanty added ✨ enhancement New feature or improvement and removed 🐞bug Something isn't working labels Dec 18, 2021
@dbanty dbanty changed the title Models generated with oneOf or anyOf have empty properties Support top level oneOf and anyOf Dec 18, 2021
@spacether
Copy link

spacether commented Dec 28, 2021

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.

@dvaerum
Copy link

dvaerum commented Jun 6, 2022

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 😉

@dbanty dbanty added the 🍭 OpenAPI Compliance Supporting a new bit of the OpenAPI spec label Aug 13, 2023
@openapi-generators openapi-generators locked and limited conversation to collaborators Aug 13, 2023
@dbanty dbanty converted this issue into discussion #829 Aug 13, 2023

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
✨ enhancement New feature or improvement 🍭 OpenAPI Compliance Supporting a new bit of the OpenAPI spec
Projects
None yet
Development

No branches or pull requests

4 participants