brutusin / brutusin/json-forms
Use json-forms to generate its schemas?
- Dominant language
- JavaScript
- Stars
- 618
- Forks
- 171
- PR merge metrics
- No merged PRs in 30d
Description
In order to ensure that json-forms can generate any form I desired, I tried to write a schema which can generate itself, but failed.
Here is my schema:
{
"$schema": "http://json-schema.org/draft-03/schema#",
"type": "object",
"properties": {
"$schema": {
"type": "string",
"title": "schema",
"description": "",
"default": "http://json-schema.org/draft-03/schema#",
"readOnly": true,
"required": true
},
"type": {
"type": "string",
"title": "type",
"default": "object",
"readOnly": true
},
"properties": {
"type": "object",
"title": "properties",
"additionalProperties": {
"type": "object",
"properties": {
"type": {
"type": "string",
"enum": ["integer","string","array","object","boolean"]
},
"title": {
"type":"string"
},
"description": {
"type":"string"
},
"default": {
"dependsOn": [ "type" ]
},
"required": {
"type":"boolean"
},
"enum": {
"dependsOn": [ "type" ]
}
}
}
}
}
}
Here is my resolver function:
function resolver(names, data, cb) {
var schemas = new Object();
for(var key in data.properties) {
var type = data.properties[key].type;
if (type == 'integer' || type == 'string') {
var schema = new Object();
schema.type = type;
schemas["$.properties[*].default"] = schema;
var schema = new Object();
schema.type = 'array';
schema.items = {type:type};
schemas["$.properties[*].enum"] = schema;
}
break;
}
setTimeout(function(){cb(schemas)},500); // in order to show asynchrony
}
I encounter two problems here.
1. There is no way to distinguish instances of `additionalProperties`, since they are all marked by `*`.
2. I add the first property, and change option to triger my resolver function, it's OK. But subsequent add will fail with `Cannot read property 'type' of undefined`
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with issue #96 and reproduce the supplied self-generating schema and resolver in json-forms. Compare the resolver paths for multiple additionalProperties instances, then reproduce the failure when adding a second property and trace the undefined type error. Done means both cases resolve without ambiguity or errors.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100