简体   繁体   中英

Json schema relative $ref to current “id”

I have searched SO and JSON schema documentation for a few days now, but I'm struggling to get my JSON Schema references to work across multiple files in the same directory.

My root schema would be an oneOf object:

{
  "$schema": "http://json-schema.org/draft-04/schema",
  "id": "http://localhost/json-editor/schema/function.json",
  "title": "Function",
  "oneOf": [
    {
      "$ref": "./fn_md5.json"
    },
    {
      "$ref": "fn_sha1.json"
    }
  ]
}

Now after reading the docs and most questions here, I'd assume both ./fn_md5.json and fn_sha1.json would be resolved to http://localhost/json-editor/schema/fn_....json (where the ... represents their respective name, of course). However, the resolver keeps looking into http://localhost/json-editor/fn_....json , which appears to be relative to the application's url ( JDorn's JSON Editor running at my http://localhost/json-editor/ ).

Am I understanding the schema and id wrong, or could it be an error with the editor's URL resolver?

Thanks!

for find the relative references you need use $id like this:

{
  "$schema": "http://json-schema.org/draft-04/schema",
  "id": "http://localhost/json-editor/schema/function.json",
  "$id":"https://www.baseurl.com/"
  "title": "Function",
  "oneOf": [
    {
      "$id": "./fn_md5.json"
    },
    {
      "$id": "fn_sha1.json"
    }
  ]
}

source: https://tools.ietf.org/html/draft-handrews-json-schema-01#section-8.2.4

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM