Skip to content

oneOf array of simple types bug - propose fix #476

Closed

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)

Activity

  1. Julian commented on Oct 8, 2018

    @Julian
    Member

    Hi.

    Not sure you have the right repo here.

    If you do, can you update your description to be runnable?

    Thanks!

  2. GrahamJB1 commented on Oct 8, 2018

    @GrahamJB1
    Author

    Hi,
    Sorry I missed the imports at the top, otherwise it is runnable. Just paste into a python script.
    The failure is against your latest release.
    Thanks.
    Yours,
    Graham

  3. GrahamJB1 commented on Oct 8, 2018

    @GrahamJB1
    Author

    That is 3.0.0a3, and the title ' handle basic types above' in the proposed solution is of course a comment mangled by the wiki

  4. Julian commented on Oct 8, 2018

    @Julian
    Member

    Thanks.

    What bug is being reported? And what's pjs.ObjectBuilder, that's not an object defined in this repo.

  5. GrahamJB1 commented on Oct 8, 2018

    @GrahamJB1
    Author

    I am deeply sorry - you are quite right, I am using 3.0.0a3 in conjunction with python jsonschema object and the bug is in their library. Many thanks for your prompt reply, and thank you for the high quality of your library !

  6. Julian commented on Oct 8, 2018

    @Julian
    Member
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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