# anyOf not working

**URL:** <https://jsonforms.discourse.group/t/anyof-not-working/327>\
**Category:** General\
**Created:** [August 4, 2021, 11:19am UTC](https://jsonforms.discourse.group/t/anyof-not-working/327 "2021-08-04T11:19:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![james-morris](https://yyz2.discourse-cdn.com/free1/user_avatar/jsonforms.discourse.group/james-morris/32/833_2.png) [@james-morris](https://jsonforms.discourse.group/u/james-morris)\
**Post date:** [August 4, 2021, 11:19am UTC](https://jsonforms.discourse.group/t/anyof-not-working/327/1 "2021-08-04T11:19:49Z")

</div>

I’m using the react material JSON forms and in my JSON schema I have the following:

```
    "inputTable": {
        "description": "",
        "type": "object",
        "properties": {
			.
			.
			.
            "sourceTableType": {
                "description": "Whether the table is registered as an 'entity', or 'child' entity in Visual Investigator.",
                "type": "string",
                "enum": [
                    "entity",
                    "child"
                ]
            },
            "lastUpdatedAtTimeFieldName": {
                "description": "The name of the datetime field that records when the last change was made to the record in the Visual Investigator table.",
                "type": "string"
            }
			.
			.
			.
        },
        "anyOf": [
            {
                "properties": {
                    "sourceTableType": { "const": "entity" }
                },
                "required": ["lastUpdatedAtTimeFieldName"]
            }
        ],
        "required": [
            .
			.
			.
        ]
    }

```

where . . . indicates that there are other properties of my object that have been emitted to make the example more concise.

Essentially I’m trying to say that if sourceTableType === ‘entity’ then lastUpdatedAtTimeFieldName is required.

what happens when I use this schema is I get the following:

 ![image](https://global.discourse-cdn.com/free1/uploads/jsonforms/original/1X/a871fa563fb956d5e7ccdfe22204589c4ae51edb.png)

What am I doing wrong?

---

<div class="post-metadata">

**Author:** ![sdirix](https://yyz2.discourse-cdn.com/free1/user_avatar/jsonforms.discourse.group/sdirix/32/1073_2.png) [@sdirix](https://jsonforms.discourse.group/u/sdirix)\
**Post date:** [August 11, 2021, 2:23pm UTC](https://jsonforms.discourse.group/t/anyof-not-working/327/2 "2021-08-11T14:23:47Z")

</div>

Hi @james-morris, this is what is happening here:

- Because there is an `anyOf` in the JSON Schema, the `MaterialAnyOfRenderer` is taking over rendering the `inputTable`
- The `anyOf` renderer outputs all properties “outside” of the `anyOf` as controls in a vertical layout.
- The `anyOf` renderer also outputs a tabbed selection for each `anyOf` subschema. Here there is only one subschema, so also only one tab. The content of the tab is empty as we don’t generate controls for `const` properties.

So in case you would like to have a regular table I would suggest not using the `anyOf` keyword within your schema or reregistering the table renderer with a higher priority.

Overall the JSON Schema doesn’t have the desired effect. The schema has to adhere to the regular properties of `inputTable` as well as the only `anyOf` subschema which is defined. Therefore `lastUpdatedAtTimeFieldName` will always be required.

You’re probably looking for something like this:

```json
{
  "type": "object",
  "properties": {
    "sourceTableType": {
      "type": "string",
      "enum": [
        "entity",
        "child"
      ]
    },
    "lastUpdatedAtTimeFieldName": {
      "description": "The name of the datetime field that records when the last change was made to the record in the Visual Investigator table.",
      "type": "string"
    }
  },
  "required": [],
  "if": {
    "properties": {
      "sourceTableType": {
        "const": "entity"
      }
    },
    "required": ["sourceTableType"]
  },
  "then": {
    "required": ["lastUpdatedAtTimeFieldName"]
  }
}

```

This will validate successfully for

```json
{
  "sourceTableType": "child"
}

```

and

```json
{
  "sourceTableType": "entity",
  "lastUpdatedAtTimeFieldName": "yesterday"
}

```

but not for

```json
{
  "sourceTableType": "entity"
}

```

This schema will render like this by default  
 ![conditionalRequired](https://global.discourse-cdn.com/free1/uploads/jsonforms/original/1X/919a589951f32b7485db05d4e6014107cae348df.gif)

---

<div class="post-metadata">

**Author:** ![james-morris](https://yyz2.discourse-cdn.com/free1/user_avatar/jsonforms.discourse.group/james-morris/32/833_2.png) [@james-morris](https://jsonforms.discourse.group/u/james-morris)\
**Post date:** [August 20, 2021, 3:07pm UTC](https://jsonforms.discourse.group/t/anyof-not-working/327/3 "2021-08-20T15:07:47Z")

</div>

That’s exactly what I wanted, thanks again Stefan!
