Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$ref doesn't support url #1512

Open
make0991 opened this issue Nov 13, 2019 · 7 comments
Open

$ref doesn't support url #1512

make0991 opened this issue Nov 13, 2019 · 7 comments

Comments

@make0991
Copy link

make0991 commented Nov 13, 2019

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.

@epicfaace
Copy link
Member

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?

@goncalonsp
Copy link

goncalonsp commented Dec 18, 2019

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.

@epicfaace
Copy link
Member

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.

@iplus26
Copy link

iplus26 commented Jan 6, 2020

👍 +1 for URL $ref

@xiaoronglv
Copy link

👍 +1 for URL $ref

1 similar comment
@robert7528
Copy link

👍 +1 for URL $ref

@marians
Copy link

marians commented Dec 8, 2022

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants