o
    LDi\                  !   @   s.  U 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	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!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-m.Z.m/Z/ d dl0m1Z1 d dl2m3Z3 d dl4m5Z5 d dl6m7Z7 ddl8m9Z9 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?d0< d1ed2e@e=e>ef eAe=e>ef  f fd3d4ZBd5d6d7ed8e+d9e=e@ee7d: f ef d;eCd2eAe=e>ef  f
d<d=ZDd5d6d>ee d8e+d9e=e@ee7d: f ef d;eCd2ee=e>ef  f
d?d@ZEdAejFdBe>d2e>fdCdDZGdAejFdBe>d2e>fdEdFZHdAejFdBe>dGeIe> d2e=e>ef fdHdIZJd5d6dAejFdGeIe> d8e+d9e=e@ee7d: f ef d;eCd2e@e=e>ef e=e>ef e=e>ef f fdJdKZKdLee5 d2eAe fdMdNZLdOddddddddd5ddPdQe>dRe>dSe>dTee> dUee> dLee5 dVeee5  dWeeAe=e>ef   dXeeAe=e>e	e>ef f   dYee> dZee=e>e	e>ef f  d[ee=e>e	e>ef f  d;eCd\ee=e>ef  d2e=e>ef fd]d^ZMdS )_    N)Sequence)AnyOptionalUnioncast)routing)JsonSchemaValue
ModelField	Undefinedget_compat_model_name_mapget_definitions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)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)Literal   )_is_model_fieldValidationErrorobjectLocationarrayanyOftypestringinteger)titler+   itemsMessage)r.   r+   z
Error Type)locmsgr+   )r.   r+   
propertiesrequiredHTTPValidationErrordetailDetail$ref)r.   r+   r3   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  rH   ).0namescopesrH   rH   a/var/www/www-root/data/www/77.83.87.30/venv/lib/python3.10/site-packages/fastapi/openapi/utils.py
<listcomp>d   s    z4get_openapi_security_definitions.<locals>.<listcomp>)_security_dependenciesr   _security_schememodelscheme_nameoauth_scopesappendr/   )rC   security_definitionsoperation_security_dictsecurity_dependencysecurity_definitionsecurity_namescopeoperation_securityrH   rH   rL    get_openapi_security_definitionsP   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rI|jd }t|jtrIt|jdd}|
D ]x\}}|D ]q}|j}t|dds]qQt||||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< || qQqK|S )NTskip_repeats   r   convert_underscoresinclude_in_schemafieldr^   r_   r\   _-)rJ   inr4   schemadescriptionopenapi_examplesexampleexamples
deprecated)r   r   path_paramsquery_paramsheader_paramscookie_paramsr   pathqueryheadercookielenr   type_r    getattr
field_infor   r   rJ   replacevaluer4   rm   r   r
   rS   )r]   r^   r_   r\   
parametersrC   rr   rs   rt   ru   parameter_groupsdefault_convert_underscoresfirst_field
param_typeparam_groupparamr}   param_schemarJ   re   	parameterrn   ro   rH   rH   rL   !_get_openapi_operation_parametersj   st   	







)r   
body_fieldc           
      C   s   | sd S t | s
J t| |||d}tt| j}|j}| j}i }|r&||d< d|i}	|jr5t|j|	d< n|j	t
krAt|j	|	d< ||	i|d< |S )Nrg   r4   rl   rp   ro   content)r%   r   r   r   r}   
media_typer4   rn   r   ro   r
   )
