Currently I have quite a few models defined and I want a single endpoint that can receive and return them.
My models are all different, e.g.
class A(BaseModel):
foo: str
class B(BaseModel):
bar: str
All = Union[A, B]
Considering the case where my endpoint accepts a body of the form All, and returns a new resource of that same form. I want to be able to specify that the return type All is All plus an extra id field.
i.e.
RequestAll = Union[A,B]
class ResponseAll(RequestAll):
id = str
However, when I do this, I get an error:
__init__() takes 2 positional [but more were given]
Another approach I could take is to have a RequestA and ResponseA equivalent for every type, then union Requests and Responses respectively. However, I would prefer to avoid this given the amount of types I actually have.
Is there a neat way to address this problem?