Configuration modes "Type" and "Ref"
The JSON Configurator has new configuration items:
- Type
- Ref
These cannot be defined in the same node. A JSON node can support one of these properties.
If an existing JSON file has both properties, then after saving changes, the JSON configuration automatically adjusts the format.
If a node is Ref, then it should have no Type property. Or, Type is ignored. If Type and Ref conflict, then some tools identify the schema to be invalid.
The conversion format follows these rules.
- When Ref properties are removed. is selected,
- When a JSON node selected Ref is selected, all other properties belonging to the current node are removed.
The IDE can only create a JSON schema using the Type
or
$ref
node.
The engine can change the current logic to loading the $ref
node before the
Type
node. This only happens when the schema has both $ref
and Type
.
If you must keep the same translation result, then the only way to do this is
to delete the $ref
node from your JSON schema.
Schema References With $ref
The $ref
keyword is used to reference a schema, and provides the ability
to validate recursive structures through self-reference.
An object schema with a $ref
property must be interpreted as a
$ref
reference. The value of the $ref
property must be a
URI reference. Resolved against the current URI base, it identifies the URI of a schema to
use. All other properties in a $ref
object are ignored.
Caveats:
- The URI is not a network locator, only an identifier. It is unnecessary for a schema to be down-loadable from the address if it is a network-addressable URL. Implementations should not assume they should perform a network operation when they encounter a network-addressable URI.
- A schema must not be run into an infinite loop against a schema. For
example, if two schemas "#alice" and "#bob" both have an
allOf
property that refers to the other, a built-in validator might get stuck in an infinite recursive loop trying to validate the instance. - Schemas should not make use of infinite recursive nesting.
Here is an example of a JSON schema validator tool. If the type of $ref
field does not match with type
field, then the validator identifies the schema as invalid.
Schema:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"description": "Modified JSON Schema draft v4 that includes the optional '$ref' and 'format'",
"definitions": {
"positiveInteger": {
"type": "integer",
"minimum": 0
}
},
"type": "object",
"properties": {
"maxLength": {
"type": "integer",
"$ref": "#/definitions/positiveInteger" }
}
}
Data:
{
"maxLength": "A36697"
}