Skip to content

Move "dependencies" to applicability group #528

Closed
@epoberezkin

Description

@epoberezkin

As requested by @handrews in #513 (comment)

The fact you can rewrite a keyword using if/then/else/required doesn't mean that it makes the keyword itself asserting any conditions. This schema:

{
  "properties": {
    "foo": {"type": "number"}
  }
}

can be rewritten as

{
  "if": {"required":["foo"]},
  "then": {
    "properties": {
      "foo": {"type": "number"}
    }
  }
}

"properties" keyword still belongs to the applicability group, even though you can rewrite it using "required", same as "dependencies".

Compare keywords definitions (ignoring property syntax of "dependencies" for now, I'll come back to it later):

"properties" (http://json-schema.org/latest/json-schema-validation.html#rfc.section.6.5.4):

Validation succeeds if, for each name that appears in both the instance and as a name within this keyword's value, the child instance for that name successfully validates against the corresponding schema.

"dependencies" (http://json-schema.org/latest/json-schema-validation.html#rfc.section.6.5.7):

If the dependency value is a subschema, and the dependency key is a property in the instance, the entire instance must validate against the dependency value.

So, for "properties", if a property name appears in the instance, you have to apply a corresponding subschema to the child instance.

For "dependencies", if a property name appears in the instance, you have to apply a corresponding subschema to the current instance.

The logic of "properties" and "dependencies" only differs in that the former applies subschemas to the child instance, and the latter to the current instance. Neither of them is making assertions on their own.

Now back to the property syntax of "dependencies". We have two possible points of view here:

  1. We can consider it just a syntactic sugar that allows to use <array of strings> as a shortcut for {"required": <array of strings>}. It's not dissimilar from the boolean form of the schema, where you can use false as a shortcut for {"not":{}}. In this case, "dependencies" keyword still applies a certain schema to the current instance, without making any assertions of its own.
  2. We can interpret it is as a separate thing completely that makes its own assertions. In this case the property syntax does not belong to applicability group. But the downside of this view is that it creates an overlap with "required" keyword by allowing two ways of asserting that property is required.

Regardless which way of looking at property syntax of "dependencies" we prefer, the schema syntax of "dependencies" still belongs to the applicability group, as it only uses a defined logic to apply subschemas to the current instance, without making any assertions of its own, which is consistent with how applicability is defined.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions