
    @ljr              !          U d dl Z d dlZd dlZd dlZd dlmZ d dlmZm	Z	 d dl
mZmZmZ d dlmZ d dlmZmZmZmZmZmZ d dlmZmZ d dlmZmZmZmZmZm Z  d d	l!m"Z"m#Z#m$Z$ d d
l%m&Z& d dl'm(Z( d dl)m*Z*m+Z+ d dl,m-Z- d dl.m/Z/m0Z0 d dl1m2Z2 d dl3m4Z4 d dl5m6Z6m7Z7 d dl8m9Z9m:Z:m;Z; d dl<m=Z= d dl>m?Z? d dl@mAZA dddddddiddigidddd d!dd d"d#id$dd d%g d&d'ZBd(dd)d*dd+e+dz   idid,ZCd-d.d/d0d1d2d3ZDeEeFeFf   eGd4<   e G d5 d6             ZHd7ed8eHfd9ZId:eJeKeeJeF   f      d8eKeEeFef   eJeEeFef      f   fd;ZLd<d=d>eHd?e7d@eEeKeedA   f   eEeFef   f   dBeMd8eJeEeFef      f
dCZNd<d=dDedz  d?e7d@eEeKeedA   f   eEeFef   f   dBeMd8eEeFef   dz  f
dEZOdFej                  dGeFd8eFfdHZQdFej                  dGeFd8eFfdIZRdFej                  dGeFdJeSeF   d8eEeFef   fdKZTd<d=dFej                  dJeSeF   d?e7d@eEeKeedA   f   eEeFef   f   dBeMd8eKeEeFef   eEeFef   eEeFef   f   fdLZUdMej                  d8ej                  dz  fdNZWdOeeAej                  z     d8eJe   fdPZXdQddddddddd<ddRd"eFdSeFdTeFdUeFdz  dVeFdz  dOeeAej                  z     dWeeAej                  z     dz  dXeJeEeFef      dz  dYeJeEeFeFez  f      dz  dZeFdz  d[eEeFeFez  f   dz  d\eEeFeFez  f   dz  dBeMd]eEeFef   dz  d8eEeFef   fd^ZYy)_    N)Sequence)	dataclassfield)AnyLiteralcast)routing)
ModelFieldget_definitionsget_flat_models_from_fieldsget_model_name_mapget_schema_from_model_fieldlenient_issubclass)DefaultPlaceholder_Unset)	Dependant_get_cache_key_get_oauth_scopes_get_security_scheme_is_security_scheme_UsesScopesCache)_get_flat_fields_from_paramsget_flat_paramsget_validation_alias)jsonable_encoder)FastAPIDeprecationWarning)METHODS_WITH_BODY
REF_PREFIX)OpenAPI)Body
ParamTypes)Response)_SSE_EVENT_SCHEMA)DependencyCacheKeyModelNameMap)deep_dict_updategenerate_operation_id_for_pathis_body_allowed_for_status_code)	BaseModel)JSONResponse)	BaseRouteValidationErrorobjectLocationarrayanyOftypestringinteger)titler1   itemsMessage)r4   r1   z
Error Typer4   InputContext)locmsgr1   inputctx)r9   r:   r1   )r4   r1   
propertiesrequiredHTTPValidationErrordetailDetail$ref)r4   r1   r=   InformationSuccessRedirectionzClient ErrorzServer ErrorzDefault Response)1XX2XX3XX4XX5XXDEFAULTstatus_code_rangesc                       e Zd ZU  ee      Zee   ed<    ee      Zee   ed<    ee      Z	ee   ed<    ee      Z
ee   ed<    ee      Zeeeee   f      ed<   y)_OpenAPIDependencyData)default_factorypath_paramsquery_paramsheader_paramscookie_paramssecurity_dependenciesN)__name__
__module____qualname__r   listrP   r
   __annotations__rQ   rR   rS   rT   tupler   str     H/root/.hermes/venv/lib/python3.12/site-packages/fastapi/openapi/utils.pyrN   rN   X   s{    $)$$?Kj!?%*4%@L$z"@&+D&AM4
#A&+D&AM4
#A?D@4ic&: ;< r]   rN   	dependantreturnc                   
 t               }g }i }| g dfg}|r^|j                         \  }}}t        ||      }||v r)|j                  |       |j                  j                  |j                         |j                  j                  |j                         |j                  j                  |j                         |j                  j                  |j                         |j                         
t        |      D ]  }	|	
vs
j                  |	        |s)t        |      r|j                  j                  |
f       |j                  
fdt        |j                        D               |r^|S )NT)r_   uses_scopes_cacher_   c              3   (   K   | ]	  }|d f  yw)FNr\   ).0sub_dependantoauth_scopess     r^   	<genexpr>z/_get_openapi_dependency_data.<locals>.<genexpr>}   s       
 L%0
s   )rN   popr   appendrP   extendrQ   rR   rS   copyr   r   rT   reverseddependencies)r_   dependency_datavisitedrb   
dependantscurrent_dependantparent_oauth_scopesis_root	cache_keyscoperg   s             @r^   _get_openapi_dependency_datarw   c   sk   ,.O(*G*,<Er4;P:QJ
:D..:J7."'/
	 y!##**+<+H+HI$$++,=,J,JK%%,,->-L-LM%%,,->-L-LM*//1&1BC 	+EL(##E*	+ .9JK1188"L1 	 
!)*;*H*H!I
 	
+ 2 r]   rT   c                 <   i }i }| D ]f  \  }}t        |      }t        |j                  dd      }|j                  }|||<   ||vrg ||<   |D ]  }|||   vs||   j	                  |         h |j                         D 	
cg c]	  \  }	}
|	|
i }}	}
||fS c c}
}	w )Nrc   Tby_aliasexclude_none)r   r   modelscheme_namerj   r5   )rT   security_definitionsoperation_security_dictsecurity_dependencyrg   security_schemesecurity_definitionsecurity_namerv   namescopesoperation_securitys               r^   !_get_openapi_security_definitionsr      s     46-B E)\.9LM.!!

 (33.A]+ 7757#M2! 	EE3MBB'6==eD	EE  ,C+H+H+J'4v   !333s   BT)separate_input_output_schemasro   model_name_mapfield_mapping)
validationserializationr   c                    g }t        | j                        }t        | j                        }t        | j                        }t        | j                        }t
        j                  |ft
        j                  |ft
        j                  |ft
        j                  |fg}	d}
t        | j                        dk(  rJ| j                  d   }t        |j                  j                  t              rt        |j                  dd      }
|	D ]B  \  }}|D ]6  }|j                  }t        |dd      st!        ||||      }t#        |      }t        |j                  d|
      }|t
        j                  k(  r-||j$                  k(  r|r|j$                  j'                  dd      }||j(                  |j                  j+                         |d	}|j,                  r|j,                  |d
<   t        |dd       }t        |dd       }|rt/        |      |d<   n|t0        urt/        |      |d<   t        |dd       rd|d<   |j3                  |       9 E |S )NT   r   convert_underscoresinclude_in_schemar   r   r   r   _-)r   inr>   schemadescriptionopenapi_examplesexampleexamples
deprecated)r   rP   rQ   rR   rS   r!   pathqueryheadercookielenr   
field_info
annotationr)   getattrr   r   r   replacevalueis_requiredr   r   r   rj   )ro   r   r   r   
parametersrP   rQ   rR   rS   parameter_groupsdefault_convert_underscoresfirst_field
param_typeparam_groupparamr   param_schemar   r   	parameterr   r   s                         r^   !_get_openapi_operation_parametersr      sM    J./J/JKK/0L0LML01N1NOM01N1NOM	+&			<(			M*			M*	 #'
?(()Q.%33A6k44??K*1&&(=t+' $4 ))
K  (	)E))J:':DA6-+.K	L (.D")  %+# j///EJJ&'zz))#s3  &&!,,88:&	I %%+5+A+A	-(&z3EtLj)T:G(89I(J	*%&'7'@	)$z<6*.	,'i(Q(	)))T r]   
body_fieldc                    | sy t        | t              sJ t        | |||      }t        t        | j
                        }|j                  }| j
                  j                         }i }|r||d<   d|i}	|j                  rt        |j                        |	d<   n*|j                  t        urt        |j                        |	d<   ||	i|d<   |S )Nr   r>   r   r   r   content)
isinstancer
   r   r   r    r   
media_typer   r   r   r   r   )
r   r   r   r   body_schemar   request_media_typer>   request_body_oairequest_media_contents
             r^   "get_openapi_operation_request_bodyr      s     j*----%#&C	K dJ112J#..$$002H')'/$-5{,C"",<''-
