Skip to content

Commit

Permalink
Extend new oneOf validation messages to OCDS 1.0 files
Browse files Browse the repository at this point in the history
  • Loading branch information
Bjwebb committed Nov 28, 2019
1 parent 2699342 commit 18b8ec6
Show file tree
Hide file tree
Showing 6 changed files with 1,459 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

### Added

- Extend new oneOf validation messages to OCDS 1.0 files [cove#895](https://github.com/OpenDataServices/cove/issues/895#issuecomment-558721218)

## [0.12.2] - 2019-11-26

### Fixed
Expand Down
6 changes: 5 additions & 1 deletion libcove/lib/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,11 @@ def oneOf_draft4(validator, oneOf, instance, schema):
# as it lives in the parent.
# It will not match the releases array in a release package, because
# there is no oneOf.
if schema.get("title") == "Releases":
if (
schema.get("title") == "Releases"
or schema.get("description")
== "An array of linking identifiers or releases"
):
# If instance is not a list, or is a list of zero length, then
# validating against either subschema will work.
# Assume instance is an array of Linked releases, if there are no
Expand Down
146 changes: 146 additions & 0 deletions tests/lib/fixtures/common/1-0/record-package-schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
{
"id": "http://standard.open-contracting.org/schema/1__0__3/record-package-schema.json",
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Schema for an Open Contracting Record package",
"description": "The record package contains a list of records along with some publishing meta data. The records pull together all the releases under a single Open Contracting ID and compile them into the latest version of the information along with the history of any data changes.",
"type": "object",
"properties": {
"uri": {
"title": "Package Identifier",
"description": "The URI of this package that identifies it uniquely in the world.",
"type": "string",
"format": "uri"
},
"publisher": {
"description": "Information to uniquely identify the publisher of this package.",
"type": "object",
"properties": {
"name": {
"title":"Name",
"description":"The name of the organisation or department responsible for publishing this data.",
"type": "string"
},
"scheme": {
"title":"Scheme",
"description": "The scheme that holds the unique identifiers used to identify the item being identified.",
"type": ["string", "null"]
},
"uid": {
"title":"uid",
"description": "The unique ID for this entity under the given ID scheme. Note the use of 'uid' rather than 'id'. See issue #245.",
"type": ["string", "null"]
},
"uri": {
"title":"URI",
"description":"A URI to identify the publisher.",
"type": ["string", "null"],
"format" : "uri"
}
},
"required": ["name"]
},
"license": {
"description": "A link to the license that applies to the data in this datapackage. [Open Definition Conformant](http://opendefinition.org/licenses/) licenses are strongly recommended. The canonical URI of the license should be used. Documents linked from this file may be under other license conditions. ",
"type": ["string", "null"],
"format": "uri"
},
"publicationPolicy": {
"description": "A link to a document describing the publishers publication policy.",
"type": ["string", "null"],
"format": "uri"
},
"publishedDate": {
"description": "The date that this package was published.",
"type": "string",
"format": "date-time"
},
"packages": {
"description": "A list of URIs of all the release packages that were used to create this record package.",
"type": "array",
"minItems": 1,
"items": {
"type": "string",
"format": "uri"
},
"uniqueItems": true
},
"records": {
"description": "The records for this data package.",
"type": "array",
"minItems": 1,
"items": { "$ref": "#/definitions/record" },
"uniqueItems": true
}
},
"required": ["uri", "publisher", "publishedDate", "packages", "records"],
"definitions": {
"record": {
"type": "object",
"properties": {
"ocid": {
"title": "Open Contracting ID",
"description": "A unique identifier that identifies the unique Open Contracting Process. For more information see: http://standard.open-contracting.org/1.0/en/getting_started/contracting_process/",
"type": "string"
},
"releases": {
"description": "An array of linking identifiers or releases",
"oneOf": [
{
"title": "Linked releases",
"description": "A list of objects that identify the releases associated with this Open Contracting ID. The releases MUST be sorted into date order in the array, from oldest (at position 0) to newest (last).",
"type": "array",
"items": {
"description": "Information to uniquely identify the release.",
"type": "object",
"properties": {
"url": {
"description": "The url of the release which contains the url of the package with the releaseID appended using a fragment identifier e.g. http://standard.open-contracting.org/1.0/en/examples/tender.json#ocds-213czf-000-00001",
"type": ["string", "null"],
"format" : "uri"
},
"date": {
"title": "Release Date",
"description": "The date of the release, should match `date` at the root level of the release. This is used to sort the releases in the list into date order.",
"type": "string",
"format": "date-time"
},
"tag": {
"title": "Release Tag",
"description": "The tag should match the tag in the release. This provides additional context when reviewing a record to see what types of releases are included for this ocid.",
"type": "array",
"items": {
"type": "string",
"enum": ["planning", "tender", "tenderAmendment", "tenderUpdate", "tenderCancellation", "award", "awardUpdate", "awardCancellation", "contract", "contractUpdate", "contractAmendment", "implementation", "implementationUpdate", "contractTermination", "compiled"]
}
}
},
"required": ["url", "date"]
},
"minItems": 1
},
{
"title": "Embedded releases",
"description": "A list of releases, with all the data. The releases MUST be sorted into date order in the array, from oldest (at position 0) to newest (last).",
"type": "array",
"items": {
"$ref": "http://standard.open-contracting.org/schema/1__0__3/release-schema.json"
},
"minItems": 1
}
]
},
"compiledRelease": {
"title": "Compiled release",
"description": "This is the latest version of all the contracting data, it has the same schema as an open contracting release.",
"$ref": "http://standard.open-contracting.org/schema/1__0__3/release-schema.json"
},
"versionedRelease": {
"title": "Versioned release",
"description": "This contains the history of the data in the compiledRecord. With all versions of the information and the release they came from.",
"$ref": "http://standard.open-contracting.org/schema/1__0__3/versioned-release-validation-schema.json"
}
},
"required": ["ocid", "releases"]
}
}
}
58 changes: 58 additions & 0 deletions tests/lib/fixtures/common/1-0/records_invalid_releases.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"uri": "http://example.org/invalid_record.json",
"publishedDate": "2019-09-18T17:56:21.078Z",
"publisher": {
"name": "A Publisher Name"
},
"packages": ["http://example.org/release_package.json"],
"records": [
{
"ocid": "EXAMPLE-0",
"releases": []
},
{
"ocid": "EXAMPLE-1",
"releases": [
{}
]
},
{
"ocid": "EXAMPLE-2",
"releases": [
{"id": "EXAMPLE-2-1"}
]
},
{
"ocid": "EXAMPLE-3",
"releases": [
{"url": "http://example.org/releases.json#EXAMPLE-3-1"}
]
},
{
"ocid": "EXAMPLE-4",
"releases": [
{"id": "EXAMPLE-4-1"},
{}
]
},
{
"ocid": "EXAMPLE-5",
"releases": [
{"id": "EXAMPLE-5-1"},
{"url": "http://example.org/releases.json#EXAMPLE-5-2"}
]
},
{
"ocid": "EXAMPLE-97",
"releases": "a string"
},
{
"ocid": "EXAMPLE-98",
"releases": null
},
{
"ocid": "EXAMPLE-99",
"releases": {}
}
]
}
Loading

0 comments on commit 18b8ec6

Please sign in to comment.