Skip to content

Commit 730b826

Browse files
committed
Change "id" to "$id", retain "id" for compatibility.
This addresses issue json-schema-org#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 e3a668d commit 730b826

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
@@ -323,23 +323,23 @@
323323
</t>
324324
</section>
325325

326-
<section title='The "id" keyword'>
326+
<section title='The "$id" keyword'>
327327
<t>
328-
The "id" keyword defines a URI for the schema,
328+
The "$id" keyword defines a URI for the schema,
329329
and the base URI that other URI references within the schema are resolved against.
330-
The "id" keyword itself is resolved against the base URI that the object as a whole appears in.
330+
The "$id" keyword itself is resolved against the base URI that the object as a whole appears in.
331331
</t>
332332
<t>
333333
If present, the value for this keyword MUST be a string, and MUST represent a valid <xref target="RFC3986">URI-reference</xref>.
334334
This value SHOULD be normalized, and SHOULD NOT be an empty fragment &lt;#&gt; or an empty string &lt;&gt;.
335335
</t>
336336
<t>
337-
The root schema of a JSON Schema document SHOULD contain an "id" keyword with an absolute-URI (containing a scheme, but no fragment).
337+
The root schema of a JSON Schema document SHOULD contain an "$id" keyword with an absolute-URI (containing a scheme, but no fragment).
338338
</t>
339339
<t>
340340
To name subschemas in a JSON Schema document,
341-
subschemas can use "id" to give themselves a document-local identifier.
342-
This form of "id" keyword MUST begin with a hash ("#") to identify it as a fragment URI reference,
341+
subschemas can use "$id" to give themselves a document-local identifier.
342+
This form of "$id" keyword MUST begin with a hash ("#") to identify it as a fragment URI reference,
343343
followed by a letter ([A-Za-z]), followed by any number of
344344
letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), or periods (".").
345345
<!-- This restriction is the same one defined by XML -->
@@ -350,18 +350,18 @@
350350
<artwork>
351351
<![CDATA[
352352
{
353-
"id": "http://example.com/root.json",
353+
"$id": "http://example.com/root.json",
354354
"definitions": {
355-
"A": { "id": "#foo" },
355+
"A": { "$id": "#foo" },
356356
"B": {
357-
"id": "other.json",
357+
"$id": "other.json",
358358
"definitions": {
359-
"X": { "id": "#bar" },
360-
"Y": { "id": "t/inner.json" }
359+
"X": { "$id": "#bar" },
360+
"Y": { "$id": "t/inner.json" }
361361
}
362362
},
363363
"C": {
364-
"id": "urn:uuid:ee564b8a-7a87-4125-8c96-e9f123d6766f"
364+
"$id": "urn:uuid:ee564b8a-7a87-4125-8c96-e9f123d6766f"
365365
}
366366
}
367367
}
@@ -387,10 +387,10 @@
387387
<section title="Internal references">
388388
<t>
389389
Schemas can be identified by any URI that has been given to them, including a JSON Pointer or
390-
their URI given directly by "id".
390+
their URI given directly by "$id".
391391
</t>
392392
<t>
393-
Tools SHOULD take note of the URIs that schemas, including subschemas, provide for themselves using "id".
393+
Tools SHOULD take note of the URIs that schemas, including subschemas, provide for themselves using "$id".
394394
This is known as "Internal referencing".
395395
</t>
396396

@@ -402,14 +402,14 @@
402402
<artwork>
403403
<![CDATA[
404404
{
405-
"id": "http://example.net/root.json",
405+
"$id": "http://example.net/root.json",
406406
"items": {
407407
"type": "array",
408408
"items": { "$ref": "#item" }
409409
},
410410
"definitions": {
411411
"single": {
412-
"id": "#item",
412+
"$id": "#item",
413413
"type": "integer"
414414
},
415415
}
@@ -418,7 +418,7 @@
418418
</artwork>
419419
</figure>
420420
<t>
421-
When an implementation encounters the &lt;#/definitions/single&gt; schema, it resolves the "id" URI reference
421+
When an implementation encounters the &lt;#/definitions/single&gt; schema, it resolves the "$id" URI reference
422422
against the current base URI to form &lt;http://example.net/root.json#item&gt;.
423423
</t>
424424
<t>
@@ -434,14 +434,26 @@
434434
</t>
435435
<t>
436436
Implementations SHOULD be able to associate arbitrary URIs with an arbitrary schema and/or
437-
automatically associate a schema's "id"-given URI, depending on the trust that the the validator
437+
automatically associate a schema's "$id"-given URI, depending on the trust that the the validator
438438
has in the schema.
439439
</t>
440440
<t>
441441
A schema MAY (and likely will) have multiple URIs, but there is no way for a URI to identify more than one schema.
442442
When multiple schemas try to identify with the same URI, validators SHOULD raise an error condition.
443443
</t>
444444
</section>
445+
<section title='Compatibility with "id"'>
446+
<t><cref>"id" is likely to be deleted from the spec before RFC.</cref></t>
447+
<t>
448+
Implementations MAY support "id" as a synonym for "$id" to aid
449+
in migrating schemas from older drafts, however schema authors
450+
SHOULD NOT make use of "id" and MUST NOT assume it is supported.
451+
</t>
452+
<t>
453+
The behavior when "$id" and "id" are present with different values is undefined.
454+
Implementations MAY issue a warning or error for such schemas.
455+
</t>
456+
</section>
445457
</section>
446458
</section>
447459

@@ -563,7 +575,7 @@ User-Agent: so-cool-json-schema/1.0.2 curl/7.43.0
563575
Validators MUST NOT fall into an infinite loop.
564576
</t>
565577
<t>
566-
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".
578+
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".
567579
</t>
568580
<t>
569581
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)