Skip to content

Commit 0081549

Browse files
Fix admin with empty resources (#2208)
* Fix admin with empty resources * Update test_openapi.py * fix flake8 --------- Co-authored-by: Tom Kralidis <tomkralidis@gmail.com>
1 parent 734dabe commit 0081549

File tree

3 files changed

+141
-3
lines changed

3 files changed

+141
-3
lines changed

pygeoapi/openapi.py

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -731,10 +731,32 @@ def get_admin(cfg: dict) -> dict:
731731
schema_dict = get_config_schema()
732732

733733
paths = {}
734-
735-
res_eg_key = next(iter(cfg['resources']))
734+
if cfg['resources']:
735+
res_eg_key = next(iter(cfg['resources']))
736+
else:
737+
res_eg_key = 'example'
736738
res_eg = {
737739
res_eg_key: cfg['resources'][res_eg_key]
740+
} if cfg['resources'] else {
741+
'example': {
742+
'type': 'collection',
743+
'title': 'Example',
744+
'description': 'Example',
745+
'keywords': ['example'],
746+
'links': [],
747+
'linked-data': {},
748+
'extents': {
749+
'spatial': {
750+
'bbox': [-180, -90, 180, 90],
751+
'crs': 'http://www.opengis.net/def/crs/OGC/1.3/CRS84'
752+
},
753+
'temporal': {
754+
'begin': '2000-10-30T18:24:39Z',
755+
'end': '2007-10-30T08:57:29Z',
756+
'trs': 'http://www.opengis.net/def/uom/ISO-8601/0/Gregorian' # noqa
757+
}
758+
}
759+
}
738760
}
739761
if 'extents' in res_eg[res_eg_key]:
740762
res_eg_eg_key = 'extents'
@@ -839,7 +861,7 @@ def get_admin(cfg: dict) -> dict:
839861
'description': 'Adds resource to configuration',
840862
'content': {
841863
'application/json': {
842-
'example': {'new-collection': cfg['resources'][res_eg_key]}, # noqa
864+
'example': {'new-collection': cfg['resources'][res_eg_key] if cfg['resources'] else res_eg['example'] }, # noqa
843865
'schema': schema_dict['properties']['resources']['patternProperties']['^.*$'] # noqa
844866
}
845867
},

tests/other/test_openapi.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ def config():
4343
return yaml_load(fh)
4444

4545

46+
@pytest.fixture()
47+
def config_admin_empty_resources():
48+
with open(
49+
get_test_file_path('pygeoapi-test-config-admin-empty-resources.yml')
50+
) as fh:
51+
return yaml_load(fh)
52+
53+
4654
@pytest.fixture()
4755
def config_hidden_resources():
4856
filename = 'pygeoapi-test-config-hidden-resources.yml'
@@ -131,3 +139,8 @@ def test_hidden_resources(config_hidden_resources):
131139

132140
assert '/collections/obs' not in openapi_doc['paths']
133141
assert '/collections/obs/items' not in openapi_doc['paths']
142+
143+
144+
def test_admin_empty_resources(config_admin_empty_resources):
145+
openapi_doc = get_oas(config_admin_empty_resources)
146+
assert '/admin/config' in openapi_doc['paths']
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# =================================================================
2+
#
3+
# Authors: Tom Kralidis <tomkralidis@gmail.com>
4+
#
5+
# Copyright (c) 2019 Tom Kralidis
6+
#
7+
# Permission is hereby granted, free of charge, to any person
8+
# obtaining a copy of this software and associated documentation
9+
# files (the "Software"), to deal in the Software without
10+
# restriction, including without limitation the rights to use,
11+
# copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
# copies of the Software, and to permit persons to whom the
13+
# Software is furnished to do so, subject to the following
14+
# conditions:
15+
#
16+
# The above copyright notice and this permission notice shall be
17+
# included in all copies or substantial portions of the Software.
18+
#
19+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
21+
# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
23+
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
24+
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25+
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
26+
# OTHER DEALINGS IN THE SOFTWARE.
27+
#
28+
# =================================================================
29+
30+
server:
31+
bind:
32+
host: 0.0.0.0
33+
port: 5000
34+
url: http://localhost:5000/
35+
mimetype: application/json; charset=UTF-8
36+
encoding: utf-8
37+
gzip: false
38+
languages:
39+
# First language is the default language
40+
- en-US
41+
- fr-CA
42+
cors: true
43+
pretty_print: true
44+
limits:
45+
default_items: 10
46+
max_items: 10
47+
# templates: /path/to/templates
48+
map:
49+
url: https://tile.openstreetmap.org/{z}/{x}/{y}.png
50+
attribution: '&copy; <a href="https://openstreetmap.org/copyright">OpenStreetMap contributors</a>'
51+
manager:
52+
name: TinyDB
53+
connection: /tmp/pygeoapi-test-process-manager.db
54+
output_dir: /tmp
55+
admin: true
56+
57+
logging:
58+
level: DEBUG
59+
#logfile: /tmp/pygeoapi.log
60+
61+
metadata:
62+
identification:
63+
title:
64+
en: pygeoapi default instance
65+
fr: instance par défaut de pygeoapi
66+
description:
67+
en: pygeoapi provides an API to geospatial data
68+
fr: pygeoapi fournit une API aux données géospatiales
69+
keywords:
70+
en:
71+
- geospatial
72+
- data
73+
- api
74+
fr:
75+
- géospatiale
76+
- données
77+
- api
78+
keywords_type: theme
79+
terms_of_service: https://creativecommons.org/licenses/by/4.0/
80+
url: http://example.org
81+
license:
82+
name: CC-BY 4.0 license
83+
url: https://creativecommons.org/licenses/by/4.0/
84+
provider:
85+
name: Organization Name
86+
url: https://pygeoapi.io
87+
contact:
88+
name: Lastname, Firstname
89+
position: Position Title
90+
address: Mailing Address
91+
city: City
92+
stateorprovince: Administrative Area
93+
postalcode: Zip or Postal Code
94+
country: Country
95+
phone: +xx-xxx-xxx-xxxx
96+
fax: +xx-xxx-xxx-xxxx
97+
email: you@example.org
98+
url: Contact URL
99+
hours: Hours of Service
100+
instructions: During hours of service. Off on weekends.
101+
role: pointOfContact
102+
103+
resources: {}

0 commit comments

Comments
 (0)