React-jsonschema-form: JSON Schema for UISchema validation

Created on 28 Aug 2019  路  9Comments  路  Source: rjsf-team/react-jsonschema-form

UISchema is a JSON object with specific properties and structure as described in documentation https://react-jsonschema-form.readthedocs.io/en/latest/form-customization/
It seems natural to have a JSON Schema that could be used to validate UISchema. Unfortunately I failed to find any.

Is it exists yet? Do you think it is a good idea to create one?

Most helpful comment

I have managed to validate uiSchema ui:widgets using the widgetMap from utils.
I created a validate function to loop through the uiSchema, get the type from schema and looks for a match in widgetMap

All 9 comments

Why would it be useful to validate a uiSchema? Unlike formData, which can be entered by the user, uiSchema is entered by the developer.

We actually have use cases where the UISchema can be modified by the end-user. These cases are
extremely controlled and have a form on top of it.

One way I can think of handling this @limexp would be to write a schema that controls your UISchema prop. The issue with UISchema and having a general schema for it is that they are flexible and developer-defined. Beyond checking that it's valid JSON I don't see what more the library could offer in terms of validation.

Is there a way to determine that a particular ui:widget type exists?

Our UISchemas are entered into the system in a similar way to the playground, but i am getting errors as the user is entering the data.
ie Uncaught Error: No widget "passwor" for type "string" - if i was to rename password.

The playground doesn't update the UISchema until the ui:widget value that is entered is valid. Trying to find a way to replicate this. Thanks for your help and good work

I have managed to validate uiSchema ui:widgets using the widgetMap from utils.
I created a validate function to loop through the uiSchema, get the type from schema and looks for a match in widgetMap

Ok, glad that worked! Do you have any ideas as to how we could make that easier from the side of react-jsonschema-form?

Maybe an option would be to ignore invalid uiSchema widgets or other invalid options. Rather than throwing an exception if its not recognised, just fall back to the original schema definition? thanks again, appreciate your work on this

@ba11en do you have code examples to share? I need to do the exact same thing. The UI schema can be entered "on the fly" by developers to change the form layout, and we want to validate it prior to saving as developers make mistakes.

I call this validate function when something changes in the UISchema textarea form input -
widgetMap is from utils.js in rjsf lib

function validateUISchemaProperty(prop, type, widget) {
if (widget === undefined) return null;

if (!widgetMap.hasOwnProperty(type)) {
console.log("type " + type + " not valid");
return "Type (" + type + ") not valid"; // type error
}
if (!widgetMap[type].hasOwnProperty(widget)) {
console.log("prop " + prop + " has error");
return "ui:widget \"" + widget + "\" is not valid for \"" + prop + "\" (type: " + type + ")"; // widget has error
}
return null;
}

My use case for this is that I allow 3rd parties to customize my application at runtime using json metadata. I provide a schema for this metdata, so they can validate against it. Amongst other things, the metadata allows custom forms to be defined.If a schema doc existed, in my schema, I'd #ref it in places where I permit a uischema.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

abhishekpdubey picture abhishekpdubey  路  3Comments

jabaren picture jabaren  路  3Comments

ebower12 picture ebower12  路  3Comments

norim13 picture norim13  路  3Comments

Eric24 picture Eric24  路  3Comments