a
    g	gW                     @   s  U d dl Zd dlZd dlZd dlmZmZmZmZm	Z	m
Z
mZ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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%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l0m1Z1m2Z2m3Z3 d dl4m5Z5 d dl6m7Z7 d dl8m9Z9 d dl:m;Z; dddddddiddigiddddddddg dd Z<d!dd"d#dd$e%d idid%Z=d&d'd(d)d*d+d,Z>ee?e?f e@d-< eeee?ef eee?ef  f d.d/d0ZAd1d2e	e ee/eeee;d3 f ef eBeee?ef  d4d5d6ZCd1d2ee ee/eeee;d3 f ef eBeee?ef  d7d8d9ZDejEe?e?d:d;d<ZFejEe?e?d:d=d>ZGejEe?e
e? ee?ef d?d@dAZHd1d2ejEe
e? ee/eeee;d3 f ef eBeee?ef ee?ef ee?ef f dBdCdDZIe	e7 ee dEdFdGZJdHddddddddd1dI
e?e?e?ee? ee? e	e7 ee	e7  eeee?ef   eeee?ee?ef f   ee? eee?ee?ef f  eee?ee?ef f  eBee?ef dJdKdLZKdS )M    N)
AnyDictListOptionalSequenceSetTupleTypeUnioncast)routing)GenerateJsonSchemaJsonSchemaValue
ModelField	Undefinedget_compat_model_name_mapget_definitionsget_schema_from_model_fieldlenient_issubclass)DefaultPlaceholder)	Dependant)get_flat_dependantget_flat_params)jsonable_encoder)METHODS_WITH_BODY
REF_PREFIXREF_TEMPLATE)OpenAPI)BodyParam)Response)ModelNameMap)deep_dict_updategenerate_operation_id_for_pathis_body_allowed_for_status_code)JSONResponse)	BaseRoute)HTTP_422_UNPROCESSABLE_ENTITY)LiteralValidationErrorobjectZLocationarrayZanyOftypestringinteger)titler,   itemsMessage)r/   r,   z
Error Type)locmsgr,   )r/   r,   
propertiesrequiredHTTPValidationErrorZdetailZDetail$ref)r/   r,   r4   ZInformationZSuccessZRedirectionzClient ErrorzServer ErrorzDefault Response)Z1XXZ2XXZ3XX4XXZ5XXDEFAULTstatus_code_ranges)flat_dependantreturnc                 C   sN   i }g }| j D ]6}t|jjddd}|jj}|||< |||ji q||fS )NTZby_aliasZexclude_none)Zsecurity_requirementsr   Zsecurity_schememodelZscheme_nameappendZscopes)r;   security_definitionsoperation_securityZsecurity_requirementZsecurity_definitionZsecurity_name rB   X/var/www/html/llm_bihealth/app/venv/lib/python3.9/site-packages/fastapi/openapi/utils.py get_openapi_security_definitionsI   s    
rD   T)separate_input_output_schemas)Z
validationZserialization)all_route_paramsschema_generatormodel_name_mapfield_mappingrE   r<   c           
      C   s   g }| D ]}|j }tt|}|js$qt|||||d}|j|jj|j|d}	|j	r\|j	|	d< |j
rrt|j
|	d< n|jtkrt|j|	d< |jrd|	d< ||	 q|S )NfieldrG   rH   rI   rE   )nameinr5   schemadescriptionexamplesexampleT
deprecated)
field_infor   r   include_in_schemar   aliasZin_valuer5   rO   openapi_examplesr   rQ   r   rR   r?   )
rF   rG   rH   rI   rE   
parametersparamrS   Zparam_schemaZ	parameterrB   rB   rC    get_openapi_operation_parametersZ   s8    



rZ   )
body_fieldrG   rH   rI   rE   r<   c                 C   s   | sd S t | tsJ t| ||||d}tt| j}|j}| j}i }	|rP||	d< d|i}
|jrnt	|j|
d< n|j
tkrt	|j
|
d< ||
i|	d< |	S )NrJ   r5   rN   rP   rQ   content)
isinstancer   r   r   r   rS   
media_typer5   rW   r   rQ   r   )r[   rG   rH   rI   rE   Zbody_schemarS   Zrequest_media_typer5   request_body_oaiZrequest_media_contentrB   rB   rC   "get_openapi_operation_request_body   s2    


r`   )routemethodr<   c                 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   
stacklevel)rL   pathrb   )warningswarnDeprecationWarningoperation_idpath_formatr#   rL   )ra   rb   rf   rB   rB   rC   generate_operation_id   s    rl   c                 C   s   | j r| j S | jdd S )N_ )summaryrL   replacer/   ra   rb   rB   rB   rC   generate_operation_summary   s    rr   )ra   rb   operation_idsr<   c                 C   s   i }| j r| j |d< t| |d|d< | jr4| j|d< | jp>| j}||v rd| d| jj  }t| jdi d}|r|d	| 7 }t	j
|d
d || ||d< | jr| j|d< |S )Ntagsrq   ro   rO   zDuplicate Operation ID z for function __globals____file__z at    rd   ZoperationIdrR   )rt   rr   rO   rj   Z	unique_idZendpoint__name__getattrgetrg   rh   addrR   )ra   rb   rs   	operationrj   message	file_namerB   rB   rC   get_openapi_operation_metadata   s*    




r   )ra   rs   rG   rH   rI   rE   r<   c           +   
      s>  i }i }i }| j d usJ dt| jtr4| jj}	n| j}	|	sFJ d|	j}
| jr4| j D ]}t| ||d g }t| j	dd}t
|d\}}|r dg | |r|| t| j	}t|||||d}|| |rd	d
 |D }dd
 |D }|| t|  d< |tv r@t| j||||d}|r@| d< | jri }| jD ]>}t|tjrRt||||||d\}}}|j|i||j< qR| d< | jd urt| j}n:t|	j}|j !d}|d urt|j"t#rt|j"}| j$ di |i d< |
rvt%| jrvddi}t&|	t'rN| j(rJt)| j(||||d}ni }| di |i di |
i d< | j*r di }| j*+ D ]
\}} | , }!|!-dd  t|. }"|"dkrd}"||"i }#t|!t/sJ d| j0!|}$d }%|$rDt)|$||||d}%|
pd}&|!di |&i di }'t1|'|% t2!t|. pht3j4j*!t#|}(|!!dp|#!dp|(pd})t1|#|! |)|#d< qtt5}*|s| jrt6 fdd |*d!dfD sd"ddd#t7d$ iiid% d |*< d&|vr|t8t9d' | j:r&t1 | j:  ||; < qZ|||fS )(NzMethods must be a listz.A response class is needed to generate OpenAPI)ra   rb   rs   T)Zskip_repeats)r;   security)rF   rG   rH   rI   rE   c                 S   s   i | ]}|d  |d f|qS )rM   rL   rB   .0rY   rB   rB   rC   
<dictcomp>  s   z$get_openapi_path.<locals>.<dictcomp>c                 S   s(   i | ] }| d r|d |d f|qS )r5   rM   rL   )rz   r   rB   rB   rC   r     s   
rX   )r[   rG   rH   rI   rE   ZrequestBodyra   rs   rG   rH   rI   rE   	callbacksstatus_code	responsesrO   r,   r-   rJ   r\   rN   r>   r9   defaultz%An additional response must be a dictzapplication/jsonzAdditional Responsec                 3   s   | ]}| d  v V  qdS )r   NrB   )r   statusr|   rB   rC   	<genexpr>~  s   z#get_openapi_path.<locals>.<genexpr>r8   zValidation Errorr7   r6   )rO   r\   r)   )r)   r6   )<methodsr]   response_classr   rV   r^   rT   r   r   	dependantrD   
setdefaultextendupdater   rZ   listvaluesr   r`   r[   r   r   APIRouteget_openapi_pathrf   rL   r   strinspect	signature__init__rX   rz   r   intZresponse_descriptionr$   r   r%   response_fieldr   r   r0   copypopupperdictresponse_fieldsr"   r:   httpclientr'   anyr   validation_error_definition$validation_error_response_definitionZopenapi_extralower)+ra   rs   rG   rH   rI   rE   rf   security_schemesdefinitionsZcurrent_response_classZroute_response_media_typerb   rX   r;   r@   rA   rF   Zoperation_parametersZall_parametersZrequired_parametersr_   r   callbackZcb_pathZcb_security_schemesZcb_definitionsr   Zresponse_signatureZstatus_code_paramZresponse_schemaZoperation_responsesZadditional_status_codeZadditional_responseprocess_responseZstatus_code_keyZopenapi_responserK   Zadditional_field_schemar^   Zadditional_schemaZstatus_textrO   Zhttp422rB   r   rC   r      s^   







	








r   )routesr<   c                 C   s   g }g }g }g }| D ]}t |dd rt|tjr|jrVt|jtsJJ d||j |jrh||j |jr~|	|j
  |jr|	t|j t|j}|	| q|t|| |  }|S )NrT   z'A request body must be a Pydantic Field)ry   r]   r   r   r[   r   r?   r   r   r   r   r   get_fields_from_routesr   r   r   )r   Zbody_fields_from_routesZresponses_from_routesZrequest_fields_from_routesZcallback_flat_modelsra   paramsZflat_modelsrB   rB   rC   r     s6    

r   z3.1.0)
openapi_versionro   rO   webhooksrt   serversterms_of_servicecontactlicense_inforE   )r/   versionr   ro   rO   r   r   rt   r   r   r   r   rE   r<   c              	      s  | |d}|r||d< |r"||d< |	r.|	|d< |
r:|
|d< |rF||d< ||d}|r\||d< i }i }i }t  }tt|pxg t|pg  }t|}ttd	}t||||d
\} |pg D ]r}t|tj	rt
||||||d}|r|\}}}|r||ji | |r|di | |r | q|p4g D ]z}t|tj	r6t
||||||d}|r6|\}}}|r||ji | |r|di | |r6 | q6 r҇ fddt D |d< |r||d< ||d< |r||d< |r||d< ttf i |dddS )N)r/   r   ro   rO   ZtermsOfServicer   license)Zopenapiinfor   )Zref_template)fieldsrG   rH   rE   r   ZsecuritySchemesc                    s   i | ]}| | qS rB   rB   )r   kr   rB   rC   r   
      zget_openapi.<locals>.<dictcomp>Zschemas
componentspathsr   rt   Tr=   )setr   r   r   r   r   r   r]   r   r   r   r   rk   r   sortedr   r   )r/   r   r   ro   rO   r   r   rt   r   r   r   r   rE   r   outputr   r   Zwebhook_pathsrs   Z
all_fieldsrH   rG   rI   ra   resultrf   r   Zpath_definitionsZwebhookrB   r   rC   get_openapi  s    





r   )Lhttp.clientr   r   rg   typingr   r   r   r   r   r   r   r	   r
   r   Zfastapir   Zfastapi._compatr   r   r   r   r   r   r   r   Zfastapi.datastructuresr   Zfastapi.dependencies.modelsr   Zfastapi.dependencies.utilsr   r   Zfastapi.encodersr   Zfastapi.openapi.constantsr   r   r   Zfastapi.openapi.modelsr   Zfastapi.paramsr   r   Zfastapi.responsesr    Zfastapi.typesr!   Zfastapi.utilsr"   r#   r$   Zstarlette.responsesr%   Zstarlette.routingr&   Zstarlette.statusr'   Ztyping_extensionsr(   r   r   r:   r   __annotations__rD   boolrZ   r`   r   rl   rr   r   r   r   r   rB   rB   rB   rC   <module>   s   
0(
	
1&
#$ B#

