serialize and reload (roundtrip) failed with oneOf keyword
Closed this issue · 0 comments
SebastienAndreo commented
the reification of an object previously serialized with the library failed.
the particularity of the schema: is using 'oneOf' to switch between 2 object types.
The following code and schema aim to reproduce the bug. please notice that if you serialize an object containing 'parametersA' the roundtrip will work.
Example Schema and code
schema_uri = "roundtrip.json"
builder = pjs.ObjectBuilder(schema_uri)
namespace = builder.build_classes()
data_config = """
{
"something": "a name",
"another": "a value"
}
"""
paramsTypeB = namespace.Parametersb().from_json(data_config)
somethingInstance = namespace.Something(param1="toto", param2= "tata")
somethingInstance.parameters = paramsTypeB
json_object = somethingInstance.serialize()
print(json_object)
aNewsomething = namespace.Something().from_json(json_object)
json_object2 = aNewsomething.serialize()
{
"$schema": "http://json-schema.org/draft-04/schema#",
"$id": "roundtrip.json",
"type": "object",
"properties":
{
"container": {"$ref": "#/definitions/config"}
},
"definitions": {
"config": {
"properties":{
"something": {
"allOf": [
{
"$ref": "#/definitions/params"
},
{
"properties":{
"parameters": {
"oneOf": [
{
"$ref": "#/definitions/parametersA"
},
{
"$ref": "#/definitions/parametersB"
}
]
}
},
"required": ["parameters"]
}
]
}
}
},
"params": {
"type": "object",
"properties": {
"param1": {
"type": "string"
},
"param2": {
"type": "string"
}
},
"required": [
"param1",
"param2"
]
},
"parametersA": {
"properties": {
"name": {
"type": "string"
},
"value": {
"type": "string"
}
},
"required": [
"name",
"value"
]
},
"parametersB": {
"properties": {
"something": {
"type": "string"
},
"another": {
"type": "string"
}
},
"required": [
"something",
"another"
]
}
}
}
Expected behavior
I am able to recreate the python object from the serialized JSON object.