Skip to content

Commit

Permalink
Weaken restrictions on Surveyor timestamps.
Browse files Browse the repository at this point in the history
NCS Core uses the json-schema Ruby library[0], which incorrectly
interprets schemas like this:

    sub.json
    --------
    { "attr": {
        "extends": {
          "$ref": "http://www.example.edu/super.json"
        },
        "type": [
          "string",
          "null"
        ]
    }}

    super.json
    ----------

    { "type": "string" }

Section 5.26 (on "extends") of JSON Schema Draft 03 states

    A schema that extends another schema MAY define additional
    attributes, constrain existing attributes, or add other constraints.

However, when validating a document like

    { "attr": null }

against sub.json, the json-schema library will incorrectly flag it as an
error:

    The property '#/' of type NilClass did not match the following type:
    string

I generally find altering specifications to satisfy implementations to
be distastefully backwards, but in this case I'll make an exception:

1. We need NCS Core's sync system up as fast as possible.  This is the
   most expedient path.
2. I have no evidence to prove this -- so this is very much a
   ready-fire-aim deal -- but I doubt anyone else is doing anything
   serious with Surveyor's JSON representations and a JSON Schema
   validator.

The right way to fix this would be to use an up-to-date draft of JSON
Schema (or adapt some other means of communicating JSON formats), but
draft 04 is still unpublished, and JSON Schema is the leading effort in
this field.  I guess we could also switch to a different validation
engine for NCS Core, but that takes more effort than just making
timestamps nullable all around.  So there you go.

[0] https://github.com/hoxworth/json-schema
  • Loading branch information
David Yip committed May 15, 2012
1 parent 209b51c commit 237e769
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
8 changes: 1 addition & 7 deletions doc/response_set_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,7 @@
"description": "Response set",
"properties": {
"completed_at": {
"extends": {
"$ref": "http://download.nubic.northwestern.edu/surveyor/surveyor_timestamp_schema.json#"
},
"type": [
"string",
"null"
]
"$ref": "http://download.nubic.northwestern.edu/surveyor/surveyor_timestamp_schema.json#"
},
"created_at": {
"$ref": "http://download.nubic.northwestern.edu/surveyor/surveyor_timestamp_schema.json#"
Expand Down
5 changes: 4 additions & 1 deletion doc/surveyor_timestamp_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@
"$schema": "http://json-schema.org/draft-03/schema#",
"description": "Timestamp on a Surveyor entity",
"format": "\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(?:Z|[+-]\\d{2}:\\d{2})",
"type": "string"
"type": [
"string",
"null"
]
}

0 comments on commit 237e769

Please sign in to comment.