Skip to content

Commit 9c249aa

Browse files
committed
Change "id" to "$id", retain "id" for compatibility.
This addresses issue #20. "$id" matches "$schema" and "$ref", establishing a clear naming pattern for all keywords defined in the core specification. This also reduces confusion in the very common case where objects described by the schema have an "id" property. The current plan is to continue to allow for "id" until a migration tool can be provided.
1 parent fac35a0 commit 9c249aa

File tree

2 files changed

+36
-19
lines changed

2 files changed

+36
-19
lines changed

jsonschema-core.xml

+31-19
Original file line numberDiff line numberDiff line change
@@ -340,23 +340,23 @@
340340
</t>
341341
</section>
342342

343-
<section title='The "id" keyword'>
343+
<section title='The "$id" keyword'>
344344
<t>
345-
The "id" keyword defines a URI for the schema,
345+
The "$id" keyword defines a URI for the schema,
346346
and the base URI that other URI references within the schema are resolved against.
347-
The "id" keyword itself is resolved against the base URI that the object as a whole appears in.
347+
The "$id" keyword itself is resolved against the base URI that the object as a whole appears in.
348348
</t>
349349
<t>
350350
If present, the value for this keyword MUST be a string, and MUST represent a valid <xref target="RFC3986">URI-reference</xref>.
351351
This value SHOULD be normalized, and SHOULD NOT be an empty fragment &lt;#&gt; or an empty string &lt;&gt;.
352352
</t>
353353
<t>
354-
The root schema of a JSON Schema document SHOULD contain an "id" keyword with an absolute-URI (containing a scheme, but no fragment).
354+
The root schema of a JSON Schema document SHOULD contain an "$id" keyword with an absolute-URI (containing a scheme, but no fragment).
355355
</t>
356356
<t>
357357
To name subschemas in a JSON Schema document,
358-
subschemas can use "id" to give themselves a document-local identifier.
359-
This form of "id" keyword MUST begin with a hash ("#") to identify it as a fragment URI reference,
358+
subschemas can use "$id" to give themselves a document-local identifier.
359+
This form of "$id" keyword MUST begin with a hash ("#") to identify it as a fragment URI reference,
360360
followed by a letter ([A-Za-z]), followed by any number of
361361
letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), or periods (".").
362362
<!-- This restriction is the same one defined by XML -->
@@ -367,18 +367,18 @@
367367
<artwork>
368368
<![CDATA[
369369
{
370-
"id": "http://example.com/root.json",
370+
"$id": "http://example.com/root.json",
371371
"definitions": {
372-
"A": { "id": "#foo" },
372+
"A": { "$id": "#foo" },
373373
"B": {
374-
"id": "other.json",
374+
"$id": "other.json",
375375
"definitions": {
376-
"X": { "id": "#bar" },
377-
"Y": { "id": "t/inner.json" }
376+
"X": { "$id": "#bar" },
377+
"Y": { "$id": "t/inner.json" }
378378
}
379379
},
380380
"C": {
381-
"id": "urn:uuid:ee564b8a-7a87-4125-8c96-e9f123d6766f"
381+
"$id": "urn:uuid:ee564b8a-7a87-4125-8c96-e9f123d6766f"
382382
}
383383
}
384384
}
@@ -404,10 +404,10 @@
404404
<section title="Internal references">
405405
<t>
406406
Schemas can be identified by any URI that has been given to them, including a JSON Pointer or
407-
their URI given directly by "id".
407+
their URI given directly by "$id".
408408
</t>
409409
<t>
410-
Tools SHOULD take note of the URIs that schemas, including subschemas, provide for themselves using "id".
410+
Tools SHOULD take note of the URIs that schemas, including subschemas, provide for themselves using "$id".
411411
This is known as "Internal referencing".
412412
</t>
413413

@@ -419,14 +419,14 @@
419419
<artwork>
420420
<![CDATA[
421421
{
422-
"id": "http://example.net/root.json",
422+
"$id": "http://example.net/root.json",
423423
"items": {
424424
"type": "array",
425425
"items": { "$ref": "#item" }
426426
},
427427
"definitions": {
428428
"single": {
429-
"id": "#item",
429+
"$id": "#item",
430430
"type": "integer"
431431
},
432432
}
@@ -435,7 +435,7 @@
435435
</artwork>
436436
</figure>
437437
<t>
438-
When an implementation encounters the &lt;#/definitions/single&gt; schema, it resolves the "id" URI reference
438+
When an implementation encounters the &lt;#/definitions/single&gt; schema, it resolves the "$id" URI reference
439439
against the current base URI to form &lt;http://example.net/root.json#item&gt;.
440440
</t>
441441
<t>
@@ -451,14 +451,26 @@
451451
</t>
452452
<t>
453453
Implementations SHOULD be able to associate arbitrary URIs with an arbitrary schema and/or
454-
automatically associate a schema's "id"-given URI, depending on the trust that the the validator
454+
automatically associate a schema's "$id"-given URI, depending on the trust that the the validator
455455
has in the schema.
456456
</t>
457457
<t>
458458
A schema MAY (and likely will) have multiple URIs, but there is no way for a URI to identify more than one schema.
459459
When multiple schemas try to identify with the same URI, validators SHOULD raise an error condition.
460460
</t>
461461
</section>
462+
<section title='Compatibility with "id"'>
463+
<t><cref>"id" is likely to be deleted from the spec before RFC.</cref></t>
464+
<t>
465+
Implementations MAY support "id" as a synonym for "$id" to aid
466+
in migrating schemas from older drafts, however schema authors
467+
SHOULD NOT make use of "id" and MUST NOT assume it is supported.
468+
</t>
469+
<t>
470+
The behavior when "$id" and "id" are present with different values is undefined.
471+
Implementations MAY issue a warning or error for such schemas.
472+
</t>
473+
</section>
462474
</section>
463475
</section>
464476

@@ -580,7 +592,7 @@ User-Agent: so-cool-json-schema/1.0.2 curl/7.43.0
580592
Validators MUST NOT fall into an infinite loop.
581593
</t>
582594
<t>
583-
Servers need to take care that malicious parties can't change the functionality of existing schemas by uploading a schema with an pre-existing or very similar "id".
595+
Servers need to take care that malicious parties can't change the functionality of existing schemas by uploading a schema with an pre-existing or very similar "$id".
584596
</t>
585597
<t>
586598
Individual JSON Schema vocabularies are liable to also have their own security considerations. Consult the respective specifications for more information.

schema.json

+5
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,12 @@
2929
},
3030
"type": "object",
3131
"properties": {
32+
"$id": {
33+
"type": "string",
34+
"format": "uriref"
35+
},
3236
"id": {
37+
"description": "This keyword has been deprecated in favor of \"$id\"",
3338
"type": "string",
3439
"format": "uriref"
3540
},

0 commit comments

Comments
 (0)