35
35
#
36
36
# =================================================================
37
37
38
-
38
+ from collections import ChainMap
39
39
from copy import deepcopy
40
40
from datetime import datetime
41
41
from http import HTTPStatus
@@ -1101,6 +1101,21 @@ def get_oas_30(cfg: dict, locale: str) -> tuple[list[dict[str, str]], dict[str,
1101
1101
}
1102
1102
}
1103
1103
1104
+ limit = {
1105
+ 'name' : 'limit' ,
1106
+ 'in' : 'query' ,
1107
+ 'description' : 'The optional limit parameter limits the number of items that are presented in the response document' , # noqa
1108
+ 'required' : False ,
1109
+ 'schema' : {
1110
+ 'type' : 'integer' ,
1111
+ 'minimum' : 1 ,
1112
+ 'maximum' : 10000 ,
1113
+ 'default' : 100
1114
+ },
1115
+ 'style' : 'form' ,
1116
+ 'explode' : False
1117
+ }
1118
+
1104
1119
profile = {
1105
1120
'name' : 'profile' ,
1106
1121
'in' : 'query' ,
@@ -1144,6 +1159,11 @@ def get_oas_30(cfg: dict, locale: str) -> tuple[list[dict[str, str]], dict[str,
1144
1159
1145
1160
coll_properties ['schema' ]['items' ]['enum' ] = list (p .fields .keys ())
1146
1161
1162
+ coll_limit = _derive_limit (
1163
+ deepcopy (limit ), cfg ['server' ].get ('limits' , {}),
1164
+ v .get ('limits' , {})
1165
+ )
1166
+
1147
1167
paths [items_path ] = {
1148
1168
'get' : {
1149
1169
'summary' : f'Get { title } items' ,
@@ -1154,7 +1174,7 @@ def get_oas_30(cfg: dict, locale: str) -> tuple[list[dict[str, str]], dict[str,
1154
1174
{'$ref' : '#/components/parameters/f' },
1155
1175
{'$ref' : '#/components/parameters/lang' },
1156
1176
{'$ref' : '#/components/parameters/bbox' },
1157
- { '$ref' : f" { OPENAPI_YAML [ 'oapif-1' ] } #/components/parameters/limit" }, # noqa
1177
+ coll_limit ,
1158
1178
{'$ref' : '#/components/parameters/crs' }, # noqa
1159
1179
{'$ref' : '#/components/parameters/bbox-crs' },
1160
1180
coll_properties ,
@@ -1405,3 +1425,28 @@ def get_oas_30(cfg: dict, locale: str) -> tuple[list[dict[str, str]], dict[str,
1405
1425
LOGGER .debug ('collection is not feature/item based' )
1406
1426
1407
1427
return [{'name' : 'records' }, {'name' : 'features' }], {'paths' : paths }
1428
+
1429
+
1430
+ def _derive_limit (limit_object , server_limits , collection_limits ) -> dict :
1431
+ """
1432
+ Helper function to derive a limit object for a given collection
1433
+
1434
+ :param limit_object: OpenAPI limit parameter
1435
+ :param server_limits: server level limits configuration
1436
+ :param collection_limits: collection level limits configuration
1437
+
1438
+ :returns: updated limit object
1439
+ """
1440
+
1441
+ effective_limits = ChainMap (collection_limits , server_limits )
1442
+
1443
+ default_limit = effective_limits .get ('default_items' , 10 )
1444
+ max_limit = effective_limits .get ('max_items' , 10 )
1445
+
1446
+ limit_object ['schema' ]['default' ] = default_limit
1447
+ limit_object ['schema' ]['maximum' ] = max_limit
1448
+
1449
+ text = f' (maximum={ max_limit } , default={ default_limit } ).'
1450
+ limit_object ['description' ] += text
1451
+
1452
+ return limit_object
0 commit comments