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 653 forks source link

Misinterpretation of "required" for boolean properties #928

Closed tommywalsh closed 6 years ago

tommywalsh commented 6 years ago

The JSON Schema spec says this about the "required" keyword:

An object instance is valid against this keyword if every item in the array is the name of a property in the instance.

In other words, marking a property as "required" is supposed to mean "This property must not be omitted from the object instance".

See http://json-schema.org/latest/json-schema-validation.html#rfc.section.6.17

For boolean properties, I believe this keyword is being misinterpreted. It appears that angular-schema-form is interpreting "required" to mean "The user must check this box". Or, in other words "required" is being interpreted to mean "This property must have the value 'true'".

This can be seen on the schemaform demo site: http://schemaform.io/examples/bootstrap-example.html 1) Select the "Kitchen Sink" option 2) In the schema section, add "soul" to the "required" array. 3) Go to the "generated form" section, and uncheck the "Terms of Service" checkbox. 4) Click the "Do It" button

You will see "Form is not valid", and you will see that the "Terms of Service" widget gets a red "required" warning.

It seems as if angular-schema-form is imposing its own meaning onto the "required" keyword for boolean properties. This seemingly makes it impossible to define a schema that says "the object instance must contain this field, but it can be either true or false".

Anthropic commented 6 years ago

I believe this is a duplicate of #857 which has been resolved in the latest alpha. I'm hoping to release another in the next few weeks.