django-jsonform icon indicating copy to clipboard operation
django-jsonform copied to clipboard

Referencing to an external jsonschema file

Open shodhansave opened this issue 2 years ago • 4 comments

I have 2 jsonschema files in which one has a reference to another:

article.json

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "a.json",
  "title": "Article",
  "type": "object",
  "properties": {
    "aid": {
      "type": "integer"
    },
    "author": {
      "type": "string"
    },
    "title": {
      "type": "string"
    }
  },
  "required": ["aid", "author", "title"]
}

publisher.json

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "p.json",
  "title": "Publisher",
  "type": "object",
  "properties": {
    "pid": {
      "type": "integer"
    },
    "name": {
      "type": "integer"
    },
    "lang": {
      "type": "string"
    },
    "articles": {
      "type": "array",
      "items": {
        "$ref": "a.json"
      }
    }
  },
  "required": ["pid", "articles"]
}

when i check the Django admin page, i get different errors based on what I specify in $ref in publisher.json.

for the above one, i get this error:

(!) Error: Error while creating EditorState: Invalid schema: '$ref' value must begin with a hash (#) character
Check browser console for more details about the error.

console log:

react-dom.production.min.js:141 Error: Error while creating EditorState: Invalid schema: '$ref' value must begin with a hash (#) character
    at e.create (react-json-form.js:1:69660)
    at new t (react-json-form.js:1:80421)
    at fh (react-dom.production.min.js:81:106)
    at Ch (react-dom.production.min.js:114:51)
    at Pj (react-dom.production.min.js:233:139)
    at di (react-dom.production.min.js:168:305)
    at Nj (react-dom.production.min.js:168:236)
    at sc (react-dom.production.min.js:168:96)
    at gf (react-dom.production.min.js:162:109)
    at Pa (react-dom.production.min.js:157:184)
Ye @ react-dom.production.min.js:141
Mh.c.callback @ react-dom.production.min.js:141
dh @ react-dom.production.min.js:80
Bj @ react-dom.production.min.js:145
Qj @ react-dom.production.min.js:176
unstable_runWithPriority @ react.production.min.js:24
Za @ react-dom.production.min.js:73
eb @ react-dom.production.min.js:170
gf @ react-dom.production.min.js:162
Pa @ react-dom.production.min.js:157
yd @ react-dom.production.min.js:188
(anonymous) @ react-dom.production.min.js:191
bi @ react-dom.production.min.js:163
zd @ react-dom.production.min.js:191
M.render @ react-dom.production.min.js:243
render @ react-json-form.js:1
initJSONForm @ index.js:62
initializeAllForNode @ index.js:100
init @ index.js:105
(anonymous) @ index.js:145

if i add a # then i get this error:

(!) TypeError: Cannot read properties of undefined (reading '#a.json')
Check browser console for more details about the error.

on console:

react-dom.production.min.js:141 TypeError: Cannot read properties of undefined (reading '#a.json')
    at e.getRef (react-json-form.js:1:70194)
    at t.getRef (react-json-form.js:1:70822)
    at De (react-json-form.js:1:54652)
    at y (react-json-form.js:1:58840)
    at Ie (react-json-form.js:1:59178)
    at t.getFields (react-json-form.js:1:71243)
    at t.render (react-json-form.js:1:72375)
    at Te (react-dom.production.min.js:119:308)
    at Ch (react-dom.production.min.js:119:105)
    at Pj (react-dom.production.min.js:233:139)
Ye @ react-dom.production.min.js:141
Mh.c.callback @ react-dom.production.min.js:141
dh @ react-dom.production.min.js:80
Bj @ react-dom.production.min.js:145
Qj @ react-dom.production.min.js:176
unstable_runWithPriority @ react.production.min.js:24
Za @ react-dom.production.min.js:73
eb @ react-dom.production.min.js:170
gf @ react-dom.production.min.js:162
Pa @ react-dom.production.min.js:157
yd @ react-dom.production.min.js:188
(anonymous) @ react-dom.production.min.js:191
bi @ react-dom.production.min.js:163
zd @ react-dom.production.min.js:191
M.render @ react-dom.production.min.js:243
render @ react-json-form.js:1
initJSONForm @ index.js:62
initializeAllForNode @ index.js:100
init @ index.js:105
(anonymous) @ index.js:145

looking at the docs it seems that same-file references are supported, but not sure of external file referencing is not supported.

any idea what should i do here so that i can correctly refer the schema from a different file?

thanks

shodhansave avatar Oct 02 '23 13:10 shodhansave

Referencing external schema is not supported yet.

bhch avatar Oct 02 '23 16:10 bhch

thanks @bhch, any plans for adding this in the near future?

shodhansave avatar Oct 02 '23 22:10 shodhansave

Referencing external schemas from their $id value requires that the form field has information about all the external schemas, where they are and how to find them.

If you have some ideas about implementing this feature, please share them here.

bhch avatar Oct 04 '23 12:10 bhch

not something i can think off right now, but i will give it a thought :+1:

shodhansave avatar Nov 03 '23 14:11 shodhansave