Skip to content

Commit caafad4

Browse files
authored
Added payload examples and other default values in the Open API definition of the admin API (geopython#1878)
* - Added example payload in the Open API definition of the admin API * - fixed flake8 error * - removed test on extents key, when creating admin patch payload example * - added obs collection in pygeoapi config test admin * - switched order of obs collection in resources * - simplify payload example for admin api post resource * - removed processes collection from test admin configuration files
1 parent c91719e commit caafad4

File tree

3 files changed

+121
-11
lines changed

3 files changed

+121
-11
lines changed

pygeoapi/openapi.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -552,13 +552,14 @@ def get_oas_30(cfg: dict, fail_on_invalid_collection: bool = True) -> dict:
552552
schema_dict = get_config_schema()
553553
oas['definitions'] = schema_dict['definitions']
554554
LOGGER.debug('Adding admin endpoints')
555-
oas['paths'].update(get_admin())
555+
oas['paths'].update(get_admin(cfg))
556556

557557
return oas
558558

559559

560560
def get_oas_30_parameters(cfg: dict, locale_: str):
561561
server_locales = l10n.get_locales(cfg)
562+
562563
return {
563564
'f': {
564565
'name': 'f',
@@ -684,7 +685,8 @@ def get_oas_30_parameters(cfg: dict, locale_: str):
684685
'description': 'Configuration resource identifier',
685686
'required': True,
686687
'schema': {
687-
'type': 'string'
688+
'type': 'string',
689+
'default': list(cfg['resources'].keys())[0]
688690
}
689691
}
690692
}
@@ -709,12 +711,17 @@ def get_config_schema():
709711
return yaml_load(fh2)
710712

711713

712-
def get_admin():
714+
def get_admin(cfg: dict) -> dict:
713715

714716
schema_dict = get_config_schema()
715717

716718
paths = {}
717719

720+
res_eg_key = next(iter(cfg['resources']))
721+
res_eg = {
722+
res_eg_key: cfg['resources'][res_eg_key]
723+
}
724+
718725
paths['/admin/config'] = {
719726
'get': {
720727
'summary': 'Get admin configuration',
@@ -745,6 +752,7 @@ def get_admin():
745752
'description': 'Updates admin configuration',
746753
'content': {
747754
'application/json': {
755+
'example': cfg,
748756
'schema': schema_dict
749757
}
750758
},
@@ -765,6 +773,7 @@ def get_admin():
765773
'description': 'Updates admin configuration',
766774
'content': {
767775
'application/json': {
776+
'example': {'metadata': cfg['metadata']},
768777
'schema': schema_dict
769778
}
770779
},
@@ -807,6 +816,7 @@ def get_admin():
807816
'description': 'Adds resource to configuration',
808817
'content': {
809818
'application/json': {
819+
'example': {'new-collection': cfg['resources'][res_eg_key]}, # noqa
810820
'schema': schema_dict['properties']['resources']['patternProperties']['^.*$'] # noqa
811821
}
812822
},
@@ -853,6 +863,7 @@ def get_admin():
853863
'description': 'Updates admin configuration resource',
854864
'content': {
855865
'application/json': {
866+
'example': res_eg[res_eg_key],
856867
'schema': schema_dict['properties']['resources']['patternProperties']['^.*$'] # noqa
857868
}
858869
},
@@ -876,6 +887,7 @@ def get_admin():
876887
'description': 'Updates admin configuration resource',
877888
'content': {
878889
'application/json': {
890+
'example': {'extents': res_eg[res_eg_key]['extents']},
879891
'schema': schema_dict['properties']['resources']['patternProperties']['^.*$'] # noqa
880892
}
881893
},

tests/data/admin/admin-put.json

Lines changed: 63 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,71 @@
6161
}
6262
},
6363
"resources": {
64-
"hello-world": {
65-
"type": "process",
66-
"processor": {
67-
"name": "HelloWorld"
64+
65+
"obs": {
66+
"type": "collection",
67+
"title": "Observations",
68+
"description": "My cool observations",
69+
"keywords": [
70+
"observations",
71+
"monitoring"
72+
],
73+
"linked-data": {
74+
"context": [
75+
{
76+
"datetime": "https://schema.org/DateTime"
77+
},
78+
{
79+
"vocab": "https://example.com/vocab#",
80+
"stn_id": "vocab:stn_id",
81+
"value": "vocab:value"
6882
}
83+
]
84+
},
85+
"links": [
86+
{
87+
"type": "text/csv",
88+
"rel": "canonical",
89+
"title": "data",
90+
"href": "https://github.com/mapserver/mapserver/blob/branch-7-0/msautotest/wxs/data/obs.csv",
91+
"hreflang": "en-US"
92+
},
93+
{
94+
"type": "text/csv",
95+
"rel": "alternate",
96+
"title": "data",
97+
"href": "https://raw.githubusercontent.com/mapserver/mapserver/branch-7-0/msautotest/wxs/data/obs.csv",
98+
"hreflang": "en-US"
99+
}
100+
],
101+
"extents": {
102+
"spatial": {
103+
"bbox": [
104+
-180,
105+
-90,
106+
180,
107+
90
108+
],
109+
"crs": "http://www.opengis.net/def/crs/OGC/1.3/CRS84"
110+
},
111+
"temporal": {
112+
"begin": "2000-10-30T18:24:39+00:00",
113+
"end": "2007-10-30T08:57:29+00:00"
69114
}
115+
},
116+
"providers": [
117+
{
118+
"type": "feature",
119+
"name": "CSV",
120+
"data": "tests/data/obs.csv",
121+
"id_field": "id",
122+
"geometry": {
123+
"x_field": "long",
124+
"y_field": "lat"
125+
}
126+
}
127+
]
128+
}
70129
}
71130
}
72131

tests/pygeoapi-test-config-admin.yml

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,46 @@ metadata:
9393
role: pointOfContact
9494

9595
resources:
96-
hello-world:
97-
type: process
98-
processor:
99-
name: HelloWorld
96+
obs:
97+
type: collection
98+
title: Observations
99+
description: My cool observations
100+
keywords:
101+
- observations
102+
- monitoring
103+
linked-data:
104+
context:
105+
- datetime: https://schema.org/DateTime
106+
- vocab: https://example.com/vocab#
107+
stn_id: vocab:stn_id
108+
value: vocab:value
109+
links:
110+
- type: text/csv
111+
rel: canonical
112+
title: data
113+
href: https://github.com/mapserver/mapserver/blob/branch-7-0/msautotest/wxs/data/obs.csv
114+
hreflang: en-US
115+
- type: text/csv
116+
rel: alternate
117+
title: data
118+
href: https://raw.githubusercontent.com/mapserver/mapserver/branch-7-0/msautotest/wxs/data/obs.csv
119+
hreflang: en-US
120+
extents:
121+
spatial:
122+
bbox:
123+
- -180
124+
- -90
125+
- 180
126+
- 90
127+
crs: http://www.opengis.net/def/crs/OGC/1.3/CRS84
128+
temporal:
129+
begin: 2000-10-30 18:24:39+00:00
130+
end: 2007-10-30 08:57:29+00:00
131+
providers:
132+
- type: feature
133+
name: CSV
134+
data: tests/data/obs.csv
135+
id_field: id
136+
geometry:
137+
x_field: long
138+
y_field: lat

0 commit comments

Comments
 (0)