Skip to content

oneOf array of simple types bug - propose fix #476

@GrahamJB1

Description

@GrahamJB1

basicSchemaDefn = """{
'$schema':'http://json-schema.org/draft-04/schema#',
'title':'Test',
'properties':{
'SimpleArrayOfNumberOrString':{
'$ref':'#/definitions/simparray'
}
},
'required':[
'SimpleArrayOfNumberOrString'
],
'type':'object',
'definitions':{
'simparray':{
'oneOf':[
{
'type':'array',
'items':{
'type':'number'
}
},
{
'type':'array',
'items':{
'type':'string'
}
}
]
}
}
}"""

basicSchema = json.loads(basicSchemaDefn.replace(''', '"'))
builder = pjs.ObjectBuilder(basicSchema)

ns = builder.build_classes(no_extra_parameters = True)
ns.Test().from_json('{"SimpleArrayOfNumberOrString" : [0, 1]}')


Proposed fix in classbuilder.py validate:

elif isinstance(val, list):
if len(val) and hasattr(val[0], "validate"):
for subval in val:
subval.validate()
else:

handle basic types

setattr(self, prop, val)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions