U
    Rh]                     @   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 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/m0Z0 d dl1m2Z2m3Z3m4Z4 d dl5m6Z6 d dl7m8Z8 d dl9m:Z: 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d d!dg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 eAd/< eeee@ef eee@ef  f d0d1d2ZBd3d4eee0eeee<d5 f ef eCeee@ef  d6d7d8ZDd3d4ee ee0eeee<d5 f ef eCeee@ef  d9d:d;ZEejFe@e@d<d=d>ZGejFe@e@d<d?d@ZHejFe@e
e@ ee@ef dAdBdCZId3d4ejFe
e@ ee0eeee<d5 f ef eCeee@ef ee@ef ee@ef f dDdEdFZJe	e: ee dGdHdIZKdJddddddddd3ddKe@e@e@ee@ ee@ e	e: ee	e:  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  eCeee@ef  ee@ef dLdMdNZLdS )O    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_fields_from_paramsget_flat_dependantget_flat_params)jsonable_encoder)METHODS_WITH_BODY
REF_PREFIXREF_TEMPLATE)OpenAPI)Body
ParamTypes)Response)ModelNameMap)deep_dict_updategenerate_operation_id_for_pathis_body_allowed_for_status_code)	BaseModel)JSONResponse)	BaseRoute)LiteralValidationErrorobjectZLocationarrayanyOftypestringinteger)titler.   itemsMessage)r1   r.   z
Error Type)locmsgr.   r4   r5   )r1   r.   
propertiesrequiredHTTPValidationErrordetailZDetail$ref)r1   r.   r6   ZInformationZSuccessZRedirectionzClient ErrorzServer ErrorzDefault Response)1XX2XX3XX4XX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by_aliasexclude_none)security_requirementsr   security_schememodelscheme_nameappendscopes)rB   security_definitionsoperation_securitysecurity_requirementZsecurity_definitionZsecurity_name rP   Y/var/www/html/timesheet/backend/venv/lib/python3.8/site-packages/fastapi/openapi/utils.py get_openapi_security_definitionsM   s    
rR   T)separate_input_output_schemas)
validationserialization)	dependantschema_generatormodel_name_mapfield_mappingrS   rC   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r|jd }t|jtrt|jdd}|D ] \}}|D ]}|j}t|ddsqt|||||d}|j}t|jd|}|tj	kr|j|jkr|r|jdd	}||j|j|d
}|jr4|j|d< t|dd }t|dd }|r`t||d< n|tkrvt||d< t|dd rd|d< || qq|S )NTskip_repeats   r   convert_underscoresinclude_in_schemafieldrW   rX   rY   rS   _-)nameinr7   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   aliasrc   replacevaluer7   rf   r   r   rK   )rV   rW   rX   rY   rS   
parametersrB   rk   rl   rm   rn   Zparameter_groupsdefault_convert_underscoresfirst_field
param_typeZparam_groupparamrv   Zparam_schemarc   r]   	parameterrg   rh   rP   rP   rQ   !_get_openapi_operation_parameters^   s|    





  


r   )
body_fieldrW   rX   rY   rS   rC   c                 C   s   | sd S t | tst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 )Nr_   r7   re   ri   rh   content)
isinstancer   AssertionErrorr   r   r   rv   
media_typer7   rg   r   rh   r   )r   rW   rX   rY   rS   Zbody_schemarv   Zrequest_media_typer7   request_body_oaiZrequest_media_contentrP   rP   rQ   "get_openapi_operation_request_body   s2    


r   )routemethodrC   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)rc   ro   r   )warningswarnDeprecationWarningoperation_idpath_formatr$   rc   )r   r   ro   rP   rP   rQ   generate_operation_id   s    r   c                 C   s   | j r| j S | jdd S )Nra    )summaryrc   rx   r1   r   r   rP   rP   rQ   generate_operation_summary   s    r   )r   r   operation_idsrC   c                 C   s   i }| j r| j |d< t| |d|d< | jr4| j|d< | jp>| j}||krd| d| jj  }t| jdi d}|r|d	| 7 }t	j
|d
d || ||d< | jr| j|d< |S )Ntagsr   r   rf   zDuplicate Operation ID z for function __globals____file__z at r\   r   operationIdrj   )r   r   rf   r   	unique_idendpoint__name__ru   getr   r   addrj   )r   r   r   	operationr   message	file_namerP   rP   rQ   get_openapi_operation_metadata   s*    




r   )r   r   rW   rX   rY   rS   rC   c           +   
      s<  i }i }i }| j d k	stdt| jtr4| jj}	n| j}	|	sFtd|	j}
| jr2| j D ]}t| ||d g }t	| j
dd}t|d\}}|r dg | |r|| t| j
||||d}|| |rd	d
 |D }dd
 |D }|| t|  d< |tkr8t| j||||d}|r8| d< | jri }| jD ]>}t|tjrJt||||||d\}}}|j|i||j< qJ| d< | jd k	rt| j}n:t|	j}|j !d}|d k	rt|j"t#rt|j"}| j$ di |i d< |
rnt%| jrnddi}t&|	t'rF| j(rBt)| 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/std| j0!|}#d }$|#r<t)|#||||d}$|
pd}%| di |%i di }&t1|&|$ t2!t|. p`t3j4j*!t#|}'| !dp|"!dp|'pd}(t1|"|  |(|"d< qd})t5| j
}*|*s| jrt6 fd d!|)d"dfD sd#ddd$t7d% iiid& d |)< d'|kr|t8t9d( | j:r$t1 | j:  ||; < qZ|||fS ))NzMethods must be a listz.A response class is needed to generate OpenAPI)r   r   r   TrZ   )rB   security)rV   rW   rX   rY   rS   c                 S   s   i | ]}|d  |d f|qS )rd   rc   rP   .0r~   rP   rP   rQ   
<dictcomp>)  s     z$get_openapi_path.<locals>.<dictcomp>c                 S   s(   i | ] }| d r|d |d f|qS )r7   rd   rc   )r   r   rP   rP   rQ   r   ,  s   
 rz   )r   rW   rX   rY   rS   requestBodyr   r   rW   rX   rY   rS   	callbacksstatus_code	responsesrf   r.   r/   r_   r   re   rI   r@   defaultz%An additional response must be a dictzapplication/jsonzAdditional ResponseZ422c                 3   s   | ]}| d  kV  qdS )r   NrP   )r   statusr   rP   rQ   	<genexpr>  s   z#get_openapi_path.<locals>.<genexpr>r>   zValidation Errorr:   r8   )rf   r   r*   )r*   r8   )<methodsr   r   response_classr   ry   r   r^   r   r   rV   rR   
