o
    bi]                  !   @   s@  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	m
Z
 d dlmZ d dlmZmZmZmZmZmZmZ d dlmZ d dlmZ d dlmZ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(m)Z) d dl*m+Z+ d dl,m-Z- d dl.m/Z/m0Z0m1Z1 d dl2m3Z3 d dl4m5Z5 d dl6m7Z7 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%Z8d&dd'd(dd)e$d idid*Z9d+d,d-d.d/d0d1Z:e;e<e<f e=d2< d3ed4e>e;e<ef e?e;e<ef  f fd5d6Z@d7d8d9ed:e-d;e;e>ee	d< f e;e<ef f d=eAd4e?e;e<ef  f
d>d?ZBd7d8d@edB d:e-d;e;e>ee	d< f e;e<ef f d=eAd4e;e<ef dB f
dAdBZCdCejDdDe<d4e<fdEdFZEdCejDdDe<d4e<fdGdHZFdCejDdDe<dIeGe< d4e;e<ef fdJdKZHd7d8dCejDdIeGe< d:e-d;e;e>ee	d< f e;e<ef f d=eAd4e>e;e<ef e;e<ef e;e<ef f fdLdMZIdNee7 d4e?e fdOdPZJdQddddddddd7ddRd e<dSe<dTe<dUe<dB dVe<dB dNee7 dWee7 dB dXe?e;e<ef  dB dYe?e;e<e<eB f  dB dZe<dB d[e;e<e<eB f dB d\e;e<e<eB f dB d=eAd]e;e<ef dB d4e;e<ef fd^d_ZKdS )`    N)Sequence)AnyLiteralcast)routing)
ModelField	Undefinedget_definitionsget_flat_models_from_fieldsget_model_name_mapget_schema_from_model_fieldlenient_issubclass)DefaultPlaceholder)	Dependant)_get_flat_fields_from_paramsget_flat_dependantget_flat_paramsget_validation_alias)jsonable_encoder)FastAPIDeprecationWarning)METHODS_WITH_BODY
REF_PREFIX)OpenAPI)Body
ParamTypes)Response)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)titler(   itemsMessage)r+   r(   z
Error Typer+   InputContext)locmsgr(   inputctx)r0   r1   r(   )r+   r(   
propertiesrequiredHTTPValidationErrordetailDetail$ref)r+   r(   r4   InformationSuccessRedirectionzClient ErrorzServer ErrorzDefault Response)1XX2XX3XX4XX5XXDEFAULTstatus_code_rangesflat_dependantreturnc                 C   s   i }i }| j D ]0}t|jjddd}|jj}|||< ||vr"g ||< |jp&g D ]}||| vr6|| | q'qdd | D }||fS )NTby_aliasexclude_nonec                 S   s   g | ]\}}||iqS  rI   ).0namescopesrI   rI   W/sda-disk/www/egybert/egybert_env/lib/python3.10/site-packages/fastapi/openapi/utils.py
<listcomp>e   s    z4get_openapi_security_definitions.<locals>.<listcomp>)_security_dependenciesr   _security_schememodelscheme_nameoauth_scopesappendr,   )rD   security_definitionsoperation_security_dictsecurity_dependencysecurity_definitionsecurity_namescopeoperation_securityrI   rI   rM    get_openapi_security_definitionsQ   s*   
r\   T)separate_input_output_schemas	dependantmodel_name_mapfield_mapping)
validationserializationr]   c                 C   s  g }t | dd}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rJt|jdd}|
D ]z\}}|D ]s}|j}t|dds^qRt||||d}t|}t|jd|}|tj	kr||jkr|r|jdd	}||j|j |d
}|jr|j|d< t|dd }t|dd }|rt||d< n
|tkrt||d< t|dd rd|d< || qRqL|S )NTskip_repeats   r   convert_underscoresinclude_in_schemafieldr_   r`   r]   _-)rK   inr5   schemadescriptionopenapi_examplesexampleexamples
deprecated)r   r   path_paramsquery_paramsheader_paramscookie_paramsr   pathqueryheadercookielenr   
field_info
annotationr    getattrr   r   rK   replacevalueis_requiredrn   r   r   rT   )r^   r_   r`   r]   
parametersrD   rs   rt   ru   rv   parameter_groupsdefault_convert_underscoresfirst_field
param_typeparam_groupparamr|   param_schemarK   rf   	parameterro   rp   rI   rI   rM   !_get_openapi_operation_parametersk   st   	







)r   
body_fieldc           
      C   s   | sd S t | tsJ t| |||d}tt| j}|j}| j }i }|r)||d< d|i}	|jr8t	|j|	d< n|j
tkrDt	|j
|	d< ||	i|d< |S )Nrh   r5   rm   rq   rp   content)
isinstancer   r   r   r   r|   
media_typer   ro   r   rp   r   )
r   r_   r`   r]   body_schemar|   request_media_typer5   request_body_oairequest_media_contentrI   rI   rM   "get_openapi_operation_request_body   s0   	


r   routemethodc                 C   s2   t jdtdd | jr| jS | j}t| j||dS )Nzqfastapi.openapi.utils.generate_operation_id() was deprecated, it is not used internally, and will be removed soon   )messagecategory
stacklevel)rK   rw   r   )warningswarnr   operation_idpath_formatr   rK   )r   r   rw   rI   rI   rM   generate_operation_id   s   r   c                 C   s   | j r| j S | jdd S )Nrj    )summaryrK   r   r+   r   r   rI   rI   rM   generate_operation_summary   s   r   operation_idsc                 C   s   i }| j r
| j |d< t| |d|d< | jr| j|d< | jp| j}||v rId| d| jj  }t| jdi d}|rB|d	| 7 }t	j
|d
d || ||d< | jrZ| j|d< |S )Ntagsr   r   rn   zDuplicate Operation ID z for function __globals____file__z at re   )r   operationIdrr   )r   r   rn   r   	unique_idendpoint__name__r~   getr   r   addrr   )r   r   r   	operationr   r   	file_namerI   rI   rM   get_openapi_operation_metadata   s*   




r   c           *   	      s   i }i }i }| j d usJ dt| jtr| jj}n| j}|s#J d|j}	| jr| j D ]}
t| |
|d g }t| j	dd}t
|d\}}|rR dg | |rY|| t| j	|||d}|| |rd	d
 |D }dd
 |D }|| t|  d< |
tv rt| j|||d}|r| d< | jri }| jD ]}t|tjrt|||||d\}}}|j|i||j< q| d< | jd urt| j}nt|j}|j d}|d urt|j!t"rt|j!}| j# di |i d< |	r*t$| jr*ddi}t%|t&r| j'rt(| j'|||d}ni }| di |i di |	i d< | j)r di }| j)* D ]\}}t+,|}|-dd  t|. } | dkrUd} || i }!t|t/seJ d| j0 |}"d }#|"rt(|"|||d}#|	p|d}$|di |$i di }%t1|%|# t2 t|. pt3j4j) t"|}&| dp|! dp|&pd}'t1|!| |'|!d< q9d}(t5| j	})|)s| jrt6 fd d!|(d"dfD sd#ddd$t7d% iiid& d |(< d'|vr|t8t9d( | j:rt1 | j:  ||
; < q-|||fS ))NzMethods must be a listz.A response class is needed to generate OpenAPI)r   r   r   Trc   )rD   security)r^   r_   r`   r]   c                 S   s   i | ]}|d  |d f|qS )rl   rK   rI   rJ   r   rI   rI   rM   
<dictcomp>0  s    z$get_openapi_path.<locals>.<dictcomp>c                 S   s(   i | ]}| d r|d |d f|qS )r5   rl   rK   )r   r   rI   rI   rM   r   3  s    r   )r   r_   r`   r]   requestBodyr   r   r_   r`   r]   	callbacksstatus_code	responsesrn   r(   r)   rh   r   rm   rQ   rB   defaultz%An additional response must be a dictzapplication/jsonzAdditional Response422c                 3   s    | ]	}| d  v V  qdS )r   NrI   )rJ   statusr   rI   rM   	<genexpr>  s
    

z#get_openapi_path.<locals>.<genexpr>r@   zValidation Errorr9   r6   )rn   r   r#   )r#   r6   )<methodsr   response_classr   r   r   rg   r   r   r^   r\   
setdefaultextendupdater   listvaluesr   r   r   r   r   APIRouteget_openapi_pathrw   rK   r   strinspect	signature__init__r   r   r   intresponse_descriptionr   r   r!   response_fieldr   r   r,   copydeepcopypopupperdictresponse_fieldsr   rC   httpclientr   anyr   validation_error_definition$validation_error_response_definitionopenapi_extralower)*r   r   r_   r`   r]   rw   security_schemesdefinitionscurrent_response_classroute_response_media_typer   r   rD   rU   r[   operation_parametersall_parametersrequired_parametersr   r   callbackcb_pathcb_security_schemescb_definitionsr   response_signaturestatus_code_paramresponse_schemaoperation_responsesadditional_status_codeadditional_responseprocess_responsestatus_code_keyopenapi_responseri   additional_field_schemar   additional_schemastatus_textrn   http422all_route_paramsrI   r   rM   r     sH  



















r   routesc                 C   s   g }g }g }g }| D ]J}t |dd rTt|tjrT|jr+t|jts%J d||j |jr4||j |jr?|	|j
  |jrJ|	t|j t|j}|	| q
|t|| |  }|S )Nrg   z'A request body must be a Pydantic Field)r~   r   r   r   r   r   rT   r   r   r   r   r   get_fields_from_routesr   r^   r   )r   body_fields_from_routesresponses_from_routesrequest_fields_from_routescallback_flat_modelsr   paramsflat_modelsrI   rI   rM   r     s4   


r   z3.1.0)openapi_versionr   rn   webhooksr   serversterms_of_servicecontactlicense_infor]   external_docsversionr   r   rn   r   r   r   r   r   r  r  c                    s  | |d}|r||d< |r||d< |	r|	|d< |
r|
|d< |r#||d< ||d}|r.||d< i }i }i }t  }tt|p<g t|pAg  }t|t  d	}t|}t|||d
\} |p\g D ]6}t|tjrt	|||||d}|r|\}}}|r|
|ji | |r|
di | |r | q]|pg D ]6}t|tjrt	|||||d}|r|\}}}|r|
|ji | |r|
di | |rΈ | q rއ fddt D |d< |r||d< ||d< |r||d< |r||d< |r||d< ttdi |dddS )N)r+   r  r   rn   termsOfServicer   license)openapiinfor   )known_models)fieldsr_   r]   r   securitySchemesc                    s   i | ]}| | qS rI   rI   )rJ   kr   rI   rM   r   1  s    zget_openapi.<locals>.<dictcomp>schemas
componentspathsr   r   externalDocsTrF   rI   )setr   r   r
   r   r	   r   r   r   r   r   r   r   sortedr   r   )r+   r  r   r   rn   r   r   r   r   r   r   r  r]   r  r  outputr  r  webhook_pathsr   
all_fieldsr   r_   r`   r   resultrw   r   path_definitionswebhookrI   r  rM   get_openapi  s   






r  )Lr   http.clientr   r   r   collections.abcr   typingr   r   r   fastapir   fastapi._compatr   r   r	   r
   r   r   r   fastapi.datastructuresr   fastapi.dependencies.modelsr   fastapi.dependencies.utilsr   r   r   r   fastapi.encodersr   fastapi.exceptionsr   fastapi.openapi.constantsr   r   fastapi.openapi.modelsr   fastapi.paramsr   r   fastapi.responsesr   fastapi.typesr   fastapi.utilsr   r   r   pydanticr    starlette.responsesr!   starlette.routingr"   r   r   rC   r   r   __annotations__tupler   r\   boolr   r   r   r   r   r  r   r   r   r  rI   rI   rI   rM   <module>   sJ  
 $	


!
P
#


"$	
 ;
#
	

