mokkabonna / vue-vuelidate-jsonschema

Create vuelidate validation rules based on json schema
110 stars 5 forks source link

String format validation is not supported #15

Open thatside-zaraffa opened 6 years ago

thatside-zaraffa commented 6 years ago

Validation like:

"email": {
    "type": "string",
    "format": "email"
},

won't work as expected. See http://json-schema.org/latest/json-schema-validation.html#rfc.section.7 for list of currently supported formats and http://json-schema.org/draft-07/json-schema-release-notes.html#formats for those which were added in draft 7.

mokkabonna commented 6 years ago

That's correct, it is listed as an TODO in the roadmap in the readme.

It is optional. However I plan to support it. PR's are welcome though.

Implementations MAY support the "format" keyword as a validation assertion. Should they choose to do so:

they SHOULD implement validation for attributes defined below; they SHOULD offer an option to disable validation for this keyword. Implementations MAY add custom format attributes. Save for agreement between parties, schema authors SHALL NOT expect a peer implementation to support this keyword and/or custom format attributes.

thatside-zaraffa commented 6 years ago

I will try to add this if I'll have enough time. An idea to consider: maybe this library could use AJV under the hood? This is a great change but the main win from this decision would be the speed of implementation of new JSON Schema drafts because AJV author participates a lot in JSON Schema development process.

And a little off-topic issue: it seems that schemaRequired => noParamsRequired validator doesn't work like in Vuelidate (code here: https://github.com/monterail/vuelidate/blob/master/src/validators/common.js#L5).

mokkabonna commented 6 years ago
  1. Have considered it, don't remember exactly the thought process, but for now I keep it as is. As you said it is also a big change. I will probably reevaluate in the future.
  2. This intentional. I follow json schema definition of required, not vuelidate. See https://github.com/mokkabonna/vue-vuelidate-jsonschema#required-property-in-json-schema-context
moltar commented 6 years ago

+1 for ajv - it's the fastest JSON schema validator out there. Why not take advantage of that?

moltar commented 6 years ago

Another thing not supported is $data refs. Very useful for password confirmations to compare two passwords.

ajv supports this natively.