From 76269d0283f0fdde05265e0466031fe8c550280c Mon Sep 17 00:00:00 2001 From: Artem Goncharov Date: Thu, 22 Aug 2024 10:18:01 +0200 Subject: [PATCH] Add neutron pagination and sort query parameters Pagination and sorting is implemented deep inside neutron and is not directly visible on the resource schemas. Add those by default to every indexing method (except of extensions where it is known to be ignored). Change-Id: Ia8055d1edd08581193f2e722f911a50f6a3c63d3 --- codegenerator/openapi/neutron.py | 56 ++++++++++++++++++++++++++++++-- 1 file changed, 54 insertions(+), 2 deletions(-) diff --git a/codegenerator/openapi/neutron.py b/codegenerator/openapi/neutron.py index b9ec378..5b473a4 100644 --- a/codegenerator/openapi/neutron.py +++ b/codegenerator/openapi/neutron.py @@ -281,7 +281,40 @@ class NeutronGenerator(OpenStackServerSourceBase): } }, headers={}, - parameters={}, + parameters={ + "limit": ParameterSchema( + name="limit", + location="query", + description="Requests a page size of items. Returns a number of items up to a limit value. Use the limit parameter to make an initial limited request and use the ID of the last-seen item from the response as the marker parameter value in a subsequent limited request.", + type_schema=TypeSchema(type="integer", minimum=0), + ), + "marker": ParameterSchema( + name="marker", + location="query", + description="The ID of the last-seen item. Use the limit parameter to make an initial limited request and use the ID of the last-seen item from the response as the marker parameter value in a subsequent limited request.", + type_schema=TypeSchema(type="string"), + ), + "page_reverse": ParameterSchema( + name="page_reverse", + location="query", + description="Reverse the page direction", + type_schema=TypeSchema(type="boolean"), + ), + "sort_key": ParameterSchema( + name="sort_key", + location="query", + description="Sort results by the attribute. This is an optional feature and may be silently ignored by the server.", + type_schema=TypeSchema(type="string"), + ), + "sort_dir": ParameterSchema( + name="sort_dir", + location="query", + description="Sort direction. This is an optional feature and may be silently ignored by the server.", + type_schema=TypeSchema( + type="string", enum=["asc", "desc"] + ), + ), + }, schemas={}, ), ) @@ -724,7 +757,26 @@ class NeutronGenerator(OpenStackServerSourceBase): operation_spec.parameters.append( ParameterSchema(ref=param_ref_name) ) - + if path != "/v2.0/extensions" and collection not in ["extensions"]: + # All Neutron LIST operations support pagination and sorting (as + # much as possible). Sadly there is no preciese info whether + # certain operations do not support that so we add it everywhere + # by default. + operation_spec.parameters.append( + ParameterSchema(ref="#/components/parameters/sort_key") + ) + operation_spec.parameters.append( + ParameterSchema(ref="#/components/parameters/sort_dir") + ) + operation_spec.parameters.append( + ParameterSchema(ref="#/components/parameters/limit") + ) + operation_spec.parameters.append( + ParameterSchema(ref="#/components/parameters/marker") + ) + operation_spec.parameters.append( + ParameterSchema(ref="#/components/parameters/page_reverse") + ) responses_spec = operation_spec.responses if method == "DELETE": response_code = "204"