r   r^   r_   r\   body_schemar}   request_media_typer4   request_body_oairequest_media_contentrH   rH   rL   "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 soonr$   
stacklevel)rJ   rv   r   )warningswarnDeprecationWarningoperation_idpath_formatr   rJ   )r   r   rv   rH   rH   rL   generate_operation_id   s   r   c                 C   s   | j r| j S | jdd S )Nri    )summaryrJ   r~   r.   r   r   rH   rH   rL   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   rm   zDuplicate Operation ID z for function __globals____file__z at rd   r   operationIdrq   )r   r   rm   r   	unique_idendpoint__name__r|   getr   r   addrq   )r   r   r   	operationr   message	file_namerH   rH   rL   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 ]\}}|+ }|,dd  t|- } | dkrTd} || i }!t|t.sdJ d| j/ |}"d }#|"rt(|"|||d}#|	p{d}$|di |$i di }%t0|%|# t1 t|- pt2j3j) t"|}&| dp|! dp|&pd}'t0|!| |'|!d< q9d}(t4| j	})|)s| jrt5 fd d!|(d"dfD sd#ddd$t6d% iiid& d |(< d'|vr|t7t8d( | j9rt0 | j9  ||
: < q-|||fS ))NzMethods must be a listz.A response class is needed to generate OpenAPI)r   r   r   Trb   )rC   security)r]   r^   r_   r\   c                 S   s   i | ]}|d  |d f|qS )rk   rJ   rH   rI   r   rH   rH   rL   
<dictcomp>/  s    z$get_openapi_path.<locals>.<dictcomp>c                 S   s(   i | ]}| d r|d |d f|qS )r4   rk   rJ   )r   r   rH   rH   rL   r   2  s    r   )r   r^   r_   r\   requestBodyr   r   r^   r_   r\   	callbacksstatus_code	responsesrm   r+   r,   rg   r   rl   rP   rA   defaultz%An additional response must be a dictzapplication/jsonzAdditional Response422c                 3   s    | ]	}| d  v V  qdS )r   NrH   )rI   statusr   rH   rL   	<genexpr>  s
    

z#get_openapi_path.<locals>.<genexpr>r?   zValidation Errorr8   r5   )rm   r   r&   )r&   r5   );methods
isinstanceresponse_classr   r   r   rf   r   r   r]   r[   
setdefaultextendupdater   listvaluesr   r   r   r   r   APIRouteget_openapi_pathrv   rJ   r   strinspect	signature__init__r   r   r   intresponse_descriptionr   r   r!   response_fieldr   r   r/   copypopupperdictresponse_fieldsr   rB   httpclientr   anyr   validation_error_definition$validation_error_response_definitionopenapi_extralower)*r   r   r^   r_   r\   rv   security_schemesdefinitionscurrent_response_classroute_response_media_typer   r   rC   rT   rZ   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_responserh   additional_field_schemar   additional_schemastatus_textrm   http422all_route_paramsrH   r   rL   r     sH  


















r   routesc                 C   s   g }g }g }g }| D ]I}t |dd rSt|tjrS|jr*t|js$J d||j |jr3||j |jr>|	|j
  |jrI|	t|j t|j}|	| q
|t|| |  }|S )Nrf   z'A request body must be a Pydantic Field)r|   r   r   r   r   r%   rS   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_modelsrH   rH   rL   r     s4   


r   z3.1.0)openapi_versionr   rm   webhooksr   serversterms_of_servicecontactlicense_infor\   external_docsr.   versionr   r   rm   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	\} |pUg D ]6}t|tjrt|||||d
}|r|\}}}|rz|	|j
i | |r|	di | |r | qV|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   rm   termsOfServicer   license)openapiinfor   )fieldsr^   r\   r   securitySchemesc                    s   i | ]}| | qS rH   rH   )rI   kr   rH   rL   r   /  s    zget_openapi.<locals>.<dictcomp>schemas
componentspathsr   r   externalDocsTrE   rH   )setr   r   r   r   r   r   r   r   r   r   r   sortedr   r   )r.   r   r   r   rm   r   r   r   r   r   r   r   r\   r   r  outputr
  r  webhook_pathsr   
all_fieldsr^   r_   r   resultrv   r   path_definitionswebhookrH   r  rL   get_openapi  s   






r  )Nhttp.clientr   r   r   collections.abcr   typingr   r   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.openapi.constantsr   r   fastapi.openapi.modelsr   fastapi.paramsr   r   fastapi.responsesr   fastapi.typesr   fastapi.utilsr   r   r   pydanticr    starlette.responsesr!   starlette.routingr"   typing_extensionsr#   _compatr%   r   r   rB   r   r   __annotations__tupler   r[   boolr   r   r   r   r   r  r   r   r   r  rH   rH   rH   rL   <module>   sF  
 $		


!
P
#


"$	
 ;
#
	

