The json schema produced by inheriting from a dataclass containing an inner class, and modifying the inner class in the inherited class is incorrect.
In the example below, there is a dataclass Top with an inner dataclass called Inner. If you inherit a new class from Top and add a new element to it's inner class, then the json schema produced doesn't include the new element in the new Inner:
@dataclass
class Top(JsonSchemaMixin):
@dataclass
class Inner(JsonSchemaMixin):
a: int
b: int
x: float
y: Inner
@dataclass
class TopDerived(Top, JsonSchemaMixin):
@dataclass
class Inner(Top.Inner, JsonSchemaMixin):
c: int
y: Inner
typing's get_type_hints correctly identifies that Inner in the derived class is defined in the derived class, and has c: int:
**Note*** - workaround
Changing the inner class name in the derived class does fix the problem, as the naming isn't then confused:
@dataclass
class Top(JsonSchemaMixin):
@dataclass
class Inner(JsonSchemaMixin):
a: int
b: int
x: float
y: Inner
@dataclass
class TopDerived(Top, JsonSchemaMixin):
@dataclass
class InnerNew(Top.Inner, JsonSchemaMixin):
c: int
y: InnerNew
(in relation to https://github.com/s-knibbs/dataclasses-jsonschema/issues/137#issue-709278266)
The json schema produced by inheriting from a dataclass containing an inner class, and modifying the inner class in the inherited class is incorrect.
In the example below, there is a dataclass
Top
with an inner dataclass calledInner
. If you inherit a new class fromTop
and add a new element to it's inner class, then the json schema produced doesn't include the new element in the new Inner:typing's get_type_hints correctly identifies that Inner in the derived class is defined in the derived class, and has
c: int
:Attempting to instantiate a
TopDerived
without ac
also throws expected exception:Problem
The schema produced by the above fails to use the new defintion of
Inner
defined inTopDerived
:**Note*** - workaround Changing the inner class name in the derived class does fix the problem, as the naming isn't then confused:
produces a schema of: