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

undefined rootSchema in resolveSchema() causes: Cannot read properties of undefined (reading 'properties') #1855

Closed
mirismaili opened this issue Dec 20, 2021 · 4 comments
Milestone

Comments

@mirismaili
Copy link
Contributor

mirismaili commented Dec 20, 2021

Describe the bug

In resolveSchema() function:

if (resultSchema !== undefined && resultSchema.$ref !== undefined) {
try {
return retrieveResolvableSchema(schema, resultSchema.$ref);
} catch (e) {
return retrieveResolvableSchema(rootSchema, resultSchema.$ref);
}
}

rootSchema in catch block can be undefined. This is an optional parameter of resolveShcema():

export const resolveSchema = (
schema: JsonSchema,
schemaPath: string,
rootSchema?: JsonSchema
): JsonSchema => {

and its value hasn't been checked (for being undefined) before.


This is not only a potential bug. The function has actually been called without rootSchema in some places (e.g. in testers.js) and I especially encountered it after this:

currentDataSchema = resolveSchema(schema, schemaPath);

Expected behavior

Obviously, having no error.

But I think the more important issue here is why schema $refs should be resolved in testers many times? This would be a big performance issue! The schema can be parsed (resolved) one time and be used multiple times (in testers and probably any other places).

Steps to reproduce the issue

  1. Go to Playground
  2. Set:
    JSON-Schema:
    {
      "type": "object",
      "definitions": {
        "test": {
          "type": "string"
        }
      },
      "properties": {
        "foo": {
          "type": "object",
          "properties": {
            "bar": {
              "$ref": "#/definitions/test"
            }
          }
        }
      }
    }
    UI-Schema:
    false
    Data:
    {}

Screenshots

image

Note: The above playground works with JsonForms v3.0.0-alpha.2

In which browser are you experiencing the issue?

Google Chrome v96.0.4664.93 (Official Build) (64-bit)

@sdirix
Copy link
Member

sdirix commented Dec 22, 2021

Hi @mirismaili, thanks for the report!

Yes the resolving is not in the best state at the moment in the alpha release. We will make sure that all basic resolving cases work before the stable release, see #1750 for more information.

Note that you can always resolve your JSON Schema yourself before handing it over to JSON Forms. I would like recommend json-refs for that, see https://jsonforms.io/docs/ref-resolving

@sdirix sdirix added this to the 3.0 milestone Dec 22, 2021
@mirismaili
Copy link
Contributor Author

Hi @sdirix, you're welcome.

OK. I did so. Thanks.

@sdirix
Copy link
Member

sdirix commented May 6, 2022

This issue should be solved by #1829. Can you verify?

@sdirix
Copy link
Member

sdirix commented May 12, 2022

I'll close this for now. Please reopen if you encounter further issues.

@sdirix sdirix closed this as completed May 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants