23
23
build_schemas ,
24
24
property_from_data ,
25
25
)
26
- from .properties .schemas import parse_reference_path
26
+ from .properties .schemas import parameter_from_reference
27
27
from .responses import Response , response_from_data
28
28
29
29
_PATH_PARAM_REGEX = re .compile ("{([a-zA-Z_][a-zA-Z0-9_]*)}" )
@@ -293,6 +293,8 @@ def add_parameters(
293
293
- https://swagger.io/docs/specification/describing-parameters/
294
294
- https://swagger.io/docs/specification/paths-and-operations/
295
295
"""
296
+ # pylint: disable=too-many-branches, too-many-locals
297
+ # There isn't much value in breaking down this function further other than to satisfy the linter.
296
298
297
299
if data .parameters is None :
298
300
return endpoint , schemas , parameters
@@ -307,35 +309,32 @@ def add_parameters(
307
309
oai .ParameterLocation .COOKIE : endpoint .cookie_parameters ,
308
310
}
309
311
310
- for _param in data .parameters :
311
- param : oai .Parameter
312
+ for param in data .parameters :
313
+ # Obtain the parameter from the reference or just the parameter itself
314
+ param_or_error = parameter_from_reference (param = param , parameters = parameters )
315
+ if isinstance (param_or_error , ParseError ):
316
+ return param_or_error , schemas , parameters
317
+ param = param_or_error
312
318
313
- if _param is None :
314
- return ParseError (data = data , detail = "Null parameter provided." ), schemas , parameters
315
-
316
- if isinstance (_param , oai .Reference ):
317
- ref_path = parse_reference_path (_param .ref )
318
- if isinstance (ref_path , ParseError ):
319
- return ref_path , schemas , parameters
320
- _resolved_class = parameters .classes_by_reference .get (ref_path )
321
- if _resolved_class is None :
322
- return ParseError (data = data , detail = f"Reference `{ ref_path } ` not found." ), schemas , parameters
323
- param = _resolved_class
324
- elif isinstance (_param , oai .Parameter ):
325
- param = _param
319
+ if param .param_schema is None :
320
+ continue
326
321
327
322
unique_param = (param .name , param .param_in )
328
- if unique_param in unique_parameters :
329
- duplication_detail = (
330
- "Parameters MUST NOT contain duplicates. "
331
- "A unique parameter is defined by a combination of a name and location. "
332
- f"Duplicated parameters named `{ param .name } ` detected in `{ param .param_in } `."
323
+ if (param .name , param .param_in ) in unique_parameters :
324
+ return (
325
+ ParseError (
326
+ data = data ,
327
+ detail = (
328
+ "Parameters MUST NOT contain duplicates. "
329
+ "A unique parameter is defined by a combination of a name and location. "
330
+ f"Duplicated parameters named `{ param .name } ` detected in `{ param .param_in } `."
331
+ ),
332
+ ),
333
+ schemas ,
334
+ parameters ,
333
335
)
334
- return ParseError (data = data , detail = duplication_detail ), schemas , parameters
335
- unique_parameters .add (unique_param )
336
336
337
- if param .param_schema is None :
338
- continue
337
+ unique_parameters .add (unique_param )
339
338
340
339
prop , new_schemas = property_from_data (
341
340
name = param .name ,
0 commit comments