@@ -81,6 +81,7 @@ def generate_operation_id(*, path: str, method: str) -> str:
8181 return f"{ method } _{ clean_path } "
8282
8383
84+ # pylint: disable=too-many-instance-attributes
8485@dataclass
8586class Endpoint :
8687 """
@@ -244,10 +245,32 @@ def _add_responses(
244245 endpoint .responses .append (response )
245246 return endpoint , schemas
246247
248+ # pylint: disable=too-many-return-statements
247249 @staticmethod
248250 def add_parameters (
249251 * , endpoint : "Endpoint" , data : Union [oai .Operation , oai .PathItem ], schemas : Schemas , config : Config
250252 ) -> Tuple [Union ["Endpoint" , ParseError ], Schemas ]:
253+ """Process the defined `parameters` for an Endpoint.
254+
255+ Any existing parameters will be ignored, so earlier instances of a parameter take precedence. PathItem
256+ parameters should therefore be added __after__ operation parameters.
257+
258+ Args:
259+ endpoint: The endpoint to add parameters to.
260+ data: The Operation or PathItem to add parameters from.
261+ schemas: The cumulative Schemas of processing so far which should contain details for any references.
262+ config: User-provided config for overrides within parameters.
263+
264+ Returns:
265+ `(result, schemas)` where `result` is either an updated Endpoint containing the parameters or a ParseError
266+ describing what went wrong. `schemas` is an updated version of the `schemas` input, adding any new enums
267+ or classes.
268+
269+ See Also:
270+ - https://swagger.io/docs/specification/describing-parameters/
271+ - https://swagger.io/docs/specification/paths-and-operations/
272+ """
273+
251274 endpoint = deepcopy (endpoint )
252275 if data .parameters is None :
253276 return endpoint , schemas
@@ -329,6 +352,16 @@ def add_parameters(
329352
330353 @staticmethod
331354 def sort_parameters (* , endpoint : "Endpoint" ) -> Union ["Endpoint" , ParseError ]:
355+ """
356+ Sorts the path parameters of an `endpoint` so that they match the order declared in `endpoint.path`.
357+
358+ Args:
359+ endpoint: The endpoint to sort the parameters of.
360+
361+ Returns:
362+ Either an updated `endpoint` with sorted path parameters or a `ParseError` if something was wrong with
363+ the path parameters and they could not be sorted.
364+ """
332365 endpoint = deepcopy (endpoint )
333366 parameters_from_path = re .findall (_PATH_PARAM_REGEX , endpoint .path )
334367 try :
@@ -338,8 +371,8 @@ def sort_parameters(*, endpoint: "Endpoint") -> Union["Endpoint", ParseError]:
338371 endpoint .path_parameters = OrderedDict ((param .name , param ) for param in sorted_params )
339372 except ValueError :
340373 pass # We're going to catch the difference down below
341- path_parameter_names = [ name for name in endpoint . path_parameters ]
342- if parameters_from_path != path_parameter_names :
374+
375+ if parameters_from_path != list ( endpoint . path_parameters ) :
343376 return ParseError (
344377 detail = f"Incorrect path templating for { endpoint .path } (Path parameters do not match with path)" ,
345378 )
@@ -397,22 +430,17 @@ class GeneratorData:
397430 enums : Iterator [EnumProperty ]
398431
399432 @staticmethod
400- def from_dict (d : Dict [str , Any ], * , config : Config ) -> Union ["GeneratorData" , GeneratorError ]:
433+ def from_dict (data : Dict [str , Any ], * , config : Config ) -> Union ["GeneratorData" , GeneratorError ]:
401434 """Create an OpenAPI from dict"""
402435 try :
403- openapi = oai .OpenAPI .parse_obj (d )
404- except ValidationError as e :
405- detail = str (e )
406- if "swagger" in d :
436+ openapi = oai .OpenAPI .parse_obj (data )
437+ except ValidationError as err :
438+ detail = str (err )
439+ if "swagger" in data :
407440 detail = (
408441 "You may be trying to use a Swagger document; this is not supported by this project.\n \n " + detail
409442 )
410443 return GeneratorError (header = "Failed to parse OpenAPI document" , detail = detail )
411- if openapi .openapi .major != 3 :
412- return GeneratorError (
413- header = "openapi-python-client only supports OpenAPI 3.x" ,
414- detail = f"The version of the provided document was { openapi .openapi } " ,
415- )
416444 schemas = Schemas ()
417445 if openapi .components and openapi .components .schemas :
418446 schemas = build_schemas (components = openapi .components .schemas , schemas = schemas , config = config )
0 commit comments