OneOf serialization doesn't work when it is a child of a multitype.
Closed this issue · 2 comments
joesolly commented
Describe the bug
OneOf serialization doesn't work when it is a child of a multitype.
Example Schema and code
"$schema": "http://json-schema.org/draft-07/schema",
"title": "myschema",
"type": "object",
"definitions": {
"MainObject": {
"title": "MainObject",
"additionalProperties": false,
"type": "object",
"properties": {
"location": {
"title": "location",
"type": ["object", "string"],
"oneOf": [
{
"$ref": "#/definitions/UNIQUE_STRING"
},
{
"$ref": "#/definitions/Location"
}
]
}
}
},
"Location": {
"title": "Location",
"description": "A Location represents a span on a specific sequence.",
"type": "object",
"oneOf": [
{
"$ref": "#/definitions/Location1"
},
{
"$ref": "#/definitions/Location2"
}
],
"discriminator": {
"propertyName": "type"
}
},
"Location1": {
"additionalProperties": false,
"type": "object",
"properties": {
"type": {
"type": "string",
"enum": ["Location1"],
"default": "Location1"
}
}
},
"Location2": {
"additionalProperties": false,
"type": "object",
"properties": {
"type": {
"type": "string",
"enum": ["Location2"],
"default": "Location2"
}
}
},
"UNIQUE_STRING": {
"additionalProperties": false,
"type": "string",
"pattern": "^\\w[^:]*:.+$",
}
}
}
>>> import python_jsonschema_objects as pjs
>>> builder = pjs.ObjectBuilder(examples['myschema'])
>>> ns = builder.build_classes()
>>> MainObject = ns.MainObject(**{'location': {'type': 'location2'}})
Expected behavior
I expect this to succeed. Instead I get an error stack trace like this:
venv/3.8/lib/python3.8/site-packages/python_jsonschema_objects/classbuilder.py:200: in __init__
setattr(self, prop, props[prop])
venv/3.8/lib/python3.8/site-packages/python_jsonschema_objects/classbuilder.py:228: in __setattr__
prop.__set__(self, val)
venv/3.8/lib/python3.8/site-packages/python_jsonschema_objects/descriptors.py:47: in __set__
if isinstance(val, typ):
E TypeError: isinstance() arg 2 must be a type or tuple of types
joesolly commented
This was not an issue in 0.3.10 but has been an issue in 0.3.11, 0.3.12, 0.3.13, and 0.3.14.
cwacek commented
Hmm. Sounds like a regression. I’m pretty sure there’s no nested oneOf test case so that’s not surprising.
I’ll try and take a look this weekend
… On May 6, 2021, at 11:51 AM, Joseph Solomon ***@***.***> wrote:
This was not an issue in 0.3.10 but has been an issue in 0.3.11, 0.3.12, 0.3.13, and 0.3.14.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.