Reputation: 5473
I am using pydantic in my project and am using its jsonSchema functions.
I have defined some models using class MyModel(BaseModel)
and can get the schema of the model using MyModel.schema()
.
How can I obtain the json schema when the model is used together with typing.Type
? For example the following:
typing.List[MyModel]
typing.Optional[MyModel]
typing.Union[MyModel1, MyModel2]
Example of what I would like to obtain:
MyModelList = typing.List[MyModel]
MyModelListSchema = get_schema(MyModelList)
Upvotes: 0
Views: 1248
Reputation: 5473
This is now doable using pydantic and __root__
attribute.
class MyModelList(BaseModel):
__root__: typing.List[MyModel]
MyModelListSchema = MyModelList.schema()
Upvotes: 2