j) 
		6	)+;J<N<N+Oi(#57L"MYr]   routemethodc                     t        j                  dt        d       | j                  r| j                  S | j                  }t        | j                  ||      S )Nzqfastapi.openapi.utils.generate_operation_id() was deprecated, it is not used internally, and will be removed soon   )messagecategory
stacklevel)r   r   r   )warningswarnr   operation_idpath_formatr'   r   )r   r   r   s      r^   generate_operation_idr   
  sP     MM>*	 !!!!!D)uzzVTTr]   c                     | j                   r| j                   S | j                  j                  dd      j                         S )Nr    )summaryr   r   r4   r   r   s     r^   generate_operation_summaryr     s3    }}}}::c3'--//r]   operation_idsc                     i }| j                   r| j                   |d<   t        | |      |d<   | j                  r| j                  |d<   | j                  xs | j                  }||v rft        | j                  dd      }d| d| }t        | j                  d	i       j                  d
      }|r|d| z  }t        j                  |d       |j                  |       ||d<   | j                  r| j                  |d<   |S )Ntagsr   r   r   rU   z<unnamed_endpoint>zDuplicate Operation ID z for function __globals____file__z at r   )r   operationIdr   )r   r   r   r   	unique_idr   endpointgetr   r   addr   )r   r   r   	operationr   endpoint_namer   	file_names           r^   get_openapi_operation_metadatar     s     !#Izz!JJ	&5E&QIi#(#4#4	- %%8L}$
<PQ+L>WENNM2>BB:N	i[))Gg!,l#+Im"'"2"2	,r]   c           	        0 i }i }i }| j                   J d       t        | j                  t              r| j                  j                  }n| j                  }|sJ d       |j
                  }	| j                  rt        | j                        }
|
j                  |
j                  |
j                  |
j                  fD cg c]  }t        |      D ]  }|  }}}| j                   D ]Y  }t        | ||      0g }t        |
j                         \  }}|r!0j#                  dg       j%                  |       |r|j'                  |       t)        |
|||      }|j%                  |       |rn|D ci c]  }|d   |d   f| }}|D ci c]  }|j+                  d	      r|d   |d   f|  }}|j'                  |       t-        |j/                               0d
<   |t0        v r t3        | j4                  |||      }|r|0d<   | j6                  rzi }| j6                  D ]d  }t        |t8        j:                        st=        t?        t8        j@                  |      ||||      \  }}}|jB                  |i||jD                  <   f |0d<   | jF                  tI        | jF                        }nktK        jL                  |jN                        }|jP                  j+                  d      }|/t        |jR                  tT              rtI        |jR                        }| jV                  0j#                  di       j#                  i       d<   tY        | jF                        r| jZ                  rii }| j\                  rt_        | j\                  |||      } | |d<   ni |d<   |0j#                  di       j#                  |i       j#                  di       d<   n| j`                  ri }!tc        jd                  tf              } | j\                  r+t_        | j\                  |||      }"dg| d	<   dd|"d| d   d<   | |!d<   |!0j#                  di       j#                  |i       j#                  di       d<   n|	rddi}#ti        |tj              r(| jl                  rt_        | jl                  |||      }#ni }#|#0j#                  di       j#                  |i       j#                  di       j#                  |	i       d<   | jn                  r0j#                  di       }$| jn                  jq                         D ]  \  }%}&tc        jd                  |&      }'|'js                  dd        tI        |%      ju                         }(|(dk(  rd }(|$j#                  |(i       })t        |'tv              sJ d!       | jx                  j+                  |%      }d }*|rSt_        ||||      }*|	xs d}+|'j#                  di       j#                  |+i       j#                  di       },t{        |,|*       t|        j+                  tI        |%      ju                               xs2 t~        j                  jn                  j+                  tU        |%            }-|'j+                  d      xs |)j+                  d      xs |-xs d"}.t{        |)|'       |.|)d<    d#}/|s| j4                  rOt        0fd$|/d%d fD              s8d&ddd't        d(z   iiid)0d   |/<   d*|vr|j'                  t        t        d+       | j                  rt{        0| j                         0||j                         <   \ |||fS c c}}w c c}w c c}w ),NzMethods must be a listz.A response class is needed to generate OpenAPI)r   r   r   )rT   security)ro   r   r   r   r   r   r>   r   )r   r   r   r   requestBodyr   r   r   r   r   	callbacksstatus_code	responsesr   r   
itemSchemar   zapplication/jsonldatar2   zapplication/json)r1   contentMediaTypecontentSchemar=   ztext/event-streamr1   r   r|   rK   defaultz%An additional response must be a dictzAdditional Response422c              3   ,   K   | ]  }|d    v   yw)r   Nr\   )re   statusr   s     r^   rh   z#get_openapi_path.<locals>.<genexpr>  s%      B )K00Bs   rI   zValidation ErrorrB   r?   )r   r   r,   )r,   r?   )Gmethodsr   response_classr   r   r   r   rw   r_   rP   rQ   rR   rS   r   r   r   rT   
setdefaultrk   updater   r   rX   valuesr   r   r   r   r	   APIRouteget_openapi_pathr   _APIRouteLiker   r   r   r[   inspect	signature__init__r   r   intresponse_descriptionr(   is_json_streamstream_item_fieldr   is_sse_streamrl   deepcopyr#   r   r*   response_fieldr   r5   ri   upperdictresponse_fieldsr&   rL   httpclientanyr   validation_error_definition$validation_error_response_definitionopenapi_extralower)1r   r   r   r   r   r   security_schemesdefinitionscurrent_response_classroute_response_media_typero   fieldsr   all_route_paramsr   r   r~   r   operation_parametersr   all_parametersrequired_parametersr   r   callbackcb_pathcb_security_schemescb_definitionsr   response_signaturestatus_code_paramjsonl_contentitem_schemasse_contentcontent_schemaresponse_schemaoperation_responsesadditional_status_codeadditional_responseprocess_responsestatus_code_keyopenapi_responseadditional_field_schemar   additional_schemastatus_textr   http422r   s1                                                   @r^   r   r   7  s    D')"$K==$>&>>$%&&(:;161E1E1K1K!&!5!5!S#SS!,B,M,M6uG  ++,,----		
 6f=	
  	
	
 	
 mm D	-F6F-I 02J1*9*O*O 5 "4
 "$$Z4;;<NO# ''(<=#D /-+.K	$  23EO"<AU4[%-0%7" "
 ",'yy, 4[%-0%7'# ' %%&9:*.~/D/D/F*G	,'**#E$//#1"/2O	$  $/?Im,	 % LH!(G,<,<=
 -"&w'<'<h"G*7+9*7:W	#/* 5=MM73K	(--0L *3	+&  ,!%"3"34 &-%6%67M7V7V%W"$6$A$A$E$Em$T!$0!"3";";SA&)*;*C*C&D **   b1<<["M /u/@/@A''46M..&A"'"9"9+9*7:W	' 7Bl368l3 HU ((b9DD#R jB/0CE ((24K"&--0A"BK..)D"'"9"9+9*7:W	* 4:(J/$,0B-;=L1&9
 1<K- HS ((b9DD#R jB/0CE /'-x&8O)*@,O //.I&+&:&:/=.;>[	/O /1O
 #2	 ((b9DD#R jB/

121	 
 &/&:&:;&K# __**,)B *''+}}5H'I$$(($7&)*@&A&G&G&IO&)3*3':'E'E'($ &&6= ?= "11556LMEEI+2M"'+9*7:W	3/ &?%TBT
,77	2F'Z
B7'Z"5 *
 )):<ST.@.D.D2399;/ /P..2237M3NO   ),,]; 1+//>1&1 1	   %%57GH6A$]3S)BT G E$4$4c B&y9B ?
 $6*$vz<Q/Q&R- 3	+&w/ %K7&&/J3W "" E,?,?@#,D ID	-J !;.._	
@"'s    ]
1]	#]route_contextc                     t        | j                  t        j                        rt	        t        j
                  |       S y )N)r   original_router	   r   r   r   )r"  s    r^   _get_api_route_for_openapir%    s0     -..0@0@AG))=99r]   routesc                    g }g }g }g }t        j                  |       D ]?  }t        |      }||j                  s|j                  r<t        |j                  t              sJ d       |j                  |j                         |j                  r|j                  |j                         |j                  r)|j                  |j                  j                                |j                  r|j                  |j                         |j                  r$|j                  t        |j                               t        |j                         }|j                  |       B |t#        ||z   |z         z   }|S )Nz'A request body must be a Pydantic Field)r	   iter_route_contextsr%  r   r   r   r
   rj   r   r   rk   r   r   r   get_fields_from_routesr   r_   rX   )	r&  body_fields_from_routesresponses_from_routesrequest_fields_from_routescallback_flat_modelsr"  	api_routeparamsflat_modelss	            r^   r)  r)  '  s\    13.035-/ 44V< 6.}=	&&##!)"6"6
C =C (..y/C/CD''%,,Y-E-EF((%,,Y-F-F-M-M-OP**%,,Y-H-HI""$++,B9CVCV,WX$Y%8%89F&--f5'6* '"77:TT* K r]   z3.1.0)openapi_versionr   r   webhooksr   serversterms_of_servicecontactlicense_infor   external_docsversionr1  r   r   r2  r   r3  r4  r5  r6  r7  c                    | |d}|r||d<   |r||d<   |	r|	|d<   |
r|
|d<   |r||d<   ||d}|r||d<   i }i }i }t               }t        t        |      t        |xs g       z         }t        |t               	      }t	        |      }t        |||
      \  }}t        j                  |      D ]  }t        |      }|t        |||||      }|s$|\  }}}|r+|j                  |j                  i       j                  |       |r!|j                  di       j                  |       |s}|j                  |        t        j                  |xs g       D ]  }t        |      } | t        | ||||      }|s$|\  }}}|r+|j                  | j                  i       j                  |       |r!|j                  di       j                  |       |s}|j                  |        |r t        |      D !ci c]  }!|!||!   
 c}!|d<   |r||d<   ||d<   |r||d<   |r||d<   |r||d<   t        t        di |dd      S c c}!w )N)r4   r8  r   r   termsOfServicer5  license)openapiinfor3  )known_models)r  r   r   r   securitySchemesschemas
componentspathsr2  r   externalDocsTry   r\   )setr)  rX   r   r   r   r	   r(  r%  r   r   r   r   sortedr   r   )"r4   r8  r1  r   r   r&  r2  r   r3  r4  r5  r6  r   r7  r=  outputrA  rB  webhook_pathsr   
all_fieldsr0  r   r   r  r"  r.  resultr   r  path_definitionswebhook_contextapi_webhookks"                                     r^   get_openapirN  I  s   " &+w?D!Y)]!1!Y&Y)8$GF#y,.J')E/1M!eM'VtHN7K(KLJ-jsuMK'4N!0%&C"M;
 !44V< 9.}=	 %+-+.KF ;A8&(8$$Y%:%:B?FFtL#))*;R@GG( $&&'78'9( #66x~2F 90A"%!+-+.KF ;A8&(8!,,[-D-DbIPPQUV#))*;R@GG( $&&'78'9( <B;<O PqKN!2 P
9)|F7O*zv!.~G-f-4PP !Qs   7I)Zrl   http.clientr   r   r   collections.abcr   dataclassesr   r   typingr   r   r   fastapir	   fastapi._compatr
   r   r   r   r   r   fastapi.datastructuresr   r   fastapi.dependencies.modelsr   r   r   r   r   r   fastapi.dependencies.utilsr   r   r   fastapi.encodersr   fastapi.exceptionsr   fastapi.openapi.constantsr   r   fastapi.openapi.modelsr   fastapi.paramsr    r!   fastapi.responsesr"   fastapi.sser#   fastapi.typesr$   r%   fastapi.utilsr&   r'   r(   pydanticr)   starlette.responsesr*   starlette.routingr+   r   r  rL   r   r[   rY   rN   rw   rX   rZ   r   boolr   r   r   r   r   rD  r   r   RouteContextr%  r)  rN  r\   r]   r^   <module>rf     sh       $ ( % %   >  
 . 8 C * + & ) : 
  , '    2VY4GHI

 #H5&97#"H5
 ' $ #j+<<=

( $ !& DcN    I :P B4ic&: ;<4
4S>4S#X//04D +/E+E !E j'"?@@A4S>Q	E $(E 
$sCx.E^ +/ T!  !  j'"?@@A4S>Q	  $(  
#s(^d FU##U-0UU0)>)> 0 0PS 0##-0ADS	#s(^@ +/e/  e/ s8e/ !	e/
 j'"?@@A4S>Qe/ $(e/ 4S>4S>4S>9:e/P''T!Y!5!556	*L #"BF(,15#'+/04*.+/^Q^Q ^Q 	^Q
 4Z^Q t^Q Y!5!556^Q y7#7#7784?^Q tCH~

%^Q $sC#I~&'$.^Q Dj^Q #sSy.!D(^Q sC#I~&-^Q $(^Q S>D(^Q  
#s(^!^Qr]   