Skip to content

Commit 2388937

Browse files
committed
Set default limit on /access/ to max limit when no pagination limit supplied
In a recent (PR)[RedHatInsights#195] we removed the default limit on the `/access/` endpoint, to ensure all records were returned in a single request instead of using the default of 10. This meant in order to be backwards compatible, we'd also need to continue supporting pagination params. To do this, we updated the spec to include `oneOf` two possible valid responses, one paginated and one unpaginated. The `data` would remain the same, but the meta data for pagination would not be included unless a `limit` param was supplied in the request. The associated updates were made to the `openapi.json` spec, but due to an existing bug/issue in the OpenAPI Generator project [1,2], this breaks some client generation which is used by app teams and QE, even though it's valid per the spec. In order to avoid having a separate endpoint explicitly for a paginated responses, and to also avoid constructing false meta data for pagination, we've decided to set the default limit on the `/access/` endpoint equal to the max limit number when no `limit` is supplied, but continue to respect the `limit` pagination param when it is supplied. This will allow for client generation to continue to work, and will allow those using pagination by default to still be supported. For those not using pagination, the response `data` should again still be the same, and the default limit will not be a barrier to hitting pagination, as it will be the same as our max results. [1] OpenAPITools/openapi-generator#15 [2] OpenAPITools/openapi-generator#1709
1 parent 36c19e4 commit 2388937

File tree

3 files changed

+6
-84
lines changed

3 files changed

+6
-84
lines changed

docs/source/specs/openapi.json

Lines changed: 3 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1518,34 +1518,19 @@
15181518
}
15191519
},
15201520
{
1521-
"$ref": "#/components/parameters/QueryLimitNoDefault"
1521+
"$ref": "#/components/parameters/QueryLimit"
15221522
},
15231523
{
15241524
"$ref": "#/components/parameters/QueryOffset"
15251525
}
15261526
],
15271527
"responses": {
15281528
"200": {
1529-
"description": "A list of access objects. By default, this request will not be paginated. To received a paginated response, include the `/?limit=` query parameter.",
1529+
"description": "A paginated list of access objects",
15301530
"content": {
15311531
"application/json": {
15321532
"schema": {
1533-
"oneOf": [
1534-
{
1535-
"$ref": "#/components/schemas/AccessNoPagination"
1536-
},
1537-
{
1538-
"$ref": "#/components/schemas/AccessPagination"
1539-
}
1540-
]
1541-
},
1542-
"examples": {
1543-
"AccessNoPagination": {
1544-
"$ref": "#/components/examples/AccessNoPagination"
1545-
},
1546-
"AccessPagination": {
1547-
"$ref": "#/components/examples/AccessPagination"
1548-
}
1533+
"$ref": "#/components/schemas/AccessPagination"
15491534
}
15501535
}
15511536
}
@@ -1607,17 +1592,6 @@
16071592
"maximum": 1000
16081593
}
16091594
},
1610-
"QueryLimitNoDefault": {
1611-
"in": "query",
1612-
"name": "limit",
1613-
"required": false,
1614-
"description": "Parameter for selecting the amount of data returned.",
1615-
"schema": {
1616-
"type": "integer",
1617-
"minimum": 1,
1618-
"maximum": 1000
1619-
}
1620-
},
16211595
"NameFilter": {
16221596
"in": "query",
16231597
"name": "name",
@@ -2345,24 +2319,6 @@
23452319
}
23462320
]
23472321
},
2348-
"AccessNoPagination": {
2349-
"allOf": [
2350-
{
2351-
"type": "object",
2352-
"required": [
2353-
"data"
2354-
],
2355-
"properties": {
2356-
"data": {
2357-
"type": "array",
2358-
"items": {
2359-
"$ref": "#/components/schemas/Access"
2360-
}
2361-
}
2362-
}
2363-
}
2364-
]
2365-
},
23662322
"Status": {
23672323
"required": [
23682324
"api_version"
@@ -2414,39 +2370,6 @@
24142370
}
24152371
}
24162372
}
2417-
},
2418-
"examples": {
2419-
"AccessNoPagination": {
2420-
"value": {
2421-
"data": [
2422-
{
2423-
"permission": "app-name:*:*",
2424-
"resourceDefinitions": []
2425-
}
2426-
]
2427-
}
2428-
},
2429-
"AccessPagination": {
2430-
"value": {
2431-
"meta": {
2432-
"count": 1,
2433-
"limit": 10,
2434-
"offset": 0
2435-
},
2436-
"links": {
2437-
"first": "/access/?application=app-name&limit=10",
2438-
"next": null,
2439-
"previous": null,
2440-
"last": "/access/?application=app-name&limit=10"
2441-
},
2442-
"data": [
2443-
{
2444-
"permission": "app-name:*:*",
2445-
"resourceDefinitions": []
2446-
}
2447-
]
2448-
}
2449-
}
24502373
}
24512374
}
24522375
}

rbac/management/access/view.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,9 @@ def get(self, request):
9494
def paginator(self):
9595
"""Return the paginator instance associated with the view, or `None`."""
9696
if not hasattr(self, '_paginator'):
97+
self._paginator = self.pagination_class()
9798
if self.pagination_class is None or 'limit' not in self.request.query_params:
98-
self._paginator = None
99-
else:
100-
self._paginator = self.pagination_class()
99+
self._paginator.default_limit = self._paginator.max_limit
101100
return self._paginator
102101

103102
def paginate_queryset(self, queryset):

tests/management/access/test_view.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def test_get_access_success(self):
123123
self.assertIsNotNone(response.data.get('data'))
124124
self.assertIsInstance(response.data.get('data'), list)
125125
self.assertEqual(len(response.data.get('data')), 1)
126-
self.assertIsNone(response.data.get('meta'))
126+
self.assertEqual(response.data.get('meta').get('limit'), 1000)
127127
self.assertEqual(self.access_data, response.data.get('data')[0])
128128

129129
def test_get_access_with_limit(self):

0 commit comments

Comments
 (0)