Knockout-Contrib / Knockout-Contrib/Knockout-Validation

idea: json-schema based validation

Open
#381 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
1k
Forks
366
PR merge metrics
No merged PRs in 30d

Description

Hi,

I've used this library in a small project and it server really well for my purposes. I'm now considering its use in larger projects, but the idea of having two sets of rules (front-end and back-end) in order to validate the same model seems to violate the DRY principle.

json-schema are useful because they provide a formal description of the data a given service is supposed to produce and/our consume. Depending on your development methodology, you can use it to automatically generate Java (or other language of choice) objects that can be de/serialized to the a compliant JSON representation. You also have the option to generate the schema from existing classes, though this path has some limitations.

Given this scenario, I was wondering that it would be very nice if I could derive validation rules straight from a json schema.

So, instead of this:

mymodel.observable1.extend( rule );
mymodel.observable2.extend( rule );
...
mymodel.a.nested.observable2.extend( rule );
mymodel.a.very.very.very.very.deepply.nested.observable2.extend( rule );
...

One could just do like that:

mymodel.extend(schema:someJsonSchema)

where 'someJsonSchema' is a json-schema object retrieved somehow.

There are a number of json-schema javssscript implementations, but none of them (as far as I know) can deal with observables(). One way would be to simply unwrap the structure and use the existing libraries, but this seems inefficient, specially for complex data structures.

WDYT ?

Contributor guide

Open the contributing guide

Research direction

The issue names no files, tests, or entry points. Start by reviewing the existing observable-level extend(rule) validation API and how models and nested observables are handled; the work would need a defined schema-based API, supported JSON Schema behavior, and tests showing validation of nested data.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.