Closed ollyhensby closed 1 month ago
Code to reproduce error:
import jsonref
import stringcase
import typing as ty
from enum import Enum
from pydantic import BaseModel, Field, RootModel, ConfigDict
from ipyautoui.autoobject import AutoObject, AutoObjectForm
class Obj(BaseModel):
a: int
b: str
ObjSet = ty.ForwardRef("ObjSet")
class ObjSet(BaseModel):
obj_set: list[ty.Union[Obj, ObjSet]]
jsonref.replace_refs(ObjSet.model_json_schema())
It appears that replace_refs
has stopped working...
What does model_json_schema
return?
pyndatic<2.9
{
"$defs": {
"Obj": {
"properties": {
"a": {
"title": "A",
"type": "integer"
},
"b": {
"title": "B",
"type": "string"
}
},
"required": [
"a",
"b"
],
"title": "Obj",
"type": "object"
},
"ObjSet": {
"properties": {
"obj_set": {
"items": {
"anyOf": [
{
"$ref": "#/$defs/Obj"
},
{
"$ref": "#/$defs/ObjSet"
}
]
},
"title": "Obj Set",
"type": "array"
}
},
"required": [
"obj_set"
],
"title": "ObjSet",
"type": "object"
}
},
"allOf": [
{
"$ref": "#/$defs/ObjSet"
}
]
}
pydantic 2.9
{
"$defs": {
"Obj": {
"properties": {
"a": {
"title": "A",
"type": "integer"
},
"b": {
"title": "B",
"type": "string"
}
},
"required": [
"a",
"b"
],
"title": "Obj",
"type": "object"
},
"ObjSet": {
"properties": {
"obj_set": {
"items": {
"anyOf": [
{
"$ref": "#/$defs/Obj"
},
{
"$ref": "#/$defs/ObjSet"
}
]
},
"title": "Obj Set",
"type": "array"
}
},
"required": [
"obj_set"
],
"title": "ObjSet",
"type": "object"
}
},
"$ref": "#/$defs/ObjSet"
}
from a quick comparison it looks as though the allOf
has disappeared in the model_json_schema
for pydantic>=2.9.
I think it may be related to this change: https://github.com/pydantic/pydantic/pull/10029
I've posted an issue about this on the jsonref
repository: https://github.com/gazpachoking/jsonref/issues/68
Describe the bug When pydantic>=2.9, the tests fail: