Comments (21)
Is there any progress on internal references? I just downloaded JsonForm for the first time and instantly encountered this when I tried to use my schema. And I think I can't avoid using $ref
because I need to allow infinite object nesting (just a relevant chunk of my schema):
"animation": {
"type": "object",
"properties": {
"properties": {
"type": "object"
},
"duration": {
"type": "integer"
},
"stepper": {
"type": "string"
},
"then": {
"$ref": "#/definitions/animation"
}
}
}
Is there any way I can work around this or I have to find another solution?
from jsonform.
Please reopen.
from jsonform.
The simplest workaround:
function resolveRefs(obj, defs)
{
Object.keys(obj).forEach(function(prop, index, array){
var def = obj[prop];
if (def.$ref) {
var ref = def.$ref.replace(/^#\/definitions\//, '');
obj[prop] = defs[ref];
} else if (typeof def === 'object') {
resolveRefs(def, defs);
}
})
}
resolveRefs(schema, schema.definitions);
from jsonform.
is there a definition of what the ref link should look like? I have some time
from jsonform.
I have a schema defining a comments history and I got the same issue. Any progress?
from jsonform.
Thx @schaman, I just implemented simple inline resolve according to your code in above mentioned commit in my dev branch.
And @igorpan now we have a working workaround version for your schema in my playground: http://ulion.github.io/jsonform/playground/?example=schema-inline-ref
from jsonform.
Bump! Looking to use this in a new project, but we have a complex json schema accross many files using many $refs.
It would be great to add each schema object to jsonform then generate a form. For example, we have a common definitions file, and multiple schemas that ref eachother.
from jsonform.
resolveRefs(data.schema, data.schema.definitions);
$('form').jsonForm(data);
Uncaught RangeError: Maximum call stack size exceeded
at String.replace ()
at escapeSelector (jsonform.js:101)
at formTree.buildFromLayout (jsonform.js:3108)
at formTree. (jsonform.js:3196)
at underscore.js:73
from jsonform.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
from jsonform.
https://json-schema.org/understanding-json-schema/structuring.html
from jsonform.
@sciurius thx.. is there a place to talk about this outside of this issue?
from jsonform.
i know its been 7 years,
so this is a specific subset of the jsonform.org spec which allows all kinds of target refs (not just 'definitions')
I think this needs a hash of already resolved links, to prevent recursion, and probably have to make a resolved copy of the target
so you don't trapse into it every time. oops. resolved..
it is ok to stomp on the source definition?
function resolveRefs(obj, defs)
{
Object.keys(obj).forEach(function(prop, index, array){
var def = obj[prop];
if (def.$ref) {
var ref = def.$ref.replace(/^#\/definitions\//, '');
obj[prop] = defs[ref];
} else if (typeof def === 'object') {
resolveRefs(def, defs);
}
})
}
and the uri resolution decoder.. , ~0, ~1 and %nn
external would never work for my use (unless it was a full URI), as the lib doesn't know where THIS doc came from as its loaded directly via javascript.
from jsonform.
External refs (/schemas) should not be in the scope of this feature, you're right.
For internal refs (/definitions), we should process the definitions
property first, and then replace them where needed. I would implement this as a pre-processor, I think, and directly modify the JSON object that is fed to JSONForm
from jsonform.
in general I agree. the example is recursive, as it uses the definition IN the definition. not sure how to update the object with this.
from jsonform.
In the spec, the loop is ok for the validation process, but in our case where we need to construct the form, it's slightly more complicated. I think we might need to stop at the first level. Maybe put a parameter for this, like levels: <integer>
for instance ? Or a "global" parameter in the JSONForm object that could be overriden ? I'm not sure...
from jsonform.
I was thinking stop at the 1st level.
the question is what do you put in the schema for any secondary?, or is that an error? then the example would fail.
thus rule : no refs in /definitions
from jsonform.
And no { "$ref": "#" }
too.
I think that we should be able to display an error stating the problem
from jsonform.
just fyi, I got jammed on another project suddenly.. so my 'free' time evaporated
from jsonform.
That's alright, don't worry :)
from jsonform.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
from jsonform.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
from jsonform.
Related Issues (20)
- change the 'previously submitted values' from a variable. HOT 26
- Ace Type as Array HOT 10
- How to Map My Custom JSON Value to JSON Forms HOT 8
- titleMap in selectbox array HOT 4
- [Question] How to get the markup of the form programatically in JS without attaching it to a DOM element HOT 3
- How to make a valid json with a onChange function ? HOT 4
- Add custom field to fieldset HOT 2
- activeClass isn't applied correctly for schemas with defaults HOT 2
- How to build a stepper form HOT 4
- process change, just fyi.. all PRs against develop branch
- Expanded Fieldset + Default TabIndex set - Collapse issue (bug) HOT 4
- tabs-left not supported in bootstrap v3
- Hide submit button HOT 2
- How to escape slash in scope HOT 3
- Rendering fails if property name contains dots HOT 1
- Missing array brackets [] on array items when using a custom field type HOT 1
- Error: JSONForm does not yet support schemas that use the $ref keyword. See: #54" HOT 2
- Boolean options are always true HOT 5
- How to use this library with bundler HOT 1
- How to show error after a control value is changed, HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jsonform.