Changeset 499 for Dev


Ignore:
Timestamp:
03/10/14 11:50:04 (11 years ago)
Author:
hendrikvanantwerpen
Message:
  • Schema patterns should be anchored.
  • App returns validation result on error.
Location:
Dev/trunk/src/server
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • Dev/trunk/src/server/app.js

    r497 r499  
    225225    function putDocument(id,rev,type,doc) {
    226226        var priv = stripAndReturnPrivates(doc);
    227         if ( doc.type === type && validator(doc, schema).valid ) {
     227        var valid;
     228        if ( doc.type === type && (valid = validator(doc, schema)).valid ) {
    228229            var opts = rev ? {headers:{'If-Match':'"'+rev+'"'}} : {};
    229230            return HTTPResult.fromResponsePromise(couch.put(id,doc,opts).response,
     
    241242            });
    242243        } else {
    243             return new HTTPResult(400,{error: "Document failed schema verification."});
     244            return new HTTPResult(400,{error: "Document failed schema verification.", valid: valid});
    244245        }
    245246    }
     
    262263    function postDocument(type,doc) {
    263264        var priv = stripAndReturnPrivates(doc);
    264         if ( doc.type === type && validator(doc, schema).valid ) {
     265        var valid;
     266        if ( doc.type === type && (valid = validator(doc, schema)).valid ) {
    265267            return HTTPResult.fromResponsePromise(couch.post(doc).response,
    266268                                                  handleUnknownError)
     
    274276            });
    275277        } else {
    276             return new HTTPResult(400,{error: "Document failed schema verification."});
     278            return new HTTPResult(400,{error: "Document failed schema verification.", valid: valid});
    277279        }
    278280    }
  • Dev/trunk/src/server/config/couchdb-schema.json

    r493 r499  
    1212      "type": "object",
    1313      "properties": {
    14           "_id": { "type": "string", "pattern": "schemaInfo" },
     14          "_id": { "type": "string", "pattern": "^schemaInfo$" },
    1515          "_rev": { "type": "string" },
    1616          "version": { "type": "string" }
     
    3232        "type": "object",
    3333        "properties": {
    34           "type": { "type": "string", "pattern": "Question" },
     34          "type": { "type": "string", "pattern": "^Question$" },
    3535          "_id": { "type": "string" },
    3636          "_rev": { "type": "string" },
     
    4949        "type": "object",
    5050        "properties": {
    51           "type": { "type": "string", "pattern": "Survey" },
     51          "type": { "type": "string", "pattern": "^Survey$" },
    5252          "_id": { "type": "string" },
    5353          "_rev": { "type": "string" },
     
    6363        "type": "object",
    6464        "properties": {
    65           "type": { "type": "string", "pattern": "SurveyRun" },
     65          "type": { "type": "string", "pattern": "^SurveyRun$" },
    6666          "_id": { "type": "string" },
    6767          "_rev": { "type": "string" },
     
    8282        "type": "object",
    8383        "properties": {
    84           "type": { "type": "string", "pattern": "Response" },
     84          "type": { "type": "string", "pattern": "^Response$" },
    8585          "_id": { "type": "string" },
    8686          "_rev": { "type": "string" },
     
    112112        "type": "object",
    113113        "properties": {
    114           "type": { "type": "string", "pattern": "Header" },
     114          "type": { "type": "string", "pattern": "^Header$" },
    115115          "text": { "type": "string" }
    116116        },
     
    121121        "type": "object",
    122122        "properties": {
    123           "type": { "type": "string", "pattern": "Text" },
     123          "type": { "type": "string", "pattern": "^Text$" },
    124124          "text": { "type": "string" }
    125125        },
     
    130130        "type": "object",
    131131        "properties": {
    132           "type": { "type": "string", "pattern": "Divider" }
     132          "type": { "type": "string", "pattern": "^Divider$" }
    133133        },
    134134        "additionalProperties": false
     
    137137        "type": "object",
    138138        "properties": {
    139           "type": { "type": "string", "pattern": "StringInput" },
     139          "type": { "type": "string", "pattern": "^StringInput$" },
    140140          "text": { "type": "string" }
    141141        },
     
    146146        "type": "object",
    147147        "properties": {
    148           "type": { "type": "string", "pattern": "TextInput" },
     148          "type": { "type": "string", "pattern": "^TextInput$" },
    149149          "maxLength": { "type": "integer" },
    150150          "text": { "type": "string" }
     
    156156        "type": "object",
    157157        "properties": {
    158           "type": { "type": "string", "pattern": "NumberInput" },
     158          "type": { "type": "string", "pattern": "^NumberInput$" },
    159159          "min": { "type": "integer" },
    160160          "max": { "type": "integer" },
     
    168168        "type": "object",
    169169        "properties": {
    170           "type": { "type": "string", "pattern": "ScaleInput" },
     170          "type": { "type": "string", "pattern": "^ScaleInput$" },
    171171          "minLabel": { "type": "string" },
    172172          "min": { "type": "integer" },
     
    191191        "type": "object",
    192192        "properties": {
    193           "type": { "type": "string", "pattern": "MultipleChoiceInput" },
     193          "type": { "type": "string", "pattern": "^MultipleChoiceInput$" },
    194194          "allowMultiple": { "type": "boolean" },
    195195          "items": { "type": "array", "items": {
Note: See TracChangeset for help on using the changeset viewer.