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

Referencing to an external jsonschema file #127

Open
shodhansave opened this issue Oct 2, 2023 · 4 comments
Open

Referencing to an external jsonschema file #127

shodhansave opened this issue Oct 2, 2023 · 4 comments
Labels
enhancement New feature or request

Comments

@shodhansave
Copy link

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
Copy link
Owner

bhch commented Oct 2, 2023

Referencing external schema is not supported yet.

@shodhansave
Copy link
Author

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

@bhch
Copy link
Owner

bhch commented Oct 4, 2023

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 bhch added the enhancement New feature or request label Oct 4, 2023
@shodhansave
Copy link
Author

not something i can think off right now, but i will give it a thought 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants