Know how much deep we have come in an rjsf form - reactjs

So Rjsf is composed of schema, the schema I have is deeply nested and I want to break break the view once I reach 3 level deep child.
How can I know that I am at which level of nesting?
e.g.:
{
"title": "Application", // root level child
"type": "object",
"properties": {
"replicas": {
"type": "integer"
},
"containers": { //1st level
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"image": {
"type": "string"
},
"commands": {
"type": "array",
"items": {
"type": "string"
}
},
"ports": { //2nd level
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string",
"default": "http"
},
"containerPort": { //3rd level deep
"type": "integer"
}
},
"minItems": 1,
"required": [
"containerPort"
]
}
},
"envs": { //2nd level
"type": "array",
"items": {
"type": "object",
"properties": {
"name": { // 3rd level
"type": "string"
},
"value": { //3rd level
"type": "string"
}
}
}
}
},
"required": [
"name",
"image",
"ports"
],
"minItems": 1
}
}
},
"required": [
"replicas",
"containers"
]
}
I want to break the UI into some other form based on the level of children. e.g., I want to make an other form when I want to get input of 3rd level deep childrens? How can I get the level of nested children?

Related

JSON Schema: Check the array to validate if a certain block of JSON objects is contained in it

I have a JSON array of arbitrary length. Each item in the array is a nested block of JSON objects, they all have same properties but different values.
I need a JSON schema to check the array if the last block in the array has the values defined in the schema.
How should the scheme be defined so that it only considers the last block in the array and ignores all the blocks before in the array?
My current solution successfully validates the JSON objects if there is only one block in the array. As soon as I have more blocks, it fails because all the others are not valid against my schema - for sure, this corresponds to the expected behaviour.
In my example, the JSON array contains two nested blocks of JSON objects. These differ for the following items:
event.action = "[load|button]"
event.label = "[journey:device-only|submit,journey:device-only]"
type = "[page|track]"
An example for my data are:
[
{
"page": {
"path": "order/checkout/summary",
"language": "en"
},
"cart": {
"ordercase": "neworder",
"product_list": [
{
"name": "Apple iPhone 14 Plus",
"quantity": 1,
"price": 1000
}
]
},
"event": {
"action": "load",
"label": "journey:device-only"
},
"type": "page"
},
{
"page": {
"path": "order/checkout/summary",
"language": "en"
},
"cart": {
"ordercase": "neworder",
"product_list": [
{
"name": "Apple iPhone 14 Plus",
"quantity": 1,
"price": 1000
}
]
},
"event": {
"action": "button",
"label": "submit,journey:device-only",
},
"type": "track"
}
]
And the schema I use which works fine for the second block if the block would be the only one in the array:
{
"type": "array",
"$schema": "http://json-schema.org/draft-07/schema#",
"items": {
"type": "object",
"required": ["event", "page", "type"],
"properties": {
"page": {
"type": "object",
"properties": {
"path": {
"const": "order/checkout/summary"
},
"language": {
"enum": ["de", "fr", "it", "en"]
}
},
"required": ["path", "language"]
},
"event": {
"type": "object",
"additionalProperties": false,
"properties": {
"action": {
"const": "button"
},
"label": {
"type": "string",
"pattern": "^[-_:, a-z0-9]*$",
"allOf": [
{
"type": "string",
"pattern": "^\\S*(?:(submit,|,submit))\\S*$"
},
{
"type": "string",
"pattern": "^\\S*(journey:(?:(device-only|device-plus)))\\S*$"
}
]
}
},
"required": ["action", "label"]
},
"type": {
"enum": ["track", "string"]
}
}
}
}

Azure Logic App Partition key [X] is invalid with COsmos Db

I need to save JSON parsed data to Cosmos Db, HTTP trigger works as it should as well as parsing but getting Partition key [my_dynamic_key_value] is invalid.
Did anyone have a similar issue?
I have found this article link but still getting the same error.
Thanks
EDIT 1
This is the flow for adding item to DB
Schema:
{
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"Groups": {
"type": "array",
"items": {
"type": "string"
}
},
"JobName": {
"type": "string"
},
"Link": {
"type": "string"
},
"MinSalary": {
"type": "string"
},
"MaxSalary": {
"type": "string"
},
"Hours": {
"type": "string"
},
"WorkPattern": {
"type": "string"
},
"Details": {
"type": "array",
"items": {
"type": "object",
"properties": {
"Name": {
"type": "string"
},
"Detail": {
"type": "string"
}
},
"required": [
"Name",
"Detail"
]
}
}
},
"required": [
"id",
"Groups",
"JobName",
"Link",
"MinSalary",
"MaxSalary",
"Hours",
"WorkPattern",
"Details"
]
}
}
Here is a response:
{
"code": "BadRequest",
"message": "Partition key [1bb2d44f-a066-4fa8-8a78-0cdcea1a756c] is invalid.\r\nActivityId: 345f9a99-534b-40cb-9dc0-9863dc8c90f5, \r\nRequestStartTime: 2020-04-28T08:04:46.8249255Z, RequestEndTime: 2020-04-28T08:04:46.8249255Z, Number of regions attempted:1\r\n, Microsoft.Azure.Documents.Common/2.10.0"
}
You need to set the partition key in the double quotes. Refer to sample screen shot below

json schema - Parent array(array of object) items have an inner array (array of primitive) with given values

Please feel free to update fitting title for this question.
I am trying to achieve something like this. An input JSON/data JSON must have an OWNER and a CHARGE_TO Account, but these don't have to be on the same Account (I.e. one Account can be OWNER, another can be CHARGE_TO) and must not contain account with any other roles.
NOTE: Need to define JSON schema which should be simple to maintain. i.e. Should be easy to add a new role in the condition. My valid and invalid JSONs are,
*************************** VALID JSON1 *********************************
{
"user": [
{
"name": "user1",
"roles": ["OWNER"]
},
{
"name": "user2",
"roles": ["ANY_OTHER_ROLE"]
},
{
"name": "user3",
"roles": ["CHARGE_TO"]
}]
}
*************************** VALID JSON2 *********************************
{
"user": [
{
"name": "user1",
"roles": ["OWNER", "CHARGE_TO"]
},
{
"name": "user2",
"roles": ["ANY_OTHER_ROLE"]
}]
}
*************************** INVALID JSON *********************************
{
"user": [
{
"name": "user1",
"roles": ["OWNER"]
},
{
"name": "user2",
"roles": ["ANY_OTHER_ROLE"]
}]
}
A JSON is valid if it has a user with roles ("OWNER" & "CHARGE_TO") or if users with roles (user1 - "OWNER", user3-"CHARGE_TO", other users with any other role).
Below is JSON schema I tried (draft_07). THIS IS NOT A WORKING SCHEMA.
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Complex inner array",
"type": "object",
"properties": {
"user": {
"type": "array",
"contains": {
"type": "object",
"properties": {
"name": { "type": "string" },
"orderRoles": {
"type": "array",
"minItems": 1,
"items": { "type": "string" }
}
},
"oneOf": [
{ "properties": { "roles": { "enum": ["OWNER", "CHARGE_TO"] }}},
{ "properties": { "roles": { "enum": ["OWNER"] }}},
{ "properties": { "roles": { "enum": ["CHARGE_TO"] }}}
]
},
"items": {
"type": "object",
"properties": {
"name": { "type": "string" },
"orderRoles": {
"type": "array",
"minItems": 1,
"items": { "type": "string" }
}
}
}
}
}
}
Below is my working schema. This is not an elegant solution as schema becomes huge if a new role ("ADMIN") is added, i.e. schema condition would An input JSON/data JSON must have an OWNER, ADMIN and a CHARGE_TO Account, but these don't have to be on the same Account (I.e. one Account can be OWNER, one Account can be ADMIN & another can be CHARGE_TO) and must not contain account with any other roles. Please feel free to improve this. Thanks.
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Complex inner array",
"type": "object",
"allOf": [
{
"properties": {
"account": {
"type": "array",
"contains": {
"type": "object",
"properties": {
"roles": {
"type": "array",
"minItems": 1,
"contains": { "enum": ["OWNER"] }
}
}
}
}
}
},
{
"properties": {
"account": {
"type": "array",
"contains": {
"type": "object",
"properties": {
"roles": {
"type": "array",
"minItems": 1,
"contains": { "enum": ["CHARGE_TO"] }
}
}
}
}
}
},
{
"properties": {
"account": {
"type": "array",
"items": {
"type": "object",
"properties": {
"roles": {
"type": "array",
"minItems": 1,
"items":{
"enum": ["CHARGE_TO", "OWNER"]
}
}
}
}
}
}
}
]
}
You need to isolate the part of the schema that checks for a specific role. Then you can just combine them with allOf. There's as little duplication as possible and you can easily add another constraint.
{
"type": "object",
"properties": {
"user": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": { "type": "string" },
"roles": {
"type": "array",
"items": { "type": "string" }
}
}
},
"allOf": [
{ "$ref": "#/definitions/require-role-owner" },
{ "$ref": "#/definitions/require-role-charge-to" }
]
}
},
"definitions": {
"require-role-owner": {
"contains": {
"properties": {
"roles": {
"contains": { "const": "OWNER" },
"allOf": [{ "$ref": "#/definitions/not-other-role" }]
}
}
}
},
"require-role-charge-to": {
"contains": {
"properties": {
"roles": {
"contains": { "const": "CHARGE_TO" },
"allOf": [{ "$ref": "#/definitions/not-other-role" }]
}
}
}
},
"not-other-role": {
"items": { "enum": ["OWNER", "CHARGE_TO"] }
}
}
}

Angular schema form access Object with Arrays from Form

I have a scenario where i need to display arrays in side a named object like this:
"actions": {
"singleSelection": [
{
"chartable": false,
"label": ""
}
]
}
I have accomplished it with the following schema:
"schema": {
"type": "object",
"title": "smart_report",
"properties": {
"actions": {
"title": "Actions",
"type": "object",
"properties": {
"singleSelection": {
"title": "Action: Single selection",
"type": "array",
"maxItems": 10,
"items": {
"type": "object",
"properties": {
"field": {
"title": "Field name",
"type": "string"
},
"label": {
"title": "Label",
"type": "string",
"description": "Label will be used for column name."
},
"chartable": {
"title": "Chartable",
"type": "boolean"
}
}
}
}
}
}
}
Now am trying to set the 'notitle' flag on 'actions' in from and trying to access the properties of 'actions', but its not working as expected:
{
"key": "actions",
"notitle": true,
"properties": {
"key": "singleSelection",
"notitle": true,
"startEmpty": true
}
},
I still see title for actions as well for 'singleSelection' and 'stratEmpty' is also not set.
If you remove the titles from the schema, as well as using the notitle attribute it should work.
(In case you remove the title, but do not use the notitle attribute, the title will be displayed with the same name as the key).

Using an array inside array

I'm trying to generate a form which will have multiple vehicles and each vehicle should have multiple people inside it.
I tried to do it by using an array inside another array. But for some obscure reasons it's not working.
This is what I want:
http://i.imgur.com/ZB2kCa1.png
This is what I have (so far):
Form:
[
{
"key": "vehicles",
"items": [
"['vehicles'][]['plate-number']",
"['vehicles'][]['color']",
{
"key": "people",
"items": [
"['vehicles'][]['people'][]['name']"
]
}
]
}
]
Schema:
{
"type": "object",
"properties": {
"vehicles": {
"type": "array",
"items": {
"type": "object",
"properties": {
"plate-number": {
"title": "Plate number",
"type": "string"
},
"color": {
"title": "Color",
"type": "string"
},
"people": {
"type": "array",
"items": {
"type": "object",
"properties": {
"title": {
"type": "string",
"enum": ["dr","jr","sir","mrs","mr","NaN","dj"]
},
"name": {
"title": "Name",
"type": "string"
}
}
}
}
}
}
}
}
}
Edit:
stefankmitph's answer solvers my problem. Thank you!
But something weird is happening: a new object person is added at the same level of vehicles. Also, when I fill a person's information and then delete this person the models is not updated.
The schema you provide does not add a property 'gender' (as shown in your picture link). So I took 'title' instead of 'gender':
[
{
"key": "vehicles",
"items": [
"vehicles[].plate-number",
"vehicles[].color", {
"key": "people",
"type": "array",
"title": "People",
"items": [
"vehicles[].people[].name",
"vehicles[].people[].title"
]
}
]
}
]
I hope this is what you're looking for!
Note: Tested with Schema Form Example Page

Resources