You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the code below if BaseModel is used rather than the MyBaseModel subclass, then the results are as expected, however with the code below, the JSON schema is not produced and no error is raised.
from __future__ import annotations
from pydantic import BaseModel
class MyBaseModel(BaseModel):
pass
class B(MyBaseModel):
b: A
class A(MyBaseModel):
a: str
print(B.model_json_schema())
Initial Checks
Description
In the code below if BaseModel is used rather than the MyBaseModel subclass, then the results are as expected, however with the code below, the JSON schema is not produced and no error is raised.
expected result:
{'$defs': {'A': {'properties': {'a': {'title': 'A', 'type': 'string'}}, 'required': ['a'], 'title': 'A', 'type': 'object'}}, 'properties': {'b': {'$ref': '#/$defs/A'}}, 'required': ['b'], 'title': 'B', 'type': 'object'}
(or an error advising the model hasn't been initialiased)
actual result:
{'properties': {}, 'title': 'MyBaseModel', 'type': 'object'}
If MyBaseModel has any fields set then it also works ok, e.g. this works as expected:
Appreciate this is an edge case but thought is worth noting if there's something that can be done.
Example Code
No response
Python, Pydantic & OS Version
Selected Assignee: @dmontagu
The text was updated successfully, but these errors were encountered: