json-schema-form / angular-schema-form

Generate forms from a JSON schema, with AngularJS!
https://json-schema-form.github.io/angular-schema-form
MIT License
2.47k stars 654 forks source link

There is no schema to validate a Form Schema against #113

Open quietlyconfident opened 10 years ago

quietlyconfident commented 10 years ago

Brief

There should be a schema that defines what a valid angular-schema-form schema is, and could be used to validate an angular-schema-form schema.

Background

From the README, Angular Schema Form can:

  1. Create a form directly from a JSON schema, and
  2. Validate form fields against the same JSON schema.

In other words, to use Angular-Schema-Form, you create a Form Definition which is a JSON Schema and defines the layout of the form as well as the validation requirements for the data. Angular-Schema-Form translates this into an HTML form and the data can come back and be validated against the Form Definition. Great! So far, so good.

But, how do you know if your Form Definition is valid? In other words, how to know that the Form Definition doesn't request unsupported field types, i.e. attempts to use an unsupported add-on, etc? Or perhaps if the Form Definition is just malformd.

To do so, it would be nice if there were another schema against which the Form Definition could be validated This would serve two purposes:

  1. It would prevent typo issues and all of the other sorts of errors that data validation protects against.
  2. The schema could help enable compatibility with other projects, for example:
quietlyconfident commented 10 years ago

I am unable to assign labels but, in my view, this should be labeled enhancement.

fiddur commented 10 years ago

That's a good idea, and would make error messages much clearer!

quietlyconfident commented 10 years ago

Architecture

rhalff commented 10 years ago

Hi, I like this idea and tried to made an attempt in creating such a thing:

https://github.com/rhalff/json-form-form-schema-validator

The current schema is overhere: https://github.com/rhalff/json-form-form-schema-validator/blob/master/schema-form.json

I'm not sure it will make error messages much cleared though, because the .form array can contain many different types.

The error report will then show it did not match any of the possible structures.

e.g. It will not tell you whether a field looks like a select and there was a typo somewhere. The select would just not match and the next definition is tried.

I was hopeing I could use this schema to automatically generate a form to define a form, but it's still far off, angular-schema-form would also need to understand "$ref" which it currently doesn't.

Anthropic commented 7 years ago

@rhalff as of 1.0.0-alpha.2 $ref is supported as a preprocessing step.