developmentseed / bones-document

Document model with JSV validation, other nice conventions
4 stars 3 forks source link

make better use of JSV #3

Closed AdrianRossouw closed 13 years ago

AdrianRossouw commented 13 years ago

The use of json-schema and JSV in the existing code base is incorrect and very inefficient. This changeset initializes a single jsv environment, and then validates the entire instance against a dynamically registered and cached schema.

Previously each field was being validated separately, using the env.validate method, which not only validates the data, but also the schema and the schema's schema (ie: the entire json-schema spec) on each invocation.

This patch requires that models must have correct json-schema definitions, and not just the properties fragment. Other than the additional top-level 'properties' key in the schema, none of the other keys are required for normal operation, but providing an 'id' for the schema aids in caching.

I removed the code that evaluates that considered empty strings as not meeting the 'required' condition, and recommend that the schema implementer also set 'minLength' to 1 on strings that are both required and may not be empty.