s-knibbs / dataclasses-jsonschema

JSON schema generation from dataclasses
MIT License
166 stars 38 forks source link

Invalid schema generated when using inheritance and allow_additional_props=False #111

Open s-knibbs opened 4 years ago

s-knibbs commented 4 years ago

Due to the way that $allOf and additionalProperties interact in json schema, currently, a schema that validates against nothing will be generated in the following case:

@dataclass
class Pet(JsonSchemaMixin):
    name: str

@dataclass
class Cat(Pet, allow_additional_props=False):
    hunting_skill: str
s-knibbs commented 4 years ago

To fix this will require supporting the unevaluatedProperties which was introduced in the latest JSON schema draft.

Initially, I propose to raise an error when inheritance and allow_additional_props=False are used together and later on add support for the 2019-09 draft with unevaluatedProperties once that's supported by the validation libraries.