From 292fd2efb25d8ed3bc0c31306a40a0b452e6dd79 Mon Sep 17 00:00:00 2001 From: Will Pugh Date: Mon, 20 May 2013 17:30:19 -0700 Subject: [PATCH 1/3] Fixed a number of places where the validation was incorrect: 1) Used to require the "Required if Available" fields. Now there is a checkbox to require this 2) Added a checkbox to require extended fields if required. 3) Fixed a number of properties that were a little wrong, e.g. keywords should be keyword. 4) Fixed a number of the formats. E.g. issued + modified require date not datetime. --- index.html | 86 ++++++++++------ js/schema.coffee | 261 +++++++++++++++++++++++++++-------------------- js/schema.js | 152 ++++++++++++++++++++++++++- js/validate.js | 6 +- 4 files changed, 361 insertions(+), 144 deletions(-) diff --git a/index.html b/index.html index 1a02c25..24e1c4c 100755 --- a/index.html +++ b/index.html @@ -33,33 +33,61 @@

Check your data file

+ { + "title": "Data Catalog", + "description": "Version 1.0", + "keyword": "catalog", + "modified": "2013-05-09", + "publisher": "US Department of X", + "person": "Contact Person", + "mbox": "contact.person@agency.gov", + "identifier": "1", + "accessLevel": "Public", + "distribution": [{ + "accessURL": "http://agency.gov/data.json", + "format": "json" + }] + }, + { + "title": "Public Elementary/Secondary Listing", + "description": "The purpose of the CCD nonfiscal surveys is to provide a listing of all schools and agencies providing free public elementary and secondary education, along with basic descriptive statistical information on each school and agency listed. Penalties apply for misuse, seehttp://nces.ed.gov/ncesglobal/data_usage_agreement.aspfor more details.", + "keyword": "education, schools", + "modified": "2011-11-19", + "publisher": "US Department of Education", + "person": "Open Data Initiative", + "mbox": "opendata@ed.gov", + "identifier": "ykv5-fn9t", + "accessLevel": "Public", + "dataDictionary": "http://nces.ed.gov/ccd/pdf/INsc09101a.pdf", + "distribution": [{ + "accessURL": "https://explore.data.gov/views/ykv5-fn9t/rows.csv?accessType=DOWNLOAD", + "format": "csv", + "size": "200mb" + },{ + "accessURL": "https://explore.data.gov/views/ykv5-fn9t/rows.json?accessType=DOWNLOAD", + "format": "json" + },{ + "accessURL": "https://explore.data.gov/views/ykv5-fn9t/rows.xml?accessType=DOWNLOAD", + "format": "xml" + }], + "webService": "http://explore.data.gov/api/views/ykv5-fn9t/rows.json", + "license": "Public Domain", + "spatial": "US", + "temporal": "2009-09-01 00:00:00,2010-05-31 00:00:00", + "frequency": "one-time", + "language": "English", + "granularity": "", + "dataQuality": "true", + "theme": "education", + "references": "http://nces.ed.gov/ccd/data/txt/psu091alay.txt", + "landingPage": "http://ed.gov/developer", + "feed": "", + "systemOfRecords": "http://nces.ed.gov/ccd/" + }] + + Require "Required if Applicable" Fields
+ Require all Extended Fields
+

Status

@@ -69,8 +97,8 @@

Additional Resources

diff --git a/js/schema.coffee b/js/schema.coffee index 8d5c0bc..05c313a 100644 --- a/js/schema.coffee +++ b/js/schema.coffee @@ -1,113 +1,156 @@ #Project open data reporting schema #For more information on the format, # see https://github.com/Baggz/Amanda/blob/master/docs/json/objects/schema.md +# +#For more information on the project open data schema, see http://project-open-data.github.io/schema/ + +require_if_available = () -> document.getElementById("require_if_available").checked +require_extended = () -> document.getElementById("require_extended").checked + + +rebuild_schema = () -> + window.schema = + type: "array" + minItems: 1 + required: true + uniqueItems: true + items: + type: "object" + properties: + + # + # required fields + title: + type: "string" + required: true + + description: + type: "string" + required: true + + keyword: + type: "string" + required: true + + modified: + type: "string" + format: "date" + required: true + + publisher: + type: "string" + required: true + + person: + type: "string" + required: true + + mbox: + type: "string" + required: true + + identifier: + type: [ "string", "integer" ] + required: true + + accessLevel: + type: "string" + required: true + enum: [ + "Public", "Restricted", "Private" + ] + + # + # required if available + dataDictionary: + type: "string" + format: "url" + required: require_if_available() + + accessURL: + type: "string" + format: "url" + required: require_if_available() + + format: + type: [ "string", "array" ] + required: require_if_available() + + license: + type: "string" + required: require_if_available() + + webService: + type: "string" + format: "url" + required: require_if_available() + + spatial: { + required: require_if_available() + } # what format is this? + + temporal: { + required: require_if_available() + } # what format is this? + + + # + #expanded fields + + format: + type: [ "string", "array" ] + required: require_extended() + + issued: + type: "string" + format: "date" + required: require_extended() + + accrualPeriodicity: + type: "string" + enum: ["hourly", "daily", "weekly", "yearly", "other"] + required: require_extended() + + language: + type: "string" + required: require_extended() + + granularity: + type: "string" + required: require_extended() + + dataQuality: + type: "string" + required: require_extended() + + theme: + type: "string" + required: require_extended() + + references: + type: "string" + required: require_extended() + + distribution: + type: [ "string", "array", "object" ] + required: require_extended() + + size: + type: [ "string", "integer" ] + required: require_extended() + + + download: + type: "string" + format: "url" + required: require_extended() + + Feed: + type: "string" + format: "url" + required: require_extended() + +rebuild_schema() + +window.rebuild_schema = rebuild_schema -window.schema = - type: "array" - minItems: 1 - required: true - uniqueItems: true - items: - type: "object" - properties: - - #basic fields - - title: - type: "string" - required: true - - description: - type: "string" - required: true - - dataDictionary: - type: "string" - format: "url" - required: true - - accessURL: - type: "string" - format: "url" - required: true - - keywords: - type: "array" - required: true - minItems: 1 - items: - type: "string" - - license: - type: "string" - required: true - - public: - type: "boolean" - required: true - - organization: - type: "string" - required: true - - #expanded fields - - modified: - type: "string" - format: "datetime" - - format: - type: [ "string", "array" ] - - publisher: - type: "string" - - issued: - type: "string" - format: "datetime" - - accrualPeriodicity: - type: "string" - - identifier: - type: [ "string", "integer" ] - - spatial: {} # what format is this? - - temporal: {} # what format is this? - - language: - type: "string" - - granularity: - type: "string" - - dataQuality: - type: "string" - - theme: - type: "string" - - references: - type: "object" - - distribution: - type: [ "string", "array", "object" ] - - size: - type: [ "string", "integer" ] - - format: - type: [ "string", "array" ] - - download: - type: "string" - format: "url" - - WebService: - type: "string" - format: "url" - - Feed: - type: "string" - format: "url" \ No newline at end of file diff --git a/js/schema.js b/js/schema.js index e9d6373..dfc89a2 100644 --- a/js/schema.js +++ b/js/schema.js @@ -1,2 +1,150 @@ -// Generated by CoffeeScript 1.4.0 -(function(){window.schema={type:"array",minItems:1,required:!0,uniqueItems:!0,items:{type:"object",properties:{title:{type:"string",required:!0},description:{type:"string",required:!0},dataDictionary:{type:"string",format:"url",required:!0},accessURL:{type:"string",format:"url",required:!0},keywords:{type:"array",required:!0,minItems:1,items:{type:"string"}},license:{type:"string",required:!0},"public":{type:"boolean",required:!0},organization:{type:"string",required:!0},modified:{type:"string",format:"datetime"},format:{type:["string","array"]},publisher:{type:"string"},issued:{type:"string",format:"datetime"},accrualPeriodicity:{type:"string"},identifier:{type:["string","integer"]},spatial:{},temporal:{},language:{type:"string"},granularity:{type:"string"},dataQuality:{type:"string"},theme:{type:"string"},references:{type:"object"},distribution:{type:["string","array","object"]},size:{type:["string","integer"]},format:{type:["string","array"]},download:{type:"string",format:"url"},WebService:{type:"string",format:"url"},Feed:{type:"string",format:"url"}}}}}).call(this); \ No newline at end of file +// Generated by CoffeeScript 1.6.2 +(function() { + var rebuild_schema, require_extended, require_if_available; + + require_if_available = function() { + return document.getElementById("require_if_available").checked; + }; + + require_extended = function() { + return document.getElementById("require_extended").checked; + }; + + rebuild_schema = function() { + return window.schema = { + type: "array", + minItems: 1, + required: true, + uniqueItems: true, + items: { + type: "object", + properties: { + title: { + type: "string", + required: true + }, + description: { + type: "string", + required: true + }, + keyword: { + type: "string", + required: true + }, + modified: { + type: "string", + format: "date", + required: true + }, + publisher: { + type: "string", + required: true + }, + person: { + type: "string", + required: true + }, + mbox: { + type: "string", + required: true + }, + identifier: { + type: ["string", "integer"], + required: true + }, + accessLevel: { + type: "string", + required: true, + "enum": ["Public", "Restricted", "Private"] + }, + dataDictionary: { + type: "string", + format: "url", + required: require_if_available() + }, + accessURL: { + type: "string", + format: "url", + required: require_if_available() + }, + format: { + type: ["string", "array"], + required: require_if_available() + }, + license: { + type: "string", + required: require_if_available() + }, + webService: { + type: "string", + format: "url", + required: require_if_available() + }, + spatial: { + required: require_if_available() + }, + temporal: { + required: require_if_available() + }, + format: { + type: ["string", "array"], + required: require_extended() + }, + issued: { + type: "string", + format: "date", + required: require_extended() + }, + accrualPeriodicity: { + type: "string", + "enum": ["hourly", "daily", "weekly", "yearly", "other"], + required: require_extended() + }, + language: { + type: "string", + required: require_extended() + }, + granularity: { + type: "string", + required: require_extended() + }, + dataQuality: { + type: "string", + required: require_extended() + }, + theme: { + type: "string", + required: require_extended() + }, + references: { + type: "string", + required: require_extended() + }, + distribution: { + type: ["string", "array", "object"], + required: require_extended() + }, + size: { + type: ["string", "integer"], + required: require_extended() + }, + download: { + type: "string", + format: "url", + required: require_extended() + }, + Feed: { + type: "string", + format: "url", + required: require_extended() + } + } + } + }; + }; + + rebuild_schema(); + + window.rebuild_schema = rebuild_schema; + +}).call(this); diff --git a/js/validate.js b/js/validate.js index 137260e..be206cc 100644 --- a/js/validate.js +++ b/js/validate.js @@ -1,10 +1,9 @@ -// Generated by CoffeeScript 1.4.0 +// Generated by CoffeeScript 1.6.2 (function() { var ProjectOpenDataValidator, __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; ProjectOpenDataValidator = (function() { - ProjectOpenDataValidator.prototype.feedback = $('#feedback'); ProjectOpenDataValidator.prototype.input = $('#input'); @@ -24,8 +23,7 @@ ProjectOpenDataValidator.prototype.validatorOptions = {}; function ProjectOpenDataValidator() { - this.validate = __bind(this.validate, this); - this.codeMirror = CodeMirror.fromTextArea(this.input[0], this.codeMirrorOptions); + this.validate = __bind(this.validate, this); this.codeMirror = CodeMirror.fromTextArea(this.input[0], this.codeMirrorOptions); this.validator = amanda('json'); this.validate(); } From 84a200d7f784e91aa3f06428463609f22e1bed9d Mon Sep 17 00:00:00 2001 From: Will Pugh Date: Mon, 20 May 2013 17:46:21 -0700 Subject: [PATCH 2/3] Fixed up the markdown to include instructions on running locally. --- readme.md | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/readme.md b/readme.md index 8d39e4d..be811ce 100644 --- a/readme.md +++ b/readme.md @@ -1,7 +1,8 @@ JSON Validator ============== -A validation tool to confirm the formatting of agency.gov/data catalog files. +A validation tool to confirm the formatting of agency.gov/data catalog files. This validates the format against the schema defined in +[Project Open Data](http://project-open-data.github.io/schema/) What Problem This Solves ------------------------ @@ -12,4 +13,20 @@ After generating a federal government data catalog file, it can be difficult to How This Solves It ------------------ -This parses a JSON file and indicates whether it's comformant. +This parses a JSON file and indicates whether it's conformant. + + +Building and running locally +------------------ + +This is an HTML/Coffeescript application. It uses linked repos, so in order to run this locally, you should do the following after cloning: + cd json-validator + git submodule init + git submodule update + +Then you should be able to simply browse the 'json-validator/index.html' file + +If you want to make changes, you should change the '.coffee' files, and compile them with the coffeescript compiler: + coffee -c js/*.coffee + +You can find information about coffee script [here](http://coffeescript.org/) From a0f28fc5d0f55e3a87b94e958be8dc13380ddd5f Mon Sep 17 00:00:00 2001 From: Will Pugh Date: Mon, 20 May 2013 17:48:40 -0700 Subject: [PATCH 3/3] Fixed some formatting issues --- readme.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/readme.md b/readme.md index be811ce..7ada424 100644 --- a/readme.md +++ b/readme.md @@ -20,6 +20,7 @@ Building and running locally ------------------ This is an HTML/Coffeescript application. It uses linked repos, so in order to run this locally, you should do the following after cloning: + cd json-validator git submodule init git submodule update @@ -27,6 +28,7 @@ This is an HTML/Coffeescript application. It uses linked repos, so in order to Then you should be able to simply browse the 'json-validator/index.html' file If you want to make changes, you should change the '.coffee' files, and compile them with the coffeescript compiler: + coffee -c js/*.coffee You can find information about coffee script [here](http://coffeescript.org/)