4545from openapi_python_generator .language_converters .python .model_generator import (
4646 type_converter ,
4747)
48- from openapi_python_generator .models import LibraryConfig , OpReturnType , Service , ServiceOperation , TypeConversion
48+ from openapi_python_generator .models import (
49+ LibraryConfig ,
50+ OpReturnType ,
51+ Service ,
52+ ServiceOperation ,
53+ TypeConversion ,
54+ )
4955
5056
5157# Helper functions for isinstance checks across OpenAPI versions
@@ -54,16 +60,18 @@ def is_response_type(obj) -> bool:
5460 return isinstance (obj , (Response30 , Response31 ))
5561
5662
57- def create_media_type_for_reference (reference_obj ):
63+ def create_media_type_for_reference (
64+ reference_obj : Response30 | Reference30 | Response31 | Reference31 ,
65+ ):
5866 """Create a MediaType wrapper for a reference object, using the correct version"""
5967 # Check which version the reference object belongs to
6068 if isinstance (reference_obj , Reference30 ):
61- return MediaType30 (schema = reference_obj )
69+ return MediaType30 (schema = reference_obj ) # type: ignore - pydantic issue with generics
6270 elif isinstance (reference_obj , Reference31 ):
63- return MediaType31 (schema = reference_obj )
71+ return MediaType31 (schema = reference_obj ) # type: ignore - pydantic issue with generics
6472 else :
6573 # Fallback to v3.0 for generic Reference
66- return MediaType30 (schema = reference_obj )
74+ return MediaType30 (schema = reference_obj ) # type: ignore - pydantic issue with generics
6775
6876
6977def is_media_type (obj ) -> bool :
@@ -185,13 +193,16 @@ def _generate_params_from_content(content: Any):
185193 if isinstance (rb_content , dict ) and any (
186194 rb_content .get (i ) is not None for i in operation_request_body_types
187195 ):
188- get_keyword = [i for i in operation_request_body_types if rb_content . get ( i )][
189- 0
190- ]
196+ get_keyword = [
197+ i for i in operation_request_body_types if rb_content . get ( i )
198+ ][ 0 ]
191199 content = rb_content .get (get_keyword )
192200 if content is not None and hasattr (content , "media_type_schema" ):
193201 mts = getattr (content , "media_type_schema" , None )
194- if isinstance (mts , (Reference , Reference30 , Reference31 , Schema , Schema30 , Schema31 )):
202+ if isinstance (
203+ mts ,
204+ (Reference , Reference30 , Reference31 , Schema , Schema30 , Schema31 ),
205+ ):
195206 params += f"{ _generate_params_from_content (mts )} , "
196207 else : # pragma: no cover
197208 raise Exception (
@@ -283,9 +294,8 @@ def generate_return_type(operation: Operation) -> OpReturnType:
283294 )
284295 elif is_schema_type (inner_schema ):
285296 converted_result = type_converter (inner_schema , True ) # type: ignore
286- if (
287- "array" in converted_result .original_type
288- and isinstance (converted_result .import_types , list )
297+ if "array" in converted_result .original_type and isinstance (
298+ converted_result .import_types , list
289299 ):
290300 matched = re .findall (r"List\[(.+)\]" , converted_result .converted_type )
291301 if len (matched ) > 0 :
@@ -348,23 +358,28 @@ def generate_service_operation(
348358 op .parameters = [] # type: ignore
349359 op .parameters .append (p ) # type: ignore
350360 except Exception : # pragma: no cover
351- print (f"Error merging path-level parameters for { path_name } " ) # pragma: no cover
361+ print (
362+ f"Error merging path-level parameters for { path_name } "
363+ ) # pragma: no cover
352364 pass
353365
354366 params = generate_params (op )
355367 # Fallback: ensure all {placeholders} in path are present as function params
356368 try :
357- placeholder_names = [m .group (1 ) for m in re .finditer (r"\{([^}/]+)\}" , path_name )]
369+ placeholder_names = [
370+ m .group (1 ) for m in re .finditer (r"\{([^}/]+)\}" , path_name )
371+ ]
358372 existing_param_names = {
359- p .split (":" )[0 ].strip ()
360- for p in params .split ("," ) if ":" in p
373+ p .split (":" )[0 ].strip () for p in params .split ("," ) if ":" in p
361374 }
362375 for ph in placeholder_names :
363376 norm_ph = common .normalize_symbol (ph )
364377 if norm_ph not in existing_param_names and norm_ph :
365378 params = f"{ norm_ph } : Any, " + params
366379 except Exception : # pragma: no cover
367- print (f"Error ensuring path placeholders in params for { path_name } " ) # pragma: no cover
380+ print (
381+ f"Error ensuring path placeholders in params for { path_name } "
382+ ) # pragma: no cover
368383 pass
369384 operation_id = generate_operation_id (op , http_operation , path_name )
370385 query_params = generate_query_params (op )
0 commit comments