Cannot parse JSON Schema to a UI Form - reactjs

I'm trying to understand how to build a schema for my form.
The data I want to store and build schema for is:
{ "aliases": { "balbalbla": ["x", "y"], "chhhhhxxxx": ["w", "q"] }
The schema I configured:
{
"title": "A registration form",
"description": "A simple form example.",
"type": "object",
"properties": {
"aliases": {
"title": "Aliases",
"description": "Inflint aliases to use together with rules.",
"type": "object",
"additionalProperties": {
"type": "array",
"items": [
{
"title": "RegEx Matcher",
"description": "Inflint will apply the alias name to match the provided RegEx.",
"type": "string"
},
{
"title": "RegEx Flags",
"description": "Inflint will apply the flags together with the RegEx string.",
"type": "string"
}
]
}
}}}
But if I go to playground of this package I use, this won't render as needed: https://rjsf-team.github.io/react-jsonschema-form/#eyJmb3JtRGF0YSI6eyJmaXJzdE5hbWUiOiJDaHVjayIsImxhc3ROYW1lIjoiTm9ycmlzIiwiYWdlIjo3NSwiYmlvIjoiUm91bmRob3VzZSBraWNraW5nIGFzc2VzIHNpbmNlIDE5NDAiLCJwYXNzd29yZCI6Im5vbmVlZCJ9LCJzY2hlbWEiOnsidGl0bGUiOiJBIHJlZ2lzdHJhdGlvbiBmb3JtIiwiZGVzY3JpcHRpb24iOiJBIHNpbXBsZSBmb3JtIGV4YW1wbGUuIiwidHlwZSI6Im9iamVjdCIsInByb3BlcnRpZXMiOnsiYWxpYXNlcyI6eyJ0aXRsZSI6IkFsaWFzZXMiLCJkZXNjcmlwdGlvbiI6IkluZmxpbnQgYWxpYXNlcyB0byB1c2UgdG9nZXRoZXIgd2l0aCBydWxlcy4iLCJ0eXBlIjoib2JqZWN0IiwiYWRkaXRpb25hbFByb3BlcnRpZXMiOnsidHlwZSI6ImFycmF5IiwiaXRlbXMiOlt7InRpdGxlIjoiUmVnRXggTWF0Y2hlciIsImRlc2NyaXB0aW9uIjoiSW5mbGludCB3aWxsIGFwcGx5IHRoZSBhbGlhcyBuYW1lIHRvIG1hdGNoIHRoZSBwcm92aWRlZCBSZWdFeC4iLCJ0eXBlIjoic3RyaW5nIn0seyJ0aXRsZSI6IlJlZ0V4IEZsYWdzIiwiZGVzY3JpcHRpb24iOiJJbmZsaW50IHdpbGwgYXBwbHkgdGhlIGZsYWdzIHRvZ2V0aGVyIHdpdGggdGhlIFJlZ0V4IHN0cmluZy4iLCJ0eXBlIjoic3RyaW5nIn1dfX19fSwidWlTY2hlbWEiOnsiZmlyc3ROYW1lIjp7InVpOmF1dG9mb2N1cyI6dHJ1ZSwidWk6ZW1wdHlWYWx1ZSI6IiIsInVpOmF1dG9jb21wbGV0ZSI6ImZhbWlseS1uYW1lIn0sImxhc3ROYW1lIjp7InVpOmVtcHR5VmFsdWUiOiIiLCJ1aTphdXRvY29tcGxldGUiOiJnaXZlbi1uYW1lIn0sImFnZSI6eyJ1aTp3aWRnZXQiOiJ1cGRvd24iLCJ1aTp0aXRsZSI6IkFnZSBvZiBwZXJzb24iLCJ1aTpkZXNjcmlwdGlvbiI6IihlYXJ0aGlhbiB5ZWFyKSJ9LCJiaW8iOnsidWk6d2lkZ2V0IjoidGV4dGFyZWEifSwicGFzc3dvcmQiOnsidWk6d2lkZ2V0IjoicGFzc3dvcmQiLCJ1aTpoZWxwIjoiSGludDogTWFrZSBpdCBzdHJvbmchIn0sImRhdGUiOnsidWk6d2lkZ2V0IjoiYWx0LWRhdGV0aW1lIn0sInRlbGVwaG9uZSI6eyJ1aTpvcHRpb25zIjp7ImlucHV0VHlwZSI6InRlbCJ9fX0sInRoZW1lIjoiZGVmYXVsdCIsImxpdmVTZXR0aW5ncyI6eyJzaG93RXJyb3JMaXN0IjoidG9wIiwidmFsaWRhdGUiOmZhbHNlLCJkaXNhYmxlIjpmYWxzZSwicmVhZG9ubHkiOmZhbHNlLCJvbWl0RXh0cmFEYXRhIjpmYWxzZSwibGl2ZU9taXQiOmZhbHNlfX0=
does anyone could tell why?

Related

Custom policy does not maintain previous values on properties array

I am creating a custom policy following this documentation.
I created one, and it is working. The JSON schema for the policy is shown below:
{
"title": "ACME Custom Basic Auth Policy",
"description": "Basic Authentication policy which enforces security according with custom consumer credentials",
"type": "object",
"properties": {
"users": {
"title": "users",
"type": "array",
"items": {
"type": "object",
"required": [
"username",
"password"
],
"properties": {
"username": {
"title": "User Name",
"type": "string",
"default": []
},
"password": {
"title": "User Password",
"type": "string",
"#context": {
"#characteristics": [
"security:sensitive"
]
}
}
}
},
"minItems": 1
}
},
"#context": {
"#vocab": "anypoint://vocabulary/policy.yaml#",
"security": "anypoint://vocabulary/policy.yaml#"
},
"$id": "allow-dynamic-resources",
"$schema": "https://json-schema.org/draft/2019-09/schema"
}
When I go to API Manager, I can configure the values on first attempt, but when I go back to change the values, they do not appear.
This happens only when I configure an array. If I configure as an object, it works. How can I fix this?

JSON Schema for array of different types with mandatory property fails validation

I created the following draft4 schema:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"$id": "catalog.structs.schema.json",
"definitions": {
"geography": {
"type": "object",
"description": "Geographical location which may or may not be part of a hierarchy.",
"properties": {
"geography_type": {
"type": "string",
"enum": ["union", "country", "state"]
},
"name": {
"type": "string",
"enum": ["Turkey", "Netherlands"]
},
"parent": {
"type": "object",
"$ref": "#/definitions/geography"
}
},
"required": ["name"]
},
"geography_group": {
"type": "array",
"description": "A grouping of discrete geographies that are not necessarily in a common hierarchy.",
"items": {
"type" : "object",
"$ref": "#/definitions/geography"
}
}
},
"oneOf": [{
"properties": {
"geography": { "type": "object", "$ref": "#/definitions/geography"},
"geography_group" : { "type": "object", "$ref": "#/definitions/geography_group"}
},
"additionalProperties": false
}]
}
The following validates correctly against the schema
{"geography":{"name":"Turkey", "geography_type":"country"}}
However, the following fails stating that the required property name is missing.
{"geography_group":[{"geography":{"name":"Turkey", "geography_type":"country"}}]}
If I remove "required": ["name"] it works, but I don't want to remove this.
What am I doing wrong?
There are a few misconceptions here, but you broadly have the right idea.
I'm not sure what you believe the oneOf is doing here. In this case, it simply isn't required, and you can put properties and additionalProperties straight in the root schema.
In terms of your problem, while you've defined geography as a property at the root level, you haven't done so for an item object in the geography_group value array.
You want to change your geograph_group definition to the following...
"geography_group": {
"type": "array",
"description": "A grouping of discrete geographies that are not necessarily in a common hierarchy.",
"items": {
"properties": {
"geograph": {
"$ref": "#/definitions/geography"
}
}
}
}
As an aside, in draft-04 of JSON Schema, any keywords alongside $ref are ignored.
The key you use in the definitions object has no bearing on the validation of your data.

