I posted this as a reply elsewhere, but I think it's actually worth tackling in a separate thread. I have written up some thoughts about JSON Schema and inheritance:
There has been some dust kicked up about schema inheritance/extension for a while. The underlying issue is: people have wanted to get an error when unfamiliar properties are used, because this could indicate a mis-spelt property name or some other mistake. By default, v4 JSON Schema validators do not raise this as an error.
Often, people have attempted to emulate this behaviour using "additionalProperties":false. The problem is that this keyword was designed to restrict properties to an exact set. People have proposed various modifications, and Francis even proposed a merge/patch system which would allow later schemas to modify this exact set to include new properties.
I have an alternative proposal, which I think is a lot simpler, and tackles the original problem (instead of trying to beat "additionalProperties" into a different shape). My proposal is:
For v5 schemas, by default, any property that is not described by a schema should be raised as an error. If you want free-form properties in a particular schema, then "additionalProperties":true will describe those properties.
I believe this proposal:
- Lines up with many people's intuition about unfamiliar properties
- Allows schema authors to opt in to unfamiliar properties - so the schema author gets to choose what they want on a schema-by-schema basis
- Preserves the existing inheritance semantics
- Is highly compatible with v4 (you can write schemas which are still meaningful for v5/v4 simultaneously)
I think the last point is particularly important, as with the growing number of users (including some big players) relying on the v4 spec, we should avoid breaking changes unless absolutely necessary.
I think it's a neat, minimal solution to the problem people are facing. I'd like to get feedback from more people about this, and whether it would be a good fit for v5.
Geraint