Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

idea: json-schema based validation #381

Open
psevestre opened this issue Dec 12, 2013 · 1 comment
Open

idea: json-schema based validation #381

psevestre opened this issue Dec 12, 2013 · 1 comment

Comments

@psevestre
Copy link

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 ?

@stevegreatrex
Copy link
Contributor

I like this idea - it's a little similar to #337

I'd not seen json-schema before and it looks like it would be a good format, but I suspect we would need a way to convert json-schema to rule definitions. Once we can do that they we could use the feature above to achieve this.

If you are familiar with this then feel free to submit a conversion and we'll see what we can do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants