Skip to content

Commit

Permalink
libcove.lib.common: Support array of codelist strings
Browse files Browse the repository at this point in the history
  • Loading branch information
Bjwebb committed Mar 10, 2023
1 parent 00eb1cc commit 346f505
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 7 deletions.
15 changes: 9 additions & 6 deletions libcove/lib/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,12 +493,15 @@ def get_schema_codelist_paths(

if value.get("type") == "object":
get_schema_codelist_paths(None, value, path, codelist_paths)
elif (
value.get("type") == "array"
and isinstance(value.get("items"), dict)
and value.get("items").get("properties")
):
get_schema_codelist_paths(None, value["items"], path, codelist_paths)
elif value.get("type") == "array" and isinstance(value.get("items"), dict):
if value.get("items").get("type") == "string":
if "codelist" in value["items"] and path not in codelist_paths:
codelist_paths[path] = (
value["items"]["codelist"],
value["items"].get("openCodelist", False),
)
elif value.get("items").get("properties"):
get_schema_codelist_paths(None, value["items"], path, codelist_paths)

return codelist_paths

Expand Down
12 changes: 11 additions & 1 deletion tests/lib/fixtures/common/release-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@
"description": "Each release provides data about a single contracting process at a particular point in time. Releases can be used to notify users of new tenders, awards, contracts and other updates. Releases may repeat or update information provided previously in this contracting process. One contracting process may have many releases. A 'record' of a contracting process follows the same structure as a release, but combines information from multiple points in time into a single summary.",
"type": "object",
"properties": {
"aCodelistArray": {
"type": "array",
"title": "A Codelist Array",
"description": "An array of codelist codes. This is a dummy field for lib-cove fixtures only.",
"items": {
"type": "string",
"codelist": "releaseTag.csv",
"openCodelist": false
}
},
"ocid": {
"title": "Open Contracting ID",
"description": "A globally unique identifier for this Open Contracting Process. Composed of an ocid prefix and an identifier for the contracting process. For more information see the [Open Contracting Identifier guidance](https://standard.open-contracting.org/1.1/en/schema/identifiers/)",
Expand Down Expand Up @@ -2196,4 +2206,4 @@
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
},
"releases": [
{
"aCodelistArray": ["planning", "AAA"],
"date": "2014-03-25T00:00:00.00Z",
"language": "English",
"id": "Buyandsell.gc.ca-2014-11-07-89f689cd-e784-4374-bb17-94144679d46f",
Expand Down
10 changes: 10 additions & 0 deletions tests/lib/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -1342,4 +1342,14 @@ def test_get_additional_codelist_values():
"path": "releases/tender/items/classification",
"values": ["GSINS"],
},
("releases/aCodelistArray"): {
"path": "releases",
"field": "aCodelistArray",
"codelist": "releaseTag.csv",
"codelist_url": "https://raw.githubusercontent.com/open-contracting/standard/1.1/schema/codelists/releaseTag.csv",
"codelist_amend_urls": [],
"isopen": False,
"values": ["AAA"],
"extension_codelist": False,
},
}

0 comments on commit 346f505

Please sign in to comment.