o
    m=8j$i                  !   @   sx  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 d dlmZ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/ d dl0m1Z1m2Z2m3Z3 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!d"i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/d0d1d2Z<e=e>e>f e?d3< d4ed5e@e=e>ef eAe=e>ef  f fd6d7ZBd8d9d:ed;e/d<e=e@ee	d= f e=e>ef f d>eCd5eAe=e>ef  f
d?d@ZDd8d9dAedB d;e/d<e=e@ee	d= f e=e>ef f d>eCd5e=e>ef dB f
dBdCZEdDejFdEe>d5e>fdFdGZGdDejFdEe>d5e>fdHdIZHdDejFdEe>dJeIe> d5e=e>ef fdKdLZJd8d9dDejFdJeIe> d;e/d<e=e@ee	d= f e=e>ef f d>eCd5e@e=e>ef e=e>ef e=e>ef f fdMdNZKdOejLd5ejFdB fdPdQZMdRee9ejLB  d5eAe fdSdTZNdUddddddddd8ddVd!e>dWe>dXe>dYe>dB dZe>dB dRee9ejLB  d[ee9ejLB  dB d\eAe=e>ef  dB d]eAe=e>e>eB f  dB d^e>dB d_e=e>e>eB f dB d`e=e>e>eB f dB d>eCdae=e>ef dB d5e=e>ef fdbdcZOdS )d    N)Sequence)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_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)_SSE_EVENT_SCHEMA)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)r1   r2   r)   )r,   r)   
propertiesrequiredHTTPValidationErrordetailDetail$ref)r,   r)   r5   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  rJ   ).0namescopesrJ   rJ   \/home/nk/hobo-godmode/plappi-mvp/.venv/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-   )rE   security_definitionsoperation_security_dictsecurity_dependencysecurity_definitionsecurity_namescopeoperation_securityrJ   rJ   rN    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urt||d< t|dd rd|d< || qRqL|S )NTskip_repeats   r   convert_underscoresinclude_in_schemafieldr`   ra   r^   _-)rL   inr6   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   rL   replacevalueis_requiredro   r   r   rU   )r_   r`   ra   r^   
parametersrE   rt   ru   rv   rw   parameter_groupsdefault_convert_underscoresfirst_field
param_typeparam_groupparamr}   param_schemarL   rg   	parameterrp   rq   rJ   rJ   rN   !_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urDt	|j
|	d< ||	i|d< |S )Nri   r6   rn   rr   rq   content)
isinstancer   r   r   r   r}   
media_typer   rp   r   rq   r   )
r   r`   ra   r^   body_schemar}   request_media_typer6   request_body_oairequest_media_contentrJ   rJ   rN   "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)rL   rx   r   )warningswarnr   operation_idpath_formatr   rL   )r   r   rx   rJ   rJ   rN   generate_operation_id   s   r   c                 C   s   | j r| j S | jdd S )Nrk    )summaryrL   r   r,   r   r   rJ   rJ   rN   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 rMt| jdd}d| d| }t| jd	i d
}|rF|d| 7 }tj	|dd |
| ||d< | jr^| j|d< |S )Ntagsr   r   ro   __name__z<unnamed_endpoint>zDuplicate Operation ID z for function __globals____file__z at rf   )r   operationIdrs   )r   r   ro   r   	unique_idr   endpointgetr   r   addrs   )r   r   r   	operationr   endpoint_namer   	file_namerJ   rJ   rN   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rx| j D ]I}
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ttj|||||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< t&| jr| j'r*i }| j(rt)| j(|||d}||d< ni |d< | di |i di d< nm| j*rfi }t+,t-}| j(rQt)| j(|||d}dg|d< dd|d|d d< ||d< | di |i di d< n1|	rddi}t.|t/r| j0rt)| j0|||d}ni }| di |i di |	i d < | j1r, di } | j12 D ]\}!}"t+,|"}#|#3d!d  t|!4 }$|$d"krd#}$| |$i }%t|#t5sJ d$| j6"|!}&d }'|&rt)|&|||d}'|	pd}(|#di |(i d i })t7|)|' t8"t|!4 pt9j:j1"t$|!}*|#"dp |%"dp |*p d%}+t7|%|# |+|%d< qd&},t;| j	}-|-s:| jrgt< fd'd(|,d)d#fD sgd*dd d+t=d, iiid- d |,< d.|vrg|t>t?d/ | j@rqt7 | j@  ||
A < q-|||fS )0NzMethods must be a listz.A response class is needed to generate OpenAPI)r   r   r   Trd   )rE   security)r_   r`   ra   r^   c                 S   s   i | ]}|d  |d f|qS )rm   rL   rJ   rK   r   rJ   rJ   rN   
<dictcomp>.  s    z$get_openapi_path.<locals>.<dictcomp>c                 S   s(   i | ]}| d r|d |d f|qS )r6   rm   rL   )r   r   rJ   rJ   rN   r   1  s    r   )r   r`   ra   r^   requestBodyr   r   r`   ra   r^   	callbacksstatus_code	responsesro   ri   
itemSchemar   zapplication/jsonldatar6   r*   zapplication/json)r)   contentMediaTypecontentSchemar5   ztext/event-streamr)   rn   rR   rC   defaultz%An additional response must be a dictzAdditional Response422c                 3   s    | ]	}| d  v V  qdS )r   NrJ   )rK   statusr   rJ   rN   	<genexpr>  s
    

z#get_openapi_path.<locals>.<genexpr>rA   zValidation Errorr:   r7   )ro   r   r$   )r$   r7   )Bmethodsr   response_classr   r   r   rh   r   r   r_   r]   
setdefaultextendupdater   listvaluesr   r   r   r   r   APIRouteget_openapi_pathr   _APIRouteLikerx   rL   r   strinspect	signature__init__r   r   r   intresponse_descriptionr    is_json_streamstream_item_fieldr   is_sse_streamcopydeepcopyr   r   r"   response_fieldr   r-   popupperdictresponse_fieldsr   rD   httpclientr   anyr   validation_error_definition$validation_error_response_definitionopenapi_extralower).r   r   r`   ra   r^   rx   security_schemesdefinitionscurrent_response_classroute_response_media_typer   r   rE   rV   r\   operation_parameters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_responserj   additional_field_schemar   additional_schemastatus_textro   http422all_route_paramsrJ   r   rN   r     s  


























r   route_contextc                 C   s   t | jtjrttj| S d S )N)r   original_router   r   r   r   )r  rJ   rJ   rN   _get_api_route_for_openapi  s   r  routesc           	      C   s   g }g }g }g }t | D ]S}t|}|d u rq|jr`|jr.t|jts(J d||j |jr7||j |j	rB|
|j	  |jrK||j |jrV|
t|j t|j}|
| q|t|| |  }|S )Nz'A request body must be a Pydantic Field)r   iter_route_contextsr  rh   r   r   r   rU   r   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  	api_routeparamsflat_modelsrJ   rJ   rN   r    s:   


r  z3.1.0)openapi_versionr   ro   webhooksr   serversterms_of_servicecontactlicense_infor^   external_docsversionr  r   ro   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|t|p?g  }t|t  d	}t|}t|||d
\} t|D ]8}t|}|d urt	|||||d}|r|\}}}|r|
|ji | |r|
di | |r | q\t|pg D ]8}t|}|d u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   ro   termsOfServicer  license)openapiinfor  )known_models)fieldsr`   r^   r   securitySchemesc                    s   i | ]}| | qS rJ   rJ   )rK   kr   rJ   rN   r   _  s    zget_openapi.<locals>.<dictcomp>schemas
componentspathsr  r   externalDocsTrG   rJ   )setr  r   r	   r
   r   r   r  r  r   r   r   r   sortedr   r   ) r,   r  r  r   ro   r  r  r   r  r  r  r  r^   r  r  outputr!  r"  webhook_pathsr   
all_fieldsr  r`   ra   r  r  resultrx   r   path_definitionswebhook_contextapi_webhookrJ   r  rN   get_openapi  s   






r-  )Pr   http.clientr   r   r   collections.abcr   typingr   r   r   fastapir   fastapi._compatr   r   r	   r
   r   r   fastapi.datastructuresr   r   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.sser   fastapi.typesr   fastapi.utilsr   r   r    pydanticr!   starlette.responsesr"   starlette.routingr#   r   r   rD   r   r   __annotations__tupler   r]   boolr   r   r   r   r   r$  r   r   RouteContextr  r  r-  rJ   rJ   rJ   rN   <module>   sV  
  


!
P
#


 $	
 ^

&	

