Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

react-jsonschema-form to generate a form itself #1465

Closed
3 tasks done
GitToby opened this issue Sep 12, 2019 · 12 comments
Closed
3 tasks done

react-jsonschema-form to generate a form itself #1465

GitToby opened this issue Sep 12, 2019 · 12 comments

Comments

@GitToby
Copy link

GitToby commented Sep 12, 2019

Prerequisites

Description

Is there a schema that produces a form to generate another form JSON schema? Simmilar to issue #1276, however the owner of that issue vanished.

i.e. a meta jsonschema form that creates other jsonschema forms

Steps to Reproduce

make and run this app:

iconst Form = JSONSchemaForm.default;
const schema = {
    "$schema": "http://json-schema.org/draft-07/schema#",
    "$id": "http://json-schema.org/draft-07/schema#",
    "title": "Core schema meta-schema",
...
};
const uiSchema = {
  description: {
    "ui:widget": "textarea"
  }
};

ReactDOM.render(<Form schema={schema} uiSchema={uiSchema}/>, 
             document.getElementById("main"));

https://jsfiddle.net/jsToby/u98aygc6/

Expected behavior

A form that allows the user to generate a fully valid JSONSchema which produces a form.

Actual behavior

Inputting the definition provided on http://json-schema.org creates the following error:

Core schema meta-schema
Unsupported field schema for field root: Unknown field type object,boolean.

Version

1.8.0

You can usually get this information in your package.json or in the file URL if you're using the unpkg one.

@epicfaace
Copy link
Member

I'm interested in this too! I think the definition you found on json-schema.org is the correct one; it's just that rjsf can't render such a complicated schema yet. We may have to change the framework to add more features (such as, for example, handling types of both object and boolean) but I think it would give us a cool and useful result.

@Relequestual
Copy link
Contributor

Consider Stoplight Studio: https://stoplight.io/studio/
ccing @philsturgeon should you want further info.

@GitToby
Copy link
Author

GitToby commented Sep 13, 2019

@epicfaace it makes sense rjsf cant render a tuple of types as the form should only output one type of result?

Once I fixed the unsupported schema problem setting "type": "object" at the root, i get the following error:

Error: Could not find a definition for #.

@Relequestual my use case for making a meta form is to dynamically generate validating forms for different schemas on the fly and persist them in a database. Thanks for the link though, looks super useful!

@Relequestual
Copy link
Contributor

@GitToby Ah OK.
Yeah, there are a lot of complexities in generating forms for ALL valid schemas.
We would like to t some point work with the teams behind such form generators to define a generalised form vocabulary, post draft-8 release. =]

@epicfaace
Copy link
Member

epicfaace commented Sep 13, 2019

@epicfaace it makes sense rjsf cant render a tuple of types as the form should only output one type of result?

Not really, it would be nice to support this. See #282 and @mfulton26 's suggestion at #282 (comment) on how to handle it by having a "type" dropdown. That being said, though, the only time in which type is an object is the main type: ["object", "boolean"], so maybe we don't need to handle this because form builders will almost always build root schemas that are objects, not booleans.

Once I fixed the unsupported schema problem setting "type": "object" at the root, i get the following error:

Error: Could not find a definition for #.

This is probably because currently, the only definitions rjsf supports are those whose paths start with #/definitions. See @domharrington 's PR #954.

@Relequestual my use case for making a meta form is to dynamically generate validating forms for different schemas on the fly and persist them in a database. Thanks for the link though, looks super useful!

Yeah, I'm working on the same problem too (creating a form builder UI using react-jsonschema-form itself), so would love to get some progress on this. Those two issues above are probably the major issues needed to be resolved, but more may crop up. If you are willing to help move these fixes forward, that would be great!

@GitToby
Copy link
Author

GitToby commented Sep 13, 2019

Yeah, i can take a quick look over the weekend. looks like that PR has gone a bit stale and out of date, i'll look into it anyways! 📚 🔍

@domharrington
Copy link
Contributor

@GitToby we're using my fork in production at ReadMe to generate dynamic forms from user's OAS files. You can see this in action here: https://preview.readme.io/.

Would love to get it merged in so we don't have to rely on my fork and so others can use it.

@knilink
Copy link
Contributor

knilink commented Oct 3, 2019

If the form support the meta schema then it should be possible.

node -p "JSON.stringify((new require('ajv')()).getSchema('http://json-schema.org/draft-07/schema').schema,null,2)"

@JulesGosnell
Copy link

Guys,

I'm just starting a project that would really benefit from having this working.

Can anyone give me the status of this issue ?

We may have some time to throw at it...

Many thanks,

Jules

@JulesGosnell
Copy link

Looking at the draft-07 meta-schema (https://json-schema.org/draft-07/schema), it looks to me as though it is defined tightly enough to validate a schema, yet not tightly enough to make building one via react-jsonschema-form as easy an experience as it could be...

For example, The draft-07 meta-schema seems to define the set of properties that an object in the schema might have as a big flat space including e.g. "multipleOf" (for use with "number"s) and "additionaItems" (for use with "array"s) in the same breath. It also includes what appear to be semantically mutually exclusive pairs e.g. "maximum" and "exclusiveMaximum" with no indication of this exclusivity.

I was hoping to use the meta-schema to drive a web-form in which, if I chose to add a new string-property in the resulting schema, I would only be presented with potential attributes for that property which made sense in the context of a string.

As far as I can make out, the introduction of vocabularies in draft-2019-09 does not address this.

In conclusion, it looks to me as though, in order to get the best results out of my meta-schema-generated form, I will have to define my own form-friendly meta-schema ? Has anyone else come to the same conclusion or know of any work in this direction which I might use/extend/contribute-to ?

Many thanks,

Jules

@epicfaace
Copy link
Member

I will have to define my own form-friendly meta-schema

Yeah, that's probably correct. Doing this would be a great addition to rjsf, though, as it would clarify what exactly we support and what features of JSON Schema we don't yet support.

@stale
Copy link

stale bot commented Jul 22, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Please leave a comment if this is still an issue for you. Thank you.

@stale stale bot added the wontfix label Jul 22, 2022
@stale stale bot closed this as completed Aug 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants