From ac091cc991062d86f992bd897df49b6eb129250f Mon Sep 17 00:00:00 2001 From: Bruce D'Arcus Date: Wed, 1 Jun 2022 20:42:56 -0400 Subject: [PATCH] input: Convert root into object, require version Convert the root of schema into an object with metadata, and a required 'version' property. Include optional 'title' and 'description' properties. Also, update tests. Close #319 --- schemas/input/csl-data.json | 38 ++++++++++++++++++++++++++------ tests/schemas/input/test_json.py | 32 ++++++++++++++++++--------- 2 files changed, 52 insertions(+), 18 deletions(-) diff --git a/schemas/input/csl-data.json b/schemas/input/csl-data.json index 000e634c..b44f0741 100644 --- a/schemas/input/csl-data.json +++ b/schemas/input/csl-data.json @@ -2,18 +2,38 @@ "title": "CSL JSON/YAML", "description": "JSON schema for CSL input data", "$schema": "http://json-schema.org/draft-07/schema#", - "$id": "https://resource.citationstyles.org/schema/latest/input/json/csl-data.json", - "type": "array", - "items": { - "$ref": "#/definitions/refitem" + "$id": "https://resource.citationstyles.org/schema/v1.1/input/json/csl-data.json", + "type": "object", + "required": ["references", "version"], + "properties": { + "version": { + "type": "number", + "enum": [1.1] + }, + "title": { + "type": "string" + }, + "description": { + "type": "string" + }, + "references": { + "type": "array", + "items": { + "$ref": "#/definitions/refitem" + } + } }, "definitions": { "title-variable": { "title": "Title variable", "description": "Titles are represented as a string or as an object.", "anyOf": [ - { "$ref": "#/definitions/rich-text-string" }, - { "$ref": "#/definitions/title-object" } + { + "$ref": "#/definitions/rich-text-string" + }, + { + "$ref": "#/definitions/title-object" + } ] }, "title-object": { @@ -90,7 +110,11 @@ "type": "object", "title": "Literal Date", "description": "A date that should be passed through to the processor as is; for dates that cannot be represented in EDTF.", - "examples": [{ "literal": "Han Dynasty" }], + "examples": [ + { + "literal": "Han Dynasty" + } + ], "properties": { "literal": { "type": "string" diff --git a/tests/schemas/input/test_json.py b/tests/schemas/input/test_json.py index 6a024ae0..a2cb588e 100644 --- a/tests/schemas/input/test_json.py +++ b/tests/schemas/input/test_json.py @@ -84,10 +84,15 @@ def test_schema_is_valid(json_schema): def test_basic_data_schema_validates(csl_data_validator): - csl = [{ - 'id': 'example-id', - 'type': 'report', - }] + csl = { + 'version': 1.1, + 'references': [ + { + 'id': 'example-id', + 'type': 'report', + } + ] + } csl_data_validator.validate(csl) @@ -129,14 +134,19 @@ def test_citation_schema_compound_locator_validates(csl_citation_validator): csl_citation_validator.validate(cite) def test_basic_data_schema_with_author_validates(csl_data_validator): - csl = [{ - "id": "example-id", - "type": "report", - "author": [ - {"given": "Jane", "family": "Roe"}, - {"institution": "ACME Corporation"} + csl = { + 'version': 1.1, + 'references': [ + { + "id": "example-id", + "type": "report", + "author": [ + {"given": "Jane", "family": "Roe"}, + {"institution": "ACME Corporation"} + ] + } ] - }] + } csl_data_validator.validate(csl)