react-jsonschema-form icon indicating copy to clipboard operation
react-jsonschema-form copied to clipboard

$ref doesn't support url

Open make0991 opened this issue 6 years ago • 7 comments

Here is a valid schema:

{
  "title": "A registration form",
  "description": "A simple form example.",
  "type": "object",
  "required": [
    "address"
  ],
  "properties": {
    "address": { 
      "$ref": "https://api.myjson.com/bins/3bkzl.json#/definitions/address"
    }
  }
}

It throws exception when dereference $ref.

make0991 avatar Nov 13 '19 09:11 make0991

Not sure if we should implement this... could you look through the JSON Schema spec (https://json-schema.org/) and see what it might have to say about $ref's with a HTTPS url?

epicfaace avatar Dec 08 '19 22:12 epicfaace

The specification is very explicit in saying on section 8.3 that:

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 MUST be ignored.

The URI is not a network locator, only an identifier. A schema need not be downloadable from the address if it is a network-addressable URL, and implementations SHOULD NOT assume they should perform a network operation when they encounter a network-addressable URI.

On the latest draft, this section is here.

Nevertheless, I would also like to see this feature supported being it out-of-the-box or by allowing its users to provide their own URL resolver implementation.

goncalonsp avatar Dec 18 '19 12:12 goncalonsp

I like the idea of users being able to choose between several given $ref resolver implementations (JSON pointer, URL, or a combination of multiple ones), and also provide their own custom $ref resolver implementation if they want.

epicfaace avatar Dec 20 '19 11:12 epicfaace

👍 +1 for URL $ref

iplus26 avatar Jan 06 '20 08:01 iplus26

👍 +1 for URL $ref

xiaoronglv avatar Jun 03 '21 06:06 xiaoronglv

👍 +1 for URL $ref

robert7528 avatar Jun 16 '21 07:06 robert7528

In JSON schema draft 2020-12 (which is the latest as of writing this) this is specified:

Section 8.2.3.1:

The value of the "$ref" keyword MUST be a string which is a URI-Reference. Resolved against the current URI base, it produces the URI of the schema to apply.

For the definition of "URI-Reference" the document links to RFC3986 in one place.

This means to me that any absolute URI would be valid here, even schemes other than http:// and https://. But so far I haven't found any specification on whether processors must support any certain protocol.

Personally I would like to add my +1 for implementing HTTP(S) resolving, as we are working towards modularising schema and referencing it directly via absolute HTTPS URLs. This happening in a browser context will probably mean some requirements for servers though (sending CORS headers, handling OPTIONS requests).

marians avatar Dec 08 '22 17:12 marians