radiopurity / persephone

A material assay database
www.radiopurity.org
Apache License 2.0
12 stars 5 forks source link

Add schema validation to submit form #28

Open nepahwin opened 11 years ago

nepahwin commented 11 years ago

Original note from Adam:

import jsonschema  #https://github.com/Julian/jsonschema
import json

schema = json.loads(open('_attachments/schema/aarm.measurement.v2.01.schema.json').read())
data = json.loads(open('doc/example_assays/example_v2.01_date.json').read())

#this will raise an Exception if data doesn't match the schema
#otherwise is returns None
jsonschema.validate(data, schema)

print 'valid'
gadamc commented 11 years ago

Hi... the above example, obviously, is for python. For the client-side JS in the couchapp, we should look into using something from here: http://json-schema.org/implementations.html

note that the schema description is using the version 3 specification - the version 4 specification is very new and I don't know how much has changed.

nepahwin commented 11 years ago

I've come to think that we should only implement the schema in python upload scripts (where it will be important). The application interface is so tightly bound to the data specification that adding the schema will have very little (or no) affect on function. Submit form validation is already handled by existing infrastructure.

gadamc commented 11 years ago

Hi James..

The main reason I would implement a validation in the javascript is to make the software more robust for the developers. I understand that the application interface well matches the schema, but I would want to make sure there's some way that protects the app interface developers from making a mistake in the javascript. I don't think using one of the external JS libs for validation is very difficult. And I don't think that you will be in charge of this thing forever and/or looking over everybody's shoulder. Its like a built-in unit-test to the software that prevents builders of the website from making mistakes.

$0.02, Adam

On Mon, Jul 22, 2013 at 12:08 AM, James Loach notifications@github.comwrote:

I've come to think that we should only implement the schema in python upload scripts (where it will be important). The application interface is so tightly bound to the data specification that adding the schema will have very little (or no) affect on function. Submit form validation is already handled by existing infrastructure.

— Reply to this email directly or view it on GitHubhttps://github.com/nepahwin/persephone/issues/28#issuecomment-21327806 .

nepahwin commented 11 years ago

Yep, we'll look to implement it. I think your comment re. the developers is a good one.