SchemaForm array conditional

Background
I am making a form using http://schemaform.io/
Setup
I am trying to make an array of objects that a user can make using a form. So, the user can add as many items into the array as they want.
The array of items contains a type, then another field depending on what the type was.
If the user clicks REST, I want it to offer a field called method.
If the user clicks SSH, I want it to offer a field called path.
Code so far
SCHEMA
{
"type": "object",
"title": "Command Asset",
"properties": {
"name": {
"title": "Name",
"type": "string"
},
"commands": {
"type": "array",
"title": "Actions",
"items": {
"type": "object",
"properties": {
"commandType": {
"title": "Command Type",
"type": "string",
"enum": [
"REST",
"SSH"
]
},
"path": {
"title": "Path",
"type": "string"
},
"method": {
"title": "Method",
"type": "string"
}
}
}
}
}
}
FORM
[
{
"type": "help",
"helpvalue": "<h5>Command</h5>"
},
"name",
{
"title":"Command",
"key": "commands",
"items": [
"commands[].commandType",
{
"type": "conditional",
"condition": "modelData.commands[0].commandType=='SSH'",
"items": [
{
"key": "commands[].path"
}
]
},
{
"type": "conditional",
"condition": "modelData.commands[0].commandType=='REST'",
"items": [
{
"key": "commands[].method"
}
]
}
]
}
]
One can test this code here: http://schemaform.io/examples/bootstrap-example.html
Question
As one can see, the code I have now makes all the items' secondary properties (path or method) dependent on the first item in the array's commandType (at [0]), but I want it to depend on the commandType of the corresponding item. So, if item one has commandType of REST, it offers a method field and if item two has a command type of SSH it offers a field of path and so on.
I found an answer.
Replace the [0] with [arrayIndex].
I found it from here: https://github.com/json-schema-form/angular-schema-form/commit/21f6d3ab64435b032456dfe19e03f96b29366320

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).

Problems while creating bigquery table schema

Using Google BigQuery I need to manually create a table and load the data contained in the json file. I am using BigQuery UI, but unable to define the schema for the data, a sample of the same is given below. The problem comes with the json array as below.
{"Author": "Pranesh Nageshwar", "headline": "Train trashes crashed car", "charactercount": 1027, "dateLive": "2014-01-14", "keywords": ["train crash", "freight train", "online reporting page", "side road", "blue mountains", "new south wales", "australia", "blaxland", "new south wales", "australia", "crime stoppers", "springwood police station", "train tracks"], "id": "1226801299367"}
Arrays of values in BigQuery are represented as a field with a repeated mode. The schema you want is probably the following. If you copy and paste this into the box in the web UI, I think it will work.
[
{
"name": "author",
"type": "string"
},
{
"name": "headline",
"type": "string"
},
{
"name": "charactercount",
"type": "integer"
},
{
"name": "dateLive",
"type": "string",
},
{
"name": "keywords",
"type": "string",
"mode": "repeated"
},
{
"name": "id",
"type": "string"
}
]

Resources