Skip to content

Support top level oneOf and anyOf #388

Description

@forest-benchling

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]

Activity

  1. forest-benchling commented on Apr 14, 2021

    @forest-benchling
    CollaboratorAuthor
  2. forest-benchling commented on Apr 19, 2021

    @forest-benchling
    CollaboratorAuthor

    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?

  3. added this to the 0.10.6 milestone on Oct 17, 2021
  4. modified the milestones: 0.10.6, 0.10.7, 0.10.8 on Oct 25, 2021
  5. dbanty commented on Dec 18, 2021

    @dbanty
    Collaborator

    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.

  6. removed this from the 0.10.8 milestone on Dec 18, 2021
  7. added and removed
    🐞bugSomething isn't working
    on Dec 18, 2021
  8. changed the title [-]Models generated with `oneOf` or `anyOf` have empty properties[/-] [+]Support top level `oneOf` and `anyOf`[/+] on Dec 18, 2021
  9. spacether commented on Dec 28, 2021

    @spacether

    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.

  10. dvaerum commented on Jun 6, 2022

    @dvaerum

    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 😉

  11. locked and limited conversation to collaborators on Aug 13, 2023
  12. converted this issue into a discussion #829 on Aug 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions