Open yeralin opened 5 years ago
This quick fix seems to work for me:
schema = JSONSchema().dump(MySchema(many=True)) # Note that the many=true is ignored
schema.update(
type='array',
items={
'type': 'object',
'$ref': schema.pop('$ref'),
},
)
Consider following schema:
Now, say my payload is of this form:
The JSON Schema that could describe this payload could be:
So, in theory to generate this schema using
marshmallow-jsonschema
we could do the following:However, that's not the case. The resulting schema would be:
Setting
many=True
during schema instantiation does not affect the resulting JSON schema. According to https://github.com/fuhrysteve/marshmallow-jsonschema/blob/307a911c38a4d827d06794a04f29794fee788c4a/marshmallow_jsonschema/base.py#L81 It will always be set to"type": "object"
irregardless ofmany
option.