GithubHelp home page GithubHelp logo

Comments (21)

igorpan avatar igorpan commented on May 15, 2024 4

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.

sciurius avatar sciurius commented on May 15, 2024 3

Please reopen.

from jsonform.

schaman avatar schaman commented on May 15, 2024 1

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.

sdetweil avatar sdetweil commented on May 15, 2024 1

is there a definition of what the ref link should look like? I have some time

from jsonform.

jlopezr avatar jlopezr commented on May 15, 2024

I have a schema defining a comments history and I got the same issue. Any progress?

from jsonform.

ulion avatar ulion commented on May 15, 2024

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.

englercj avatar englercj commented on May 15, 2024

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.

Bluesoniq avatar Bluesoniq commented on May 15, 2024

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.

stale avatar stale commented on May 15, 2024

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.

sciurius avatar sciurius commented on May 15, 2024

https://json-schema.org/understanding-json-schema/structuring.html

from jsonform.

sdetweil avatar sdetweil commented on May 15, 2024

@sciurius thx.. is there a place to talk about this outside of this issue?

from jsonform.

sdetweil avatar sdetweil commented on May 15, 2024

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.

tchapi avatar tchapi commented on May 15, 2024

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.

sdetweil avatar sdetweil commented on May 15, 2024

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.

tchapi avatar tchapi commented on May 15, 2024

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.

sdetweil avatar sdetweil commented on May 15, 2024

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.

tchapi avatar tchapi commented on May 15, 2024

And no { "$ref": "#" } too.

I think that we should be able to display an error stating the problem

from jsonform.

sdetweil avatar sdetweil commented on May 15, 2024

just fyi, I got jammed on another project suddenly.. so my 'free' time evaporated

from jsonform.

tchapi avatar tchapi commented on May 15, 2024

That's alright, don't worry :)

from jsonform.

stale avatar stale commented on May 15, 2024

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.

stale avatar stale commented on May 15, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.