setdefaultextendupdater   listvaluesr   r   r   r   r   APIRouteget_openapi_pathro   rc   r   strinspect	signature__init__rz   r   r   intresponse_descriptionr%   r   r'   response_fieldr   r   r2   copypopupperdictresponse_fieldsr#   rA   httpclientr   anyr   validation_error_definition$validation_error_response_definitionopenapi_extralower)+r   r   rW   rX   rY   rS   ro   security_schemesdefinitionscurrent_response_classZroute_response_media_typer   rz   rB   rM   rN   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_responsesadditional_status_codeZadditional_responseZprocess_responseZstatus_code_keyZopenapi_responser`   Zadditional_field_schemar   Zadditional_schemaZstatus_textrf   Zhttp422Zall_route_paramsrP   r   rQ   r      sl   
  





	

   
 
  




 

r   )routesrC   c                 C   s   g }g }g }g }| D ]}t |dd rt|tjr|jrVt|jtsJtd||j |jrh||j |j	r~|
|j	  |jr|
t|j t|j}|
| q|t|| |  }|S )Nr^   z'A request body must be a Pydantic Field)ru   r   r   r   r   r   r   rK   r   r   r   r   r   get_fields_from_routesr   rV   r   )r   Zbody_fields_from_routesZresponses_from_routesZrequest_fields_from_routesZcallback_flat_modelsr   paramsZflat_modelsrP   rP   rQ   r     s4     

r   z3.1.0)openapi_versionr   rf   webhooksr   serversterms_of_servicecontactlicense_inforS   external_docs)r1   versionr   r   rf   r   r   r   r   r   r   r   rS   r   rC   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< |r||d< ttf |dddS )N)r1   r   r   rf   termsOfServicer   license)openapiinfor   )ref_template)fieldsrW   rX   rS   r   securitySchemesc                    s   i | ]}| | qS rP   rP   )r   kr   rP   rQ   r   1  s      zget_openapi.<locals>.<dictcomp>schemas
componentspathsr   r   externalDocsTrD   )setr   r   r   r   r   r   r   r   r   r   r   r   r   sortedr   r   )r1   r   r   r   rf   r   r   r   r   r   r   r   rS   r   r   outputr   r   Zwebhook_pathsr   Z
all_fieldsrX   rW   rY   r   resultro   r   Zpath_definitionsZwebhookrP   r   rQ   get_openapi  s    





r   )Mhttp.clientr   r   r   typingr   r   r   r   r   r   r   r	   r
   r   fastapir   fastapi._compatr   r   r   r   r   r   r   r   fastapi.datastructuresr   fastapi.dependencies.modelsr   fastapi.dependencies.utilsr   r   r   fastapi.encodersr   Zfastapi.openapi.constantsr   r   r   fastapi.openapi.modelsr   fastapi.paramsr   r    fastapi.responsesr!   fastapi.typesr"   fastapi.utilsr#   r$   r%   pydanticr&   starlette.responsesr'   starlette.routingr(   typing_extensionsr)   r   r   rA   r   __annotations__rR   boolr   r   r   r   r   r   r   r   r   rP   rP   rP   rQ   <module>   s    0(
	
S&   
#$ B#

