Skip to content

[BUG] Referencing ("$ref") an array type inside "oneOf" *_as first_* results in a react error #189

@MathiasBaumgartinger

Description

@MathiasBaumgartinger

Explanation

I try to create a responsive django admin interface where the user can create a form inside the application. Different form-types require different params, thus I defined a oneOf.

Unforunately, when referencing ("$ref") an array type inside "oneOf" as first results in a react error. Interestingly, if I first use another non-array type, no error will occur:

Versions used

Django==5.2.4
django-jsonform==2.23.2

❌ erroneous version

...
"type": {
    "oneOf": [
        { "title": "Dropdown", "$ref": "#/$defs/Dropdown_params", "default": {"kind": "Dropdown"} },
        { "title": "Comment", "$ref": "#/$defs/Comment_params", "default": {"kind": "Comment"} },
    ]
},
...

✔️ working version

...
"type": {
    "oneOf": [
        { "title": "Comment", "$ref": "#/$defs/Comment_params", "default": {"kind": "Comment"} },
        { "title": "Dropdown", "$ref": "#/$defs/Dropdown_params", "default": {"kind": "Dropdown"} },
    ]
},
...

See section Minimal Reproduction for reproduction

Error Message

TypeError: t is undefined
    Le http://127.0.0.1:8000/static/django_jsonform/react-json-form.js:1
    y http://127.0.0.1:8000/static/django_jsonform/react-json-form.js:1
    Te http://127.0.0.1:8000/static/django_jsonform/react-json-form.js:1
    render http://127.0.0.1:8000/static/django_jsonform/react-json-form.js:1
    React 22
    _renderReact17 http://127.0.0.1:8000/static/django_jsonform/react-json-form.js:1
    render http://127.0.0.1:8000/static/django_jsonform/react-json-form.js:1
    initJSONForm http://127.0.0.1:8000/static/django_jsonform/index.js:62
    initializeAllForNode http://127.0.0.1:8000/static/django_jsonform/index.js:100
    init http://127.0.0.1:8000/static/django_jsonform/index.js:105
    <anonymous> http://127.0.0.1:8000/static/django_jsonform/index.js:145
    EventListener.handleEvent* http://127.0.0.1:8000/static/django_jsonform/index.js:144
    <anonymous> http://127.0.0.1:8000/static/django_jsonform/index.js:149
react-dom.production.min.js:141:274
    React 24
    _renderReact17 http://127.0.0.1:8000/static/django_jsonform/react-json-form.js:1
    render http://127.0.0.1:8000/static/django_jsonform/react-json-form.js:1
    initJSONForm http://127.0.0.1:8000/static/django_jsonform/index.js:62
    initializeAllForNode http://127.0.0.1:8000/static/django_jsonform/index.js:100
    init http://127.0.0.1:8000/static/django_jsonform/index.js:105
    <anonymous> http://127.0.0.1:8000/static/django_jsonform/index.js:145
    (Async: EventListener.handleEvent)
    <anonymous> http://127.0.0.1:8000/static/django_jsonform/index.js:144
    <anonymous> http://127.0.0.1:8000/static/django_jsonform/index.js:149

Minimal Reproduction

from django.db import models
from django_jsonform.models.fields import JSONField

###########------- SCHEMA DEFINITION FOR A MODEL -------###########

class FormDefinition(models.Model):
  FORM_TYPES = [
      "Comment",
      "Dropdown",
  ]
  
  PARAMS_SCHEMA = {
      "Comment_params": {
          "type": "object",
          "properties": {
              "kind": { "const": "Comment" },
          },
          "additionalProperties": False
      },
      "Dropdown_params": {
          "type": "object",
          "properties": {
              "kind": { "const": "Dropdown" },
              "values": {
                  "type": "array",
                  "title": "Options",
                  "minItems": 2,
                  "items": {"type": "string"}
              }
          },
          "required": ["values"],
          "additionalProperties": False
      },
  }
  
  DEFINITION_SCHEMA = {
      "type": "array",
      "items": {
          "type": "dict",
          "keys": {
              "question": {
                  "type": "string"
              },
              "type": {
                  "oneOf": [
                      { "title": "Dropdown", "$ref": "#/$defs/Dropdown_params", "default": {"kind": "Dropdown"} },
                      { "title": "Comment", "$ref": "#/$defs/Comment_params", "default": {"kind": "Comment"} },
                  ]
              },
          },
          "required": ["question", "type"]
      },
      "$defs": PARAMS_SCHEMA
  }
  name = models.CharField(max_length=256)
  field_definition = JSONField(schema=DEFINITION_SCHEMA, db_index=True)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions