Skip to content

DO NOT MERGE: trial new schema w/ input #998

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ cache: yarn
script:
- bin/check_required_files_present
- npm test
- npm run test-new-schema || true
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
},
"scripts": {
"test": "ajv -s canonical-schema.json -d \"exercises/*/canonical-data.json\"",
"test-new-schema": "ajv -s schema-with-input.json -d \"exercises/*/canonical-data.json\"",
"test-one": "ajv -s canonical-schema.json -d"
}
}
142 changes: 142 additions & 0 deletions schema-with-input.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
{
"comments":
[ " This is a JSON Schema for 'canonical-data.json' files. "
, " "
, " It enforces just a general structure for all exercises, "
, " optimising for the ability to represent example-based tests"
, " of the form 'function (input) == output'. Future expansions"
, " may allow for other types of tests such as property-based. "
, " "
, " The only thing enforced regarding how test data should be "
, " structured is the error encoding, because it was agreed "
, " and it doesn't restrict flexibility in a significant way. "
, " "
, " Standardized property names may help when automatically "
, " deriving JSON parsers in some languages, so we followed "
, " a few conventions from the 'Google JSON Style Guide'. "
, " "
, " Additionally, this schema strictly enforces letters, in "
, " lowerCamelCase, for naming the 'property' being tested. We "
, " expect this regularity will allow an easier automatic "
, " generation of function's names in test generators, "
, " slightly reducing the amount of manually generated code. "
],

"$schema": "http://json-schema.org/draft-04/schema#",

"self": { "vendor" : "io.exercism"
, "name" : "canonical-data"
, "format" : "jsonschema"
, "version": "1-0-0"
},

"$ref": "#/definitions/canonicalData",

"definitions":{

"canonicalData":
{ "description": "This is the top-level file structure"
, "type" : "object"
, "required" : ["exercise" , "version", "cases"]
, "properties" :
{ "exercise" : { "$ref": "#/definitions/exercise" }
, "version" : { "$ref": "#/definitions/version" }
, "comments" : { "$ref": "#/definitions/comments" }
, "cases" : { "$ref": "#/definitions/testGroup" }
}
, "additionalProperties": false
},

"exercise":
{ "description": "Exercise's slug (kebab-case)"
, "type" : "string"
, "pattern" : "^[a-z]+(-[a-z]+)*$"
},

"version" :
{ "description" : "Semantic versioning: MAJOR.MINOR.PATCH"
, "type" : "string"
, "pattern" : "^(0|[1-9][0-9]*)(\\.(0|[1-9][0-9]*)){2}$"
},

"comments":
{ "description": "An array of strings to fake multi-line comments"
, "type" : "array"
, "items" : { "type": "string" }
, "minItems" : 1
},

"testGroup":
{ "description": "An array of labeled test items"
, "type" : "array"
, "items" : { "$ref": "#/definitions/labeledTestItem" }
, "minItems" : 1
},

"labeledTestItem":
{ "description": "A single test or group of tests with a description"
, "oneOf": [ { "$ref": "#/definitions/labeledTest" }
, { "$ref": "#/definitions/labeledTestGroup" }
]
},

"labeledTest":
{ "description": "A single test with a description"
, "type" : "object"
, "required" : ["description", "property", "input", "expected"]
, "properties" :
{ "description": { "$ref": "#/definitions/description" }
, "comments" : { "$ref": "#/definitions/comments" }
, "property" : { "$ref": "#/definitions/property" }
, "input" : { "$ref": "#/definitions/input" }
, "expected" : { "$ref": "#/definitions/expected" }
}
, "additionalProperties": false
},

"labeledTestGroup":
{ "description": "A group of tests with a description"
, "type" : "object"
, "required" : ["description", "cases"]
, "properties" :
{ "description": { "$ref": "#/definitions/description" }
, "comments" : { "$ref": "#/definitions/comments" }
, "cases" : { "$ref": "#/definitions/testGroup" }
}
, "additionalProperties": false
},

"description":
{ "description": "A short, clear, one-line description"
, "type" : "string"
},

"property":
{ "description": "A letters-only, lowerCamelCase property name"
, "type" : "string"
, "pattern" : "^[a-z]+([A-Z][a-z]+)*[A-Z]?$"
},

"input":
{ "description": "The inputs to a test case"
, "type" : "object"
},

"expected":
{ "description": "The expected return value of a test case"
, "properties":
{ "error": { "$ref": "#/definitions/error" }
}
, "dependencies":
{ "error": { "maxProperties": 1 }
}
},

"error":
{ "description": "A message describing an error condition"
, "type" : "string"
}

}

}