Reputation: 11
I'm trying to get all of the keys from this JSON schema using react.js. The end goal is to create a system that will automatically create a dynamic form based on this schema that will change during the projects lifetime.
{
"$comment": "If additional properties are needed, then the schema should be updated",
"$id": "http://example.com/topologySchema.json",
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"description": "This entry is for topology information about an architected material",
"definitions": {
"network": {
"description": "Defines objects for architected materials that consist of a network of building blocks that are perfectly bonded together",
"type": "object",
"properties": {
"nodes": {
"type": "array"
},
"connectivity": {
"type": "array"
}
},
"allOf": [
{
"if": {
"properties": {
"family": {
"const": "network"
}
}
},
"then": {
"properties": {
"nodes": {
"type": "array"
},
"connectivity": {
"type": "array"
}
},
"required": [
"nodes",
"connectivity"
]
}
}
],
"additionalProperties": false
},
"setDimension": {
"description": "Takes parameter 'architecture_dimensionality' and associates appropriate dimensionality for parameter 'nodes' Does the same for the properties 'building_block_dimensionality' and 'connectivity'",
"allOf": [
{
"if": {
"properties": {
"architecture_dimensionality": {
"const": "1D"
}
}
},
"then": {
"properties": {
"nodes": {
"type": "array",
"minItems": 1,
"items": {
"type": "array",
"minItems": 1,
"maxItems": 1,
"items": {
"type": "number"
}
}
}
}
}
},
{
"if": {
"properties": {
"architecture_dimensionality": {
"const": "2D"
}
}
},
"then": {
"properties": {
"nodes": {
"type": "array",
"minItems": 1,
"items": {
"type": "array",
"minItems": 2,
"maxItems": 2,
"items": {
"type": "number"
}
}
}
}
}
},
{
"if": {
"properties": {
"architecture_dimensionality": {
"const": "2.5D"
}
}
},
"then": {
"properties": {
"nodes": {
"type": "array",
"minItems": 1,
"items": {
"type": "array",
"minItems": 2,
"maxItems": 2,
"items": {
"type": "number"
}
}
}
}
}
},
{
"if": {
"properties": {
"architecture_dimensionality": {
"const": "3D"
}
}
},
"then": {
"properties": {
"nodes": {
"type": "array",
"minItems": 1,
"items": {
"type": "array",
"minItems": 3,
"maxItems": 3,
"items": {
"type": "number"
}
}
}
}
}
},
{
"if": {
"properties": {
"building_block_dimensionality": {
"const": "1D"
}
}
},
"then": {
"properties": {
"connectivity": {
"type": "array",
"minItems": 1,
"items": {
"type": "array",
"minItems": 2,
"maxItems": 2,
"items": {
"type": "number"
}
}
}
}
}
},
{
"if": {
"properties": {
"building_block_dimensionality": {
"const": "2D"
}
}
},
"then": {
"properties": {
"connectivity": {
"type": "array",
"minItems": 1,
"items": {
"type": "array",
"minItems": 3,
"items": {
"type": "number"
}
}
}
}
}
},
{
"if": {
"properties": {
"building_block_dimensionality": {
"const": "2.5D"
}
}
},
"then": {
"properties": {
"connectivity": {
"type": "array",
"minItems": 1,
"items": {
"type": "array",
"minItems": 3,
"items": {
"type": "number"
}
}
}
}
}
},
{
"if": {
"properties": {
"building_block_dimensionality": {
"const": "3D"
}
}
},
"then": {
"properties": {
"connectivity": {
"type": "array",
"minItems": 1,
"items": {
"type": "array",
"minItems": 4,
"items": {
"type": "number"
}
}
}
}
}
}
]
},
"topology": {
"type": "object",
"properties": {
"architecture_dimensionality": {
"title": "architecture_dimensionality",
"type": "string",
"enum": [
"1D",
"2D",
"2.5D",
"3D"
]
},
"building_block_dimensionality": {
"type": "string",
"enum": [
"1D",
"2D",
"2.5D",
"3D"
]
},
"family": {
"type": "string",
"enum": [
"network",
"kirigami",
"origami",
"linkage",
"IPC",
"sandwich",
"other"
]
},
"hierarchicalParent": {
"type": "boolean"
},
"child": {
"type": "object",
"$ref": "#/definitions/topology"
}
},
"allOf": [
{
"$ref": "#/definitions/setDimension"
},
{
"$ref": "#/definitions/network"
},
{
"if": {
"properties": {
"hierarchicalParent": {
"const": false
}
}
},
"then": {
"properties": {
"child": {
"not": {}
}
}
},
"else": {
"required": ["child"]
}
}
]
}
},
"properties": {
"topology": { "$ref": "#/definitions/topology" }
},
"title": "Topology",
"type": "object"
}
I've tried several different ways of attempting to parse the entire schema for just the keys at first and I'm struggling to get anything to work.
Upvotes: 1
Views: 468