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

When using "anyOf" and no UISchema generateDefaultUISchema fails with stack overflow #2083

Closed
LeonardHd opened this issue Jan 22, 2023 · 2 comments · Fixed by #2160
Closed
Assignees
Milestone

Comments

@LeonardHd
Copy link

LeonardHd commented Jan 22, 2023

Describe the bug

Hi,
Thanks for this awesome library. When using JsonSchema only (and have JsonForms generate a corresponding UISchema) JsonForms fails due to a stack over flow error.

The jsonSchema (minimal example) causing the error:

{
        "type": "object",
        "anyOf": [
            {
                "required": ["Option1"]
            },
            {
                "required": ["Option2"]
            }
        ],
        "properties": {
            "Option1": {
                "type": "array",
                "items": {
                    "type": "string",
                    "enum": [
                        "A",
                        "B"
                    ]
                }
            },
            "Option2": {
                "type": "array",
                "items": {
                    "type": "string",
                    "enum": [
                        "C"
                    ]
                }
            }
        }
    }

When providing a UISchema (as of below) the form renders as expected:

{
        "type": "HorizontalLayout",
        "elements": [
            {
                "type": "Control",
                "scope": "#/properties/Option1"
            },
            {
                "type": "Control",
                "scope": "#/properties/Option2"
            }
        ]
}

Expected behavior

JsonForms derives a somewhat functional UI schema, or alternatively does not crash.

Steps to reproduce the issue

  1. Clone https://github.com/eclipsesource/jsonforms-angular-seed
  2. Set schema = {...} to example above and set uischema = null;
  3. Use npm start and open localhost:4200
    -> Browser (Chrome) crashes with Stack overflow

Working example

  1. Clone https://github.com/eclipsesource/jsonforms-angular-seed
  2. Set schema = {...} and set uischema = {...}; to example above.
  3. Use npm start and open localhost:4200 -> form is rendered as expected.

Screenshots

image

In which browser are you experiencing the issue?

Google Chrome 109.0.5414.75 (Official Build) (64-bit)

Which Version of JSON Forms are you using?

v3.0.0

Framework

Angular

RendererSet

Material

Additional context

I suspected the error to be somewhere in @jsonforms\core\src\generators\uischema.ts

@sdirix sdirix added this to the 3.x milestone Jan 23, 2023
@sdirix
Copy link
Member

sdirix commented Jan 23, 2023

Thanks for the report!

@LeonardHd
Copy link
Author

Happy to do so. I actually felt I didn't get to the bottom of this.

I was able to reduce the example even further. When using "type": "object", the generation of UI schema fails - it seems the ObjectControlRenderer calls mapAdditionalProps multiple times.

  uischema = null;
  schema = {
    "type": "object",
    "anyOf": [
        {
            "required": ["Option1"]
        },
        {
            "required": ["Option2"]
        }
    ],
  };

However, wasn't able to find a place where to reproduce this issue via a test. Seems it's a combination of things causing the overflow.

@sdirix sdirix modified the milestones: 3.x, 3.2 Jun 27, 2023
sdirix pushed a commit that referenced this issue Aug 7, 2023
The Angular Material object renderer sometimes also takes over the responsibility to render
'oneOf', 'anyOf' and 'allOf' because we don't support these constructs in Angular Material yet.
However this then leads to errors. Therefore we no longer consider these combinators
during rendering.

closes #2083
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants