s-knibbs / dataclasses-jsonschema

JSON schema generation from dataclasses
MIT License
166 stars 38 forks source link

Fix nested union dataclasses #119

Closed ghost closed 2 years ago

ghost commented 4 years ago

Fixes issue #118

snorfalorpagus commented 4 years ago

@narakhan Does the proposed change look OK to you? If so can you update your MR?

richard-moss commented 3 years ago

Hi all,

I had this problem with nested Union, and tried applying both changes above, but was still have the schema only produce the first listed cliass in a Union.

I did some more testing on my side, and it could be an issue where my Union was also Optional, ie I was using

    # A, B defined already
    a: Optional[Union[A,B]] = None

In the case above, only A would be defined in the schema. If I removed the Optional typing, and default of None, and so had instead the definition below (as matches the test.py test), then both definitions A and B would be included in the schema:

    a: Union[A,B]
jobh commented 3 years ago

@richard-moss I have the same problem, see #147. I think it is another issue, not addressed by this PR.