feat(jsonschemagen): emit propertyNames from inlined-dict key slot constraints#16
Open
jdsika wants to merge 1 commit into
Open
feat(jsonschemagen): emit propertyNames from inlined-dict key slot constraints#16jdsika wants to merge 1 commit into
jdsika wants to merge 1 commit into
Conversation
8a292b2 to
29f18b0
Compare
29f18b0 to
908094b
Compare
…nstraints For an inlined-as-dict slot whose range class has an identifier/key slot, render the key slot's string-applicable constraints onto JSON Schema propertyNames (draft-06+) instead of dropping them. In the inlined-dict form the mapping key is the identifier value, so the key slot's constraints constrain the keys. JSON object keys are always strings, so only pattern, enum (equals_string_in) and a string const (equals_string) are emitted; numeric minimum/maximum, numeric const (equals_number) and allOf are excluded -- a numeric const would otherwise reject every key. structured_pattern is honored when materialize_patterns is enabled, consistent with value patterns. Backward compatible: emitted only when a string-applicable key constraint applies. Signed-off-by: jdsika <carlo.van-driesten@vdl.digital>
908094b to
b49cce8
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
For an inlined-as-dict slot (
inlined: true,inlined_as_list: false) whose rangeclass has an
identifier/keyslot, render the key slot's string-applicableconstraints onto JSON Schema
propertyNames. Previously these were silentlydropped, leaving the generated schema strictly looser than the model declares.
Motivation (standards)
Grounded at both ends:
the inlined-dict form the dictionary key is the identifier value of the range
class (not repeated in the value object: "it is acting as a key for that object, it
doesn't need to be included"). So constraints on the identifier/key slot are, by
LinkML's serialization, constraints on the keys.
propertyNames, Applicatorvocabulary) — the subschema is applied to each property name, which "will always
be a string."
propertyNamescomposes conjunctively with the existingadditionalPropertiesvalue schema.Changes
get_value_constraints_for_slothelper, then emit the string-applicable subsetonto
propertyNames:pattern,enum(equals_string_in), and a stringconst(equals_string).strings:
minimum/maximumare no-ops on strings, and a numericconst(
equals_number) would reject every key.allOf(fromrange_expression) islikewise not emitted onto keys.
structured_patternis honored whenmaterialize_patternsis enabled, identical tohow value patterns are handled (documented in-code).
propertyNamesis emitted only when a string-applicable keyconstraint applies.
Notes
propertyNamesis available since draft-06; the generator emits draft 2019-09.patternemission.
Test
Parametrized over
identifier/keykey slots; covers literalpattern,equals_string_in(enum), stringequals_string(const),structured_pattern(with/without materialization), and behavioral validate good/bad-key checks. Negative
controls assert that a numeric
constand numericminimum/maximumproduce nopropertyNames(so numeric-string keys are not wrongly rejected), and that anunconstrained key slot is unchanged.