From 2af77a2dceee18f8c85c668ba6ce76d3a3f3ef11 Mon Sep 17 00:00:00 2001 From: Tom Kralidis Date: Fri, 24 Jul 2020 21:01:01 -0400 Subject: [PATCH] only show STAC and OAProc endpoints if configured (#497) --- pygeoapi/api.py | 13 ++++++++ pygeoapi/openapi.py | 57 +++++++++++++++++++----------------- pygeoapi/templates/root.html | 4 +++ 3 files changed, 47 insertions(+), 27 deletions(-) diff --git a/pygeoapi/api.py b/pygeoapi/api.py index 3cc9986..43dde7f 100644 --- a/pygeoapi/api.py +++ b/pygeoapi/api.py @@ -185,6 +185,18 @@ class API: if format_ == 'html': # render headers_['Content-Type'] = 'text/html' + + fcm['processes'] = False + fcm['stac'] = False + + if filter_dict_by_key_value(self.config['resources'], + 'type', 'process'): + fcm['processes'] = True + + if filter_dict_by_key_value(self.config['resources'], + 'type', 'stac-collection'): + fcm['stac'] = True + content = render_j2_template(self.config, 'root.html', fcm) return headers_, 200, content @@ -1168,6 +1180,7 @@ class API: 'id': id_, 'stac_version': stac_version, 'description': description, + 'extent': stac_collections[dataset]['extents'], 'links': [] } try: diff --git a/pygeoapi/openapi.py b/pygeoapi/openapi.py index d54c174..8ce6d81 100644 --- a/pygeoapi/openapi.py +++ b/pygeoapi/openapi.py @@ -492,40 +492,43 @@ def get_oas_30(cfg): } LOGGER.debug('setting up STAC') - paths['/stac'] = { - 'get': { - 'summary': 'SpatioTemporal Asset Catalog', - 'description': 'SpatioTemporal Asset Catalog', - 'tags': ['stac'], - 'operationId': 'getStacCatalog', - 'parameters': [], - 'responses': { - '200': {'$ref': '#/components/responses/200'}, - 'default': {'$ref': '#/components/responses/default'} + stac_collections = filter_dict_by_key_value(cfg['resources'], + 'type', 'stac-collection') + if stac_collections: + paths['/stac'] = { + 'get': { + 'summary': 'SpatioTemporal Asset Catalog', + 'description': 'SpatioTemporal Asset Catalog', + 'tags': ['stac'], + 'operationId': 'getStacCatalog', + 'parameters': [], + 'responses': { + '200': {'$ref': '#/components/responses/200'}, + 'default': {'$ref': '#/components/responses/default'} + } } } - } LOGGER.debug('setting up processes') - paths['/processes'] = { - 'get': { - 'summary': 'Processes', - 'description': 'Processes', - 'tags': ['server'], - 'operationId': 'getProcesses', - 'parameters': [ - {'$ref': '#/components/parameters/f'} - ], - 'responses': { - '200': {'$ref': '{}/responses/ProcessList.yaml'.format(OPENAPI_YAML['oapip'])}, # noqa - 'default': {'$ref': '#/components/responses/default'} - } - } - } - processes = filter_dict_by_key_value(cfg['resources'], 'type', 'process') if processes: + paths['/processes'] = { + 'get': { + 'summary': 'Processes', + 'description': 'Processes', + 'tags': ['server'], + 'operationId': 'getProcesses', + 'parameters': [ + {'$ref': '#/components/parameters/f'} + ], + 'responses': { + '200': {'$ref': '{}/responses/ProcessList.yaml'.format(OPENAPI_YAML['oapip'])}, # noqa + 'default': {'$ref': '#/components/responses/default'} + } + } + } + for k, v in processes.items(): p = load_plugin('process', v['processor']) diff --git a/pygeoapi/templates/root.html b/pygeoapi/templates/root.html index 3cafb3c..bd0f7d4 100644 --- a/pygeoapi/templates/root.html +++ b/pygeoapi/templates/root.html @@ -50,18 +50,22 @@ View the collections in this service

+ {% if data['stac'] %}

SpatioTemporal Assets

View the SpatioTemporal Assets in this service

+ {% endif %} + {% if data['processes'] %}

Processes

View the processes in this service

+ {% endif %}

API Definition