Closed jaymccon closed 4 years ago
I could probably add a class argument to control whether additional properties are allowed or not:
class Person(JsonSchemaMixin, allow_additional_props=False):
name: str
age: int
This will need to be False
by default to preserve backwards compatibility.
thanks for this @s-knibbs. When can we expect a release to pip ?
Thanks for the great work on this project, been really useful thus far.
We used
"additionalProperties": false
for objects in our (hand-written) json-schema's, which was helpful to prevent invalid inputs. In this project I see no way of achieving the same.This is especially problematic with items that have defaults, if a field name is typod validation will still pass, but the resulting object will have unexpected values.
desired validation can be achieved by updating
dataclass_jsonschema/__init__.py
on line 690:I'm happy to pr a change, but not sure if I've missed some way to do this that is already catered for, or even if others want this behavior (One thought to make it optional is to provide an additional mixin
StrictJsonSchemaMixin
that adds this)