New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature Request: Constraint for single occurrence of a property structure in JSON Schema #1488
Comments
MrJarnould
changed the title
Feature Request: Constraint for Single Occurrence of a Property Structure in JSON Schema
Feature Request: Constraint for single occurrence of a property structure in JSON Schema
Feb 11, 2024
This was previously discussed in #1077. We decided to extend In short, this is happening and we have agreement on how we want it to happen, but it could still be a while until we can put out a new release that includes it. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Problem Statement
The JSON Schema specification currently lacks support for ensuring that a specific property structure is defined once and only once within an object with dynamically named properties. This capability is essential for JSON representations of relational database tables, which require exactly one primary key column.
Reference to Related GitHub Issue
This feature request is related to ongoing discussions, specifically mentioned in json-schema-org/json-schema-spec#1358, which addresses the need to apply the
contains
keyword to object structures.JSON Schema (Current)
Here is the schema that demonstrates the current validation approach, which allows dynamic keys to be associated with either a
primaryKeyProperty
or atextProperty
, but lacks the ability to enforce one and only one instance ofprimaryKeyProperty
:Example JSON Instances
Instance that Should Pass Validation:
Instance that Incorrectly Passes Validation:
The above instance should fail validation because it has more than one occurrence of the
primaryKeyProperty
structure, which is against the intended constraint.Limitations of Current Keywords
The existing keywords within JSON Schema do not provide a way to limit the number of occurrences of the
primaryKeyProperty
structure within an object. ThepatternProperties
andoneOf
are currently used to validate individual properties but cannot enforce the rule thatprimaryKeyProperty
must be limited to a single occurrence within the object.Proposed Solution
To address this limitation, we propose the introduction of a new keyword or the extension of an existing keyword to perform this validation. Possible solutions could be:
objectContains
, which would ensure that a specific structure appears exactly once within an object.contains
keyword to validate that an object contains a particular property structure only once.Conclusion
Enforcing that a
primaryKeyProperty
structure appears once and only once within an object's properties is a crucial feature for JSON Schema, enhancing its ability to model certain data structures that resemble relational databases. Thank you to @gregsdennis and @jdesrosiers for their guidance on this issue (https://json-schema.slack.com/archives/C5CF75URH/p1707258032879409).The text was updated successfully, but these errors were encountered: