a
    bg
                     @   s\   d Z ddlmZ ddlmZmZ ddlmZ eddG dd dZde	e
ed	d
dZdS )z1Quick and dirty representation for OpenAPI specs.    )	dataclass)ListTupledereference_refsT)frozenc                   @   s<   e Zd ZU dZee ed< eed< eeeeef  ed< dS )ReducedOpenAPISpeczA reduced OpenAPI spec.

    This is a quick and dirty representation for OpenAPI specs.

    Parameters:
        servers: The servers in the spec.
        description: The description of the spec.
        endpoints: The endpoints in the spec.
    serversdescription	endpointsN)	__name__
__module____qualname____doc__r   dict__annotations__strr    r   r   }/var/www/html/cobodadashboardai.evdpl.com/venv/lib/python3.9/site-packages/langchain_community/agent_toolkits/openapi/spec.pyr   	   s   

r   )specdereferencereturnc                    sl   dd d   D }|r,fdd|D }ttddd  fdd|D }td	 d
 dd|dS )a  Simplify/distill/minify a spec somehow.

    I want a smaller target for retrieval and (more importantly)
    I want smaller results from retrieval.
    I was hoping https://openapi.tools/ would have some useful bits
    to this end, but doesn't seem so.

    Args:
        spec: The OpenAPI spec.
        dereference: Whether to dereference the spec. Default is True.

    Returns:
        ReducedOpenAPISpec: The reduced OpenAPI spec.
    c                 S   sH   g | ]@\}}|  D ].\}}|d v r|  d| |d|fqqS ))getpostpatchputdelete r
   )itemsupperr   ).0ZrouteZ	operationZoperation_namedocsr   r   r   
<listcomp>*   s   z'reduce_openapi_spec.<locals>.<listcomp>pathsc                    s$   g | ]\}}}||t | d fqS ))Zfull_schemar   r    namer
   r!   )r   r   r   r"   4   s   )r!   r   c                 S   sx   i }|  dr|  d|d< |  dr@dd |  dg D |d< d| d v r\| d d |d< |  drt|  d|d< |S )Nr
   
parametersc                 S   s   g | ]}| d r|qS )requiredr   )r    Z	parameterr   r   r   r"   ?   s   
zEreduce_openapi_spec.<locals>.reduce_endpoint_docs.<locals>.<listcomp>Z200	responsesZrequestBodyr(   )r!   outr   r   r   reduce_endpoint_docs:   s    




z1reduce_openapi_spec.<locals>.reduce_endpoint_docsc                    s    g | ]\}}}|| |fqS r   r   r$   )r+   r   r   r"   J   s   r	   infor
    )r	   r
   r   )r   r   r   r   )r   r   r   r   )r+   r   r   reduce_openapi_spec   s     
	

r.   N)T)r   dataclassesr   typingr   r   Z langchain_core.utils.json_schemar   r   r   boolr.   r   r   r   r   <module>   s   