|
731 | 731 | with the same URI, validators SHOULD raise an error condition. |
732 | 732 | </t> |
733 | 733 | </section> |
734 | | - </section> |
735 | | - |
736 | | - <section title="Dereferencing"> |
737 | | - <section title="Internal References"> |
| 734 | + <section title="Dereferencing"> |
738 | 735 | <t> |
739 | 736 | Schemas can be identified by any URI that has been given to them, including |
740 | | - a JSON Pointer or their URI given directly by "$id". |
| 737 | + a JSON Pointer or their URI given directly by "$id". In all cases, |
| 738 | + dereferencing a "$ref" reference involves first resolving its value as a |
| 739 | + URI reference against the current base URI per |
| 740 | + <xref target="RFC3986">RFC 3986</xref>. |
741 | 741 | </t> |
742 | 742 | <t> |
743 | | - Tools SHOULD take note of the URIs that schemas, including subschemas, |
744 | | - provide for themselves using "$id". This is known as "Internal referencing". |
| 743 | + If the resulting URI identifies a schema within the current document, or |
| 744 | + within another schema document that has been made available to the implementation, |
| 745 | + then that schema SHOULD be used automatically. |
745 | 746 | </t> |
746 | | - |
747 | 747 | <t> |
748 | 748 | For example, consider this schema: |
749 | 749 | </t> |
|
760 | 760 | "definitions": { |
761 | 761 | "single": { |
762 | 762 | "$id": "#item", |
763 | | - "type": "integer" |
| 763 | + "type": "object", |
| 764 | + "additionalProperties": { "$ref": "other.json" } |
764 | 765 | } |
765 | 766 | } |
766 | 767 | } |
|
775 | 776 | <t> |
776 | 777 | When an implementation then looks inside the <#/items> schema, it |
777 | 778 | encounters the <#item> reference, and resolves this to |
778 | | - <http://example.net/root.json#item> which is understood as the schema |
779 | | - defined elsewhere in the same document without needing to |
780 | | - resolve the fragment against the base URI. |
| 779 | + <http://example.net/root.json#item>, which it has seen defined in |
| 780 | + this same document and can therefore use automatically. |
| 781 | + </t> |
| 782 | + <t> |
| 783 | + When an implementation encounters the reference to "other.json", it resolves |
| 784 | + this to <http://example.net/other.json>, which is not defined in this |
| 785 | + document. If a schema with that identifier has otherwise been supplied to |
| 786 | + the implementation, it can also be used automatically. |
| 787 | + <cref> |
| 788 | + What should implementations do when the referenced schema is not known? |
| 789 | + Are there circumstances in which automatic network dereferencing is |
| 790 | + allowed? A same origin policy? A user-configurable option? In the |
| 791 | + case of an evolving API described by Hyper-Schema, it is expected that |
| 792 | + new schemas will be added to the system dynamically, so placing an |
| 793 | + absolute requirement of pre-loading schema documents is not feasible. |
| 794 | + </cref> |
781 | 795 | </t> |
782 | 796 | </section> |
783 | 797 | </section> |
|
0 commit comments