diff --git a/libcove/lib/common.py b/libcove/lib/common.py index 38d3b0d..dbec286 100644 --- a/libcove/lib/common.py +++ b/libcove/lib/common.py @@ -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 diff --git a/tests/lib/fixtures/common/release-schema.json b/tests/lib/fixtures/common/release-schema.json index 96f5d4f..f6202d1 100644 --- a/tests/lib/fixtures/common/release-schema.json +++ b/tests/lib/fixtures/common/release-schema.json @@ -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/)", @@ -2196,4 +2206,4 @@ } } } -} \ No newline at end of file +} diff --git a/tests/lib/fixtures/common/tenders_releases_2_releases_codelists.json b/tests/lib/fixtures/common/tenders_releases_2_releases_codelists.json index a27b470..0096cee 100644 --- a/tests/lib/fixtures/common/tenders_releases_2_releases_codelists.json +++ b/tests/lib/fixtures/common/tenders_releases_2_releases_codelists.json @@ -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", diff --git a/tests/lib/test_common.py b/tests/lib/test_common.py index 35f8685..6296933 100644 --- a/tests/lib/test_common.py +++ b/tests/lib/test_common.py @@ -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, + }, }