Skip to content

invalid output from allOf/anyOf combinator #2173

@a1528zhang

Description

@a1528zhang

Describe the bug

Here is my code


import { JsonForms } from "@jsonforms/react";
import { useState } from "react";
import {
  materialRenderers,
  materialCells,
} from "@jsonforms/material-renderers";

const Example = () => {
  const [data] = useState({});
  const schema = {
    anyOf: [
      {
        type: "object",
        properties: {
          firstName: {
            type: "object",
            properties: {
              A: {
                type: "number",
                maxLength: 1,
              },
            },
          },
        },
      },
      {
        type: "string",
      },
    ],
  };
  return (
    <JsonForms
      schema={schema}
      uischema={undefined}
      data={data}
      onChange={(d: any) => {
        console.log("getData ", d);
      }}
      renderers={materialRenderers}
      cells={materialCells}
    />
  );
};

I got this output:

image

I cant paste by code because it is a String object. When I copy this object it turns to:
{ "data": "1", "errors": [] }.
Obviously it is not a valid json object.

Expected behavior

I expected output:
{ "data": { "firstName": { "A": 1 } }, "errors": [] }

Steps to reproduce the issue

  1. Start this example and render:
    image
  2. select anyof-1 tab & input any string
    image
  3. select anyof-0 tab & input any string
    image
  4. see error on console

Screenshots

No response

In which browser are you experiencing the issue?

Google Chrome 116.0.5845.96

Which Version of JSON Forms are you using?

v3.1.0

Framework

React

RendererSet

Material

Additional context

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions