From 05ac393aaaefd9c212570ba20a45921771d3fe77 Mon Sep 17 00:00:00 2001 From: Tom Kralidis Date: Wed, 16 Oct 2019 12:28:58 -0400 Subject: [PATCH 1/2] update to canonical OAPIF schema locations (#276) --- pygeoapi/openapi.py | 2 +- tests/pygeoapi-test-openapi.yml | 50 ++++++++++++++++----------------- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/pygeoapi/openapi.py b/pygeoapi/openapi.py index 1d2d7c0..d95a2e2 100644 --- a/pygeoapi/openapi.py +++ b/pygeoapi/openapi.py @@ -41,7 +41,7 @@ LOGGER = logging.getLogger(__name__) # TODO: handle this better once schemas are public/final # allow also for schema caching OPENAPI_YAML = { - 'oapif': 'https://raw.githubusercontent.com/opengeospatial/ogcapi-features/master/core/openapi/ogcapi-features-1.yaml', # noqa + 'oapif': 'http://schemas.opengis.net/ogcapi/features/part1/1.0/openapi/ogcapi-features-1.yaml', # noqa 'oapip': 'https://raw.githubusercontent.com/opengeospatial/wps-rest-binding/master/core/openapi' # noqa } diff --git a/tests/pygeoapi-test-openapi.yml b/tests/pygeoapi-test-openapi.yml index b9bc761..0a0a727 100644 --- a/tests/pygeoapi-test-openapi.yml +++ b/tests/pygeoapi-test-openapi.yml @@ -104,11 +104,11 @@ paths: - $ref: '#/components/parameters/f' responses: 200: - $ref: https://raw.githubusercontent.com/opengeospatial/ogcapi-features/master/core/openapi/ogcapi-features-1.yaml#/components/responses/LandingPage + $ref: http://schemas.opengis.net/ogcapi/features/part1/1.0/openapi/ogcapi-features-1.yaml#/components/responses/LandingPage 400: - $ref: https://raw.githubusercontent.com/opengeospatial/ogcapi-features/master/core/openapi/ogcapi-features-1.yaml#/components/responses/InvalidParameter + $ref: http://schemas.opengis.net/ogcapi/features/part1/1.0/openapi/ogcapi-features-1.yaml#/components/responses/InvalidParameter 500: - $ref: https://raw.githubusercontent.com/opengeospatial/ogcapi-features/master/core/openapi/ogcapi-features-1.yaml#/components/responses/ServerError + $ref: http://schemas.opengis.net/ogcapi/features/part1/1.0/openapi/ogcapi-features-1.yaml#/components/responses/ServerError summary: Landing page tags: - server @@ -121,7 +121,7 @@ paths: 200: $ref: '#/components/responses/200' 400: - $ref: https://raw.githubusercontent.com/opengeospatial/ogcapi-features/master/core/openapi/ogcapi-features-1.yaml#/components/responses/InvalidParameter + $ref: http://schemas.opengis.net/ogcapi/features/part1/1.0/openapi/ogcapi-features-1.yaml#/components/responses/InvalidParameter default: $ref: '#/components/responses/default' summary: This document @@ -134,11 +134,11 @@ paths: - $ref: '#/components/parameters/f' responses: 200: - $ref: https://raw.githubusercontent.com/opengeospatial/ogcapi-features/master/core/openapi/ogcapi-features-1.yaml#/components/responses/Collections + $ref: http://schemas.opengis.net/ogcapi/features/part1/1.0/openapi/ogcapi-features-1.yaml#/components/responses/Collections 400: - $ref: https://raw.githubusercontent.com/opengeospatial/ogcapi-features/master/core/openapi/ogcapi-features-1.yaml#/components/responses/InvalidParameter + $ref: http://schemas.opengis.net/ogcapi/features/part1/1.0/openapi/ogcapi-features-1.yaml#/components/responses/InvalidParameter 500: - $ref: https://raw.githubusercontent.com/opengeospatial/ogcapi-features/master/core/openapi/ogcapi-features-1.yaml#/components/responses/ServerError + $ref: http://schemas.opengis.net/ogcapi/features/part1/1.0/openapi/ogcapi-features-1.yaml#/components/responses/ServerError summary: Feature Collections tags: - server @@ -149,13 +149,13 @@ paths: - $ref: '#/components/parameters/f' responses: 200: - $ref: https://raw.githubusercontent.com/opengeospatial/ogcapi-features/master/core/openapi/ogcapi-features-1.yaml#/components/responses/Collection + $ref: http://schemas.opengis.net/ogcapi/features/part1/1.0/openapi/ogcapi-features-1.yaml#/components/responses/Collection 400: - $ref: https://raw.githubusercontent.com/opengeospatial/ogcapi-features/master/core/openapi/ogcapi-features-1.yaml#/components/responses/InvalidParameter + $ref: http://schemas.opengis.net/ogcapi/features/part1/1.0/openapi/ogcapi-features-1.yaml#/components/responses/InvalidParameter 404: - $ref: https://raw.githubusercontent.com/opengeospatial/ogcapi-features/master/core/openapi/ogcapi-features-1.yaml#/components/responses/NotFound + $ref: http://schemas.opengis.net/ogcapi/features/part1/1.0/openapi/ogcapi-features-1.yaml#/components/responses/NotFound 500: - $ref: https://raw.githubusercontent.com/opengeospatial/ogcapi-features/master/core/openapi/ogcapi-features-1.yaml#/components/responses/ServerError + $ref: http://schemas.opengis.net/ogcapi/features/part1/1.0/openapi/ogcapi-features-1.yaml#/components/responses/ServerError summary: Get feature collection metadata tags: - obs @@ -178,19 +178,19 @@ paths: - csv type: string style: form - - $ref: https://raw.githubusercontent.com/opengeospatial/ogcapi-features/master/core/openapi/ogcapi-features-1.yaml#/components/parameters/bbox - - $ref: https://raw.githubusercontent.com/opengeospatial/ogcapi-features/master/core/openapi/ogcapi-features-1.yaml#/components/parameters/limit + - $ref: http://schemas.opengis.net/ogcapi/features/part1/1.0/openapi/ogcapi-features-1.yaml#/components/parameters/bbox + - $ref: http://schemas.opengis.net/ogcapi/features/part1/1.0/openapi/ogcapi-features-1.yaml#/components/parameters/limit - $ref: '#/components/parameters/sortby' - $ref: '#/components/parameters/startindex' responses: 200: - $ref: https://raw.githubusercontent.com/opengeospatial/ogcapi-features/master/core/openapi/ogcapi-features-1.yaml#/components/responses/Features + $ref: http://schemas.opengis.net/ogcapi/features/part1/1.0/openapi/ogcapi-features-1.yaml#/components/responses/Features 400: - $ref: https://raw.githubusercontent.com/opengeospatial/ogcapi-features/master/core/openapi/ogcapi-features-1.yaml#/components/responses/InvalidParameter + $ref: http://schemas.opengis.net/ogcapi/features/part1/1.0/openapi/ogcapi-features-1.yaml#/components/responses/InvalidParameter 404: - $ref: https://raw.githubusercontent.com/opengeospatial/ogcapi-features/master/core/openapi/ogcapi-features-1.yaml#/components/responses/NotFound + $ref: http://schemas.opengis.net/ogcapi/features/part1/1.0/openapi/ogcapi-features-1.yaml#/components/responses/NotFound 500: - $ref: https://raw.githubusercontent.com/opengeospatial/ogcapi-features/master/core/openapi/ogcapi-features-1.yaml#/components/responses/ServerError + $ref: http://schemas.opengis.net/ogcapi/features/part1/1.0/openapi/ogcapi-features-1.yaml#/components/responses/ServerError summary: Get Observations features tags: - obs @@ -198,17 +198,17 @@ paths: get: description: My cool observations parameters: - - $ref: https://raw.githubusercontent.com/opengeospatial/ogcapi-features/master/core/openapi/ogcapi-features-1.yaml#/components/parameters/featureId + - $ref: http://schemas.opengis.net/ogcapi/features/part1/1.0/openapi/ogcapi-features-1.yaml#/components/parameters/featureId - $ref: '#/components/parameters/f' responses: 200: - $ref: https://raw.githubusercontent.com/opengeospatial/ogcapi-features/master/core/openapi/ogcapi-features-1.yaml#/components/responses/Feature + $ref: http://schemas.opengis.net/ogcapi/features/part1/1.0/openapi/ogcapi-features-1.yaml#/components/responses/Feature 400: - $ref: https://raw.githubusercontent.com/opengeospatial/ogcapi-features/master/core/openapi/ogcapi-features-1.yaml#/components/responses/InvalidParameter + $ref: http://schemas.opengis.net/ogcapi/features/part1/1.0/openapi/ogcapi-features-1.yaml#/components/responses/InvalidParameter 404: - $ref: https://raw.githubusercontent.com/opengeospatial/ogcapi-features/master/core/openapi/ogcapi-features-1.yaml#/components/responses/NotFound + $ref: http://schemas.opengis.net/ogcapi/features/part1/1.0/openapi/ogcapi-features-1.yaml#/components/responses/NotFound 500: - $ref: https://raw.githubusercontent.com/opengeospatial/ogcapi-features/master/core/openapi/ogcapi-features-1.yaml#/components/responses/ServerError + $ref: http://schemas.opengis.net/ogcapi/features/part1/1.0/openapi/ogcapi-features-1.yaml#/components/responses/ServerError summary: Get Observations feature by id tags: - obs @@ -219,11 +219,11 @@ paths: - $ref: '#/components/parameters/f' responses: 200: - $ref: https://raw.githubusercontent.com/opengeospatial/ogcapi-features/master/core/openapi/ogcapi-features-1.yaml#/components/responses/ConformanceDeclaration + $ref: http://schemas.opengis.net/ogcapi/features/part1/1.0/openapi/ogcapi-features-1.yaml#/components/responses/ConformanceDeclaration 400: - $ref: https://raw.githubusercontent.com/opengeospatial/ogcapi-features/master/core/openapi/ogcapi-features-1.yaml#/components/responses/InvalidParameter + $ref: http://schemas.opengis.net/ogcapi/features/part1/1.0/openapi/ogcapi-features-1.yaml#/components/responses/InvalidParameter 500: - $ref: https://raw.githubusercontent.com/opengeospatial/ogcapi-features/master/core/openapi/ogcapi-features-1.yaml#/components/responses/ServerError + $ref: http://schemas.opengis.net/ogcapi/features/part1/1.0/openapi/ogcapi-features-1.yaml#/components/responses/ServerError summary: API conformance definition tags: - server From 7b8dc69865c1ee48701d102b24cd70be120c6936 Mon Sep 17 00:00:00 2001 From: Tom Kralidis Date: Wed, 16 Oct 2019 21:29:43 -0400 Subject: [PATCH 2/2] rename some functions to align with specification updates (#278) --- pygeoapi/api.py | 6 ++-- pygeoapi/flask_app.py | 10 +++--- pygeoapi/starlette_app.py | 8 ++--- tests/test_api.py | 73 ++++++++++++++++++++------------------- 4 files changed, 49 insertions(+), 48 deletions(-) diff --git a/pygeoapi/api.py b/pygeoapi/api.py index c187a18..1915472 100644 --- a/pygeoapi/api.py +++ b/pygeoapi/api.py @@ -215,7 +215,7 @@ class API(object): return headers_, 200, json.dumps(openapi) @pre_process - def api_conformance(self, headers_, format_): + def conformance(self, headers_, format_): """ Provide conformance definition @@ -408,7 +408,7 @@ class API(object): return headers_, 200, json.dumps(fcm, default=json_serial) - def get_features(self, headers, args, dataset, pathinfo=None): + def get_collection_items(self, headers, args, dataset, pathinfo=None): """ Queries feature collection @@ -736,7 +736,7 @@ class API(object): return headers_, 200, json.dumps(content, default=json_serial) @pre_process - def get_feature(self, headers_, format_, dataset, identifier): + def get_collection_item(self, headers_, format_, dataset, identifier): """ Get a single feature diff --git a/pygeoapi/flask_app.py b/pygeoapi/flask_app.py index d0839d9..2053069 100644 --- a/pygeoapi/flask_app.py +++ b/pygeoapi/flask_app.py @@ -98,15 +98,15 @@ def api(): @APP.route('/conformance') -def api_conformance(): +def conformance(): """ OGC open api conformance access point :returns: HTTP response """ - headers, status_code, content = api_.api_conformance(request.headers, - request.args) + headers, status_code, content = api_.conformance(request.headers, + request.args) response = make_response(content, status_code) if headers: @@ -145,10 +145,10 @@ def dataset(feature_collection, feature=None): """ if feature is None: - headers, status_code, content = api_.get_features( + headers, status_code, content = api_.get_collection_items( request.headers, request.args, feature_collection) else: - headers, status_code, content = api_.get_feature( + headers, status_code, content = api_.get_collection_item( request.headers, request.args, feature_collection, feature) response = make_response(content, status_code) diff --git a/pygeoapi/starlette_app.py b/pygeoapi/starlette_app.py index 368e16b..29f3f81 100644 --- a/pygeoapi/starlette_app.py +++ b/pygeoapi/starlette_app.py @@ -103,14 +103,14 @@ async def api(request: Request): @app.route('/conformance') @app.route('/conformance/') -async def api_conformance(request: Request): +async def conformance(request: Request): """ OGC open api conformance access point :returns: Starlette HTTP Response """ - headers, status_code, content = api_.api_conformance( + headers, status_code, content = api_.conformance( request.headers, request.query_params) response = Response(content=content, status_code=status_code) @@ -160,11 +160,11 @@ async def dataset(request: Request, feature_collection=None, feature=None): if 'feature' in request.path_params: feature = request.path_params['feature'] if feature is None: - headers, status_code, content = api_.get_features( + headers, status_code, content = api_.get_collection_items( request.headers, request.query_params, feature_collection, pathinfo=request.scope['path']) else: - headers, status_code, content = api_.get_feature( + headers, status_code, content = api_.get_collection_item( request.headers, request.query_params, feature_collection, feature) response = Response(content=content, status_code=status_code) diff --git a/tests/test_api.py b/tests/test_api.py index 15a440c..8dd1d3f 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -120,20 +120,20 @@ def test_root(config, api_): assert rsp_headers['Content-Type'] == 'text/html' -def test_api_conformance(config, api_): +def test_conformance(config, api_): req_headers = make_req_headers() - rsp_headers, code, response = api_.api_conformance(req_headers, {}) + rsp_headers, code, response = api_.conformance(req_headers, {}) root = json.loads(response) assert isinstance(root, dict) assert 'conformsTo' in root assert len(root['conformsTo']) == 4 - rsp_headers, code, response = api_.api_conformance( + rsp_headers, code, response = api_.conformance( req_headers, {'f': 'foo'}) assert code == 400 - rsp_headers, code, response = api_.api_conformance( + rsp_headers, code, response = api_.conformance( req_headers, {'f': 'html'}) assert rsp_headers['Content-Type'] == 'text/html' @@ -187,54 +187,55 @@ def test_describe_collections(config, api_): assert rsp_headers['Content-Type'] == 'text/html' -def test_get_features(config, api_): +def test_get_collection_items(config, api_): req_headers = make_req_headers() - rsp_headers, code, response = api_.get_features( + rsp_headers, code, response = api_.get_collection_items( req_headers, {}, 'foo') features = json.loads(response) assert code == 400 - rsp_headers, code, response = api_.get_features( + rsp_headers, code, response = api_.get_collection_items( req_headers, {'f': 'foo'}, 'obs') features = json.loads(response) assert code == 400 - rsp_headers, code, response = api_.get_features( + rsp_headers, code, response = api_.get_collection_items( req_headers, {'bbox': '1,2,3'}, 'obs') features = json.loads(response) assert code == 400 - rsp_headers, code, response = api_.get_features( + rsp_headers, code, response = api_.get_collection_items( req_headers, {'bbox': '1,2,3,4c'}, 'obs') assert code == 400 - rsp_headers, code, response = api_.get_features( + rsp_headers, code, response = api_.get_collection_items( req_headers, {'f': 'html'}, 'obs') assert rsp_headers['Content-Type'] == 'text/html' - rsp_headers, code, response = api_.get_features(req_headers, {}, 'obs') + rsp_headers, code, response = api_.get_collection_items( + req_headers, {}, 'obs') features = json.loads(response) assert len(features['features']) == 5 - rsp_headers, code, response = api_.get_features( + rsp_headers, code, response = api_.get_collection_items( req_headers, {'resulttype': 'hits'}, 'obs') features = json.loads(response) assert len(features['features']) == 0 # Invalid limit - rsp_headers, code, response = api_.get_features( + rsp_headers, code, response = api_.get_collection_items( req_headers, {'limit': 0}, 'obs') features = json.loads(response) assert code == 400 - rsp_headers, code, response = api_.get_features( + rsp_headers, code, response = api_.get_collection_items( req_headers, {'limit': 2}, 'obs') features = json.loads(response) @@ -253,13 +254,13 @@ def test_get_features(config, api_): assert links[3]['rel'] == 'collection' # Invalid startindex - rsp_headers, code, response = api_.get_features( + rsp_headers, code, response = api_.get_collection_items( req_headers, {'startindex': -1}, 'obs') features = json.loads(response) assert code == 400 - rsp_headers, code, response = api_.get_features( + rsp_headers, code, response = api_.get_collection_items( req_headers, {'startindex': 2}, 'obs') features = json.loads(response) @@ -277,7 +278,7 @@ def test_get_features(config, api_): assert '/collections/obs' in links[3]['href'] assert links[3]['rel'] == 'collection' - rsp_headers, code, response = api_.get_features( + rsp_headers, code, response = api_.get_collection_items( req_headers, {'startindex': 1, 'limit': 1, 'bbox': '-180,90,180,90'}, 'obs') features = json.loads(response) @@ -301,97 +302,97 @@ def test_get_features(config, api_): assert '/collections/obs' in links[4]['href'] assert links[4]['rel'] == 'collection' - rsp_headers, code, response = api_.get_features( + rsp_headers, code, response = api_.get_collection_items( req_headers, {'sortby': 'stn_id', 'stn_id': '35'}, 'obs') assert code == 400 - rsp_headers, code, response = api_.get_features( + rsp_headers, code, response = api_.get_collection_items( req_headers, {'sortby': 'stn_id:FOO', 'stn_id': '35', 'value': '89.9'}, 'obs') assert code == 400 - rsp_headers, code, response = api_.get_features( + rsp_headers, code, response = api_.get_collection_items( req_headers, {'sortby': 'stn_id:A'}, 'obs') features = json.loads(response) # FIXME? this test errors out currently assert code == 400 - rsp_headers, code, response = api_.get_features( + rsp_headers, code, response = api_.get_collection_items( req_headers, {'f': 'csv'}, 'obs') assert rsp_headers['Content-Type'] == 'text/csv; charset=utf-8' - rsp_headers, code, response = api_.get_features( + rsp_headers, code, response = api_.get_collection_items( req_headers, {'datetime': '2003'}, 'obs') assert code == 200 - rsp_headers, code, response = api_.get_features( + rsp_headers, code, response = api_.get_collection_items( req_headers, {'datetime': '1999'}, 'obs') assert code == 400 - rsp_headers, code, response = api_.get_features( + rsp_headers, code, response = api_.get_collection_items( req_headers, {'datetime': '2010-04-22'}, 'obs') assert code == 400 - rsp_headers, code, response = api_.get_features( + rsp_headers, code, response = api_.get_collection_items( req_headers, {'datetime': '2001-11-11/2003-12-18'}, 'obs') assert code == 200 - rsp_headers, code, response = api_.get_features( + rsp_headers, code, response = api_.get_collection_items( req_headers, {'datetime': '../2003-12-18'}, 'obs') assert code == 200 - rsp_headers, code, response = api_.get_features( + rsp_headers, code, response = api_.get_collection_items( req_headers, {'datetime': '2001-11-11/..'}, 'obs') assert code == 200 - rsp_headers, code, response = api_.get_features( + rsp_headers, code, response = api_.get_collection_items( req_headers, {'datetime': '1999/2005-04-22'}, 'obs') assert code == 400 - rsp_headers, code, response = api_.get_features( + rsp_headers, code, response = api_.get_collection_items( req_headers, {'datetime': '2002/2014-04-22'}, 'obs') api_.config['datasets']['obs']['extents'].pop('temporal') - rsp_headers, code, response = api_.get_features( + rsp_headers, code, response = api_.get_collection_items( req_headers, {'datetime': '2002/2014-04-22'}, 'obs') assert code == 200 -def test_get_feature(config, api_): +def test_get_collection_item(config, api_): req_headers = make_req_headers() - rsp_headers, code, response = api_.get_feature( + rsp_headers, code, response = api_.get_collection_item( req_headers, {'f': 'foo'}, 'obs', '371') assert code == 400 - rsp_headers, code, response = api_.get_feature( + rsp_headers, code, response = api_.get_collection_item( req_headers, {}, 'foo', '371') assert code == 400 - rsp_headers, code, response = api_.get_feature( + rsp_headers, code, response = api_.get_collection_item( req_headers, {}, 'obs', 'notfound') assert code == 404 - rsp_headers, code, response = api_.get_feature( + rsp_headers, code, response = api_.get_collection_item( req_headers, {'f': 'html'}, 'obs', '371') assert rsp_headers['Content-Type'] == 'text/html' - rsp_headers, code, response = api_.get_feature( + rsp_headers, code, response = api_.get_collection_item( req_headers, {}, 'obs', '371') features = json.loads(response)