Improve design document validation
Jira: COUCHDB-2818
Validates top level values:
- These should be object: "options", "filters", "lists",
"shows", "updates", "views"
- "rewrites" is an array
- "language" and "validate_doc_update" are strings
Values in "filters", "lists", "shows", "updates" should be strings.
They are mappings from function names to function contents.
Values in "options" can be anything (currently there are 2 boolean
options, but they are not checked specifically).
Views are special:
- "lib" is special: its value will be an object that
contains mapping to different libraries. The contents of
that object is not validated.
- If any other object has "map" or "reduce" value, it should
be a string.
Also try to produce helpful messages for user so they know where
the problem is.
Some examples of responses:
```
$ http -phb PUT $DB1/db2/_design/des1 views:='{"v1":"nope"}'
HTTP/1.1 400 Bad Request
{
"error": "invalid_design_doc", "reason": "View v1 must be an object"
}
$ http -phb PUT $DB1/db2/_design/des1 lists:='{"l1":true}'
HTTP/1.1 400 Bad Request
{
"error": "invalid_design_doc", "reason": "`l1` in lists is not a string"
}
$ http -phb PUT $DB1/db2/_design/des1 views:='{"v1": {"map":1}}'
HTTP/1.1 400 Bad Request
{
"error": "invalid_design_doc", "reason": "`map` in v1 must be a string"
}
```
2 files changed