Skip to content

RJSF to Support Bundled Schemas #4505

@rbrand21

Description

@rbrand21

Prerequisites

What theme are you using?

core

Is your feature request related to a problem? Please describe.

I'm bundling my disparate schemas into a single Compound Schema Document. When doing so, relative $refs (and absolute) are not resolved properly because they don't start with a #.

The library I'm using to bundle (hyperjump-io/json-schema) appears to be following the JSON Schema spec on bundling.

Here is an example:

json schemas:

// primitive-string.json
{
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "$id": "https://example.com/schemas/primitives/string",
     "title": "string",
     "type": "object",
     "properties": {
         "type": {"enum": ["string"]},
         "key": {"type": "string"}
     },
     "required": ["type", "key"]
}
// primitive-treatment.json
{
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "$id": "https://example.com/schemas/primitives/treatment",
    "type": "object",
    "anyOf": [
        {
            "title": "C",
            "properties": {
                "C": {
                    "$ref": "/schemas/primitives/string"
                }
            }
        }
    ]
}

bundling code:

//import the above two schemas as string and treatment
async function example(): Promise<object> {
    registerSchema(string)
    registerSchema(treatment)

    return await bundle("https://example.com/schemas/primitives/treatment")
}

Results in the following bundled json schema document:

{
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "$id": "https://example.com/schemas/primitives/treatment",
    "type": "object",
    "anyOf": [
        {
            "title": "C",
            "properties": {
                "C": {
                    "$ref": "/schemas/primitives/string"
                }
            }
        }
    ],
    "$defs": {
        "https://example.com/schemas/primitives/string": {
            "$id": "https://example.com/schemas/primitives/string",
            "title": "string",
            "type": "object",
            "properties": {
                "type": {
                    "enum": [
                        "string"
                    ]
                },
                "key": {
                    "type": "string"
                }
            },
            "required": [
                "type",
                "key"
            ]
        }
    }
}

When using that in an RJSF form:

// App.tsx

<Form
  key={key}
  schema={schema}
  validator={validator}
  onChange={log('changed')}
  onSubmit={log('submitted')}
  onError={log('errors')}
/>
)])

It results in the following error:

chunk-HOSCXNDA.js?v=a04102ad:5516 Uncaught Error: Could not find a definition for /schemas/primitives/string.

This is from the relative reference "$ref": "/schemas/primitives/string" and from the error checking code here

Describe the solution you'd like

Ideally RJSF would be able to support relative (or abolute using $ids defined within $defs) $refs

Describe alternatives you've considered

I have tried to massage the json schema from the bundling side to have $refs point to #/<some path> (which seems like it should work) but then schema bundling fails "because /defs isn't defined" or something similar.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions