diff --git a/pygeoapi/api.py b/pygeoapi/api.py index ce5724b..fcf21c5 100644 --- a/pygeoapi/api.py +++ b/pygeoapi/api.py @@ -131,7 +131,7 @@ class API(object): return headers_, 200, json.dumps(fcm) - def api(self, headers, args, openapi): + def api(self, headers, args, request_path, openapi): """ Provide OpenAPI document @@ -143,6 +143,16 @@ class API(object): """ headers_ = HEADERS.copy() + format_ = check_format(args, headers) + + if format_ == 'html': + data = { + 'openapi-document-path': request_path + } + headers_['Content-Type'] = 'text/html' + content = _render_j2_template(self.config, 'api.html', data) + return headers_, 200, content + headers_['Content-Type'] = 'application/openapi+json;version=3.0' return headers_, 200, json.dumps(openapi) diff --git a/pygeoapi/flask_app.py b/pygeoapi/flask_app.py index ef298aa..a857fbe 100644 --- a/pygeoapi/flask_app.py +++ b/pygeoapi/flask_app.py @@ -68,7 +68,7 @@ def api(): openapi = yaml.load(ff) headers, status_code, content = api_.api(request.headers, request.args, - openapi) + request.path, openapi) response = make_response(content, status_code) if headers: diff --git a/pygeoapi/templates/api.html b/pygeoapi/templates/api.html new file mode 100644 index 0000000..a50fc06 --- /dev/null +++ b/pygeoapi/templates/api.html @@ -0,0 +1,22 @@ + + +
+ + + + + + + + diff --git a/tests/test_api.py b/tests/test_api.py index 1cc87f0..542c9b8 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -73,12 +73,18 @@ def test_api(config, api_, openapi, headers): assert api_.config == config assert isinstance(api_.config, dict) - headers_, code, response = api_.api(headers, {}, openapi) + headers['Content-Type'] = 'application/json' + headers_, code, response = api_.api(headers, {}, '/api', openapi) assert headers_['Content-Type'] == 'application/openapi+json;version=3.0' root = json.loads(response) assert isinstance(root, dict) + a = 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' + headers['Accept'] = a + headers_, code, response = api_.api(headers, {}, '/api', openapi) + assert headers_['Content-Type'] == 'text/html' + def test_api_exception(config, api_, headers): headers_, code, response = api_.root(headers, {'f': 'foo'})