From e0003b066b15d3c7d5cbefb430b6c88ad0808431 Mon Sep 17 00:00:00 2001 From: Tom Kralidis Date: Thu, 25 Feb 2021 10:04:54 -0500 Subject: [PATCH] update queryables response --- docs/source/tour.rst | 2 +- pygeoapi/api.py | 17 ++++++++++++----- tests/test_api.py | 8 ++++---- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/docs/source/tour.rst b/docs/source/tour.rst index 0c765a8..78b24c3 100644 --- a/docs/source/tour.rst +++ b/docs/source/tour.rst @@ -62,7 +62,7 @@ Collection queryables http://localhost:5000/collections/obs/queryables -The queryables endpoint provides a list of queryable properties and their associated datatypes. +The queryables endpoint provides the collection's queryable properties and associated datatypes. Collection items diff --git a/pygeoapi/api.py b/pygeoapi/api.py index cb801d3..e68b741 100644 --- a/pygeoapi/api.py +++ b/pygeoapi/api.py @@ -696,7 +696,12 @@ class API: return headers_, 500, to_json(exception, self.pretty_print) queryables = { - 'queryables': [] + 'type': 'object', + 'title': self.config['resources'][dataset]['title'], + 'properties': {}, + '$schema': 'http://json-schema.org/draft/2019-09/schema', + '$id': '{}/collections/{}/queryables'.format( + self.config['server']['url'], dataset) } for k, v in p.fields.items(): @@ -708,10 +713,12 @@ class API: show_field = True if show_field: - queryables['queryables'].append({ - 'queryable': k, - 'type': v - }) + queryables['properties'][k] = { + 'title': k, + 'type': v['type'] + } + if 'values' in v: + queryables['properties'][k]['enum'] = v['values'] if format_ == 'html': # render queryables['title'] = self.config['resources'][dataset]['title'] diff --git a/tests/test_api.py b/tests/test_api.py index 5d42b22..d5288e8 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -258,8 +258,8 @@ def test_get_collection_queryables(config, api_): req_headers, {'f': 'json'}, 'obs') queryables = json.loads(response) - assert 'queryables' in queryables - assert len(queryables['queryables']) == 6 + assert 'properties' in queryables + assert len(queryables['properties']) == 6 # test with provider filtered properties api_.config['resources']['obs']['providers'][0]['properties'] = ['stn_id'] @@ -268,8 +268,8 @@ def test_get_collection_queryables(config, api_): req_headers, {'f': 'json'}, 'obs') queryables = json.loads(response) - assert 'queryables' in queryables - assert len(queryables['queryables']) == 1 + assert 'properties' in queryables + assert len(queryables['properties']) == 1 def test_describe_collections_json_ld(config, api_):