bhch / django-jsonform

A better, user-friendly JSON editing form field for Django admin. Also supports Postgres ArrayField.
https://django-jsonform.rtfd.io
BSD 3-Clause "New" or "Revised" License
307 stars 31 forks source link

Referencing to an external jsonschema file #127

Open shodhansave opened 9 months ago

shodhansave commented 9 months ago

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

bhch commented 9 months ago

Referencing external schema is not supported yet.

shodhansave commented 9 months ago

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

bhch commented 9 months ago

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.

shodhansave commented 8 months ago

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