
    Ng
                         d Z ddlmZ ddlmZmZ ddlmZ  ed           G d d                      Zdd	e	d
e
defdZdS )z1Quick and dirty representation for OpenAPI specs.    )	dataclass)ListTupledereference_refsT)frozenc                   \    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        k/var/www/html/ai-engine/env/lib/python3.11/site-packages/langchain_community/agent_toolkits/openapi/spec.pyr
   r
   	   sV           $ZE#sD.)******r   r
   specdereferencereturnc                     d  d                                          D             }|r fd|D             }dt          dt          fdfd|D             }t           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                     g | ]R\  }}|                                 D ]8\  }}|d v 	|                                 d| |                    d          |f9SS ))getpostpatchputdelete r   )itemsupperr   ).0route	operationoperation_namedocss        r   
<listcomp>z'reduce_openapi_spec.<locals>.<listcomp>*   s       E9$-OO$5$5  !NDFFF   ""	,	,U	,	,dhh}.E.EtL GFFFr   pathsc                 @    g | ]\  }}}||t          |           fS ))full_schemar   )r%   namer   r)   r   s       r   r*   z'reduce_openapi_spec.<locals>.<listcomp>4   sD     
 
 
'k4 ; 04 H H HI
 
 
r   r)   r   c                 d   i }|                      d          r|                      d          |d<   |                      d          r#d |                      dg           D             |d<   d| d         v r| d         d         |d<   |                      d          r|                      d          |d<   |S )Nr   
parametersc                 <    g | ]}|                     d           |S )requiredr   )r%   	parameters     r   r*   zEreduce_openapi_spec.<locals>.reduce_endpoint_docs.<locals>.<listcomp>?   s:     ! ! !==,,!! ! !r   200	responsesrequestBodyr3   )r)   outs     r   reduce_endpoint_docsz1reduce_openapi_spec.<locals>.reduce_endpoint_docs:   s    88M"" 	9!%-!8!8C88L!! 	! !!%,!;!;! ! !C
 D%%%#K07C88M"" 	9!%-!8!8C
r   c                 4    g | ]\  }}}|| |          fS r   r   )r%   r.   r   r)   r9   s       r   r*   z'reduce_openapi_spec.<locals>.<listcomp>J   sB       #D+t 
{00667  r   r   infor    )r   r   r   )r#   r   r
   r   )r   r   r   r9   s   `  @r   reduce_openapi_specr=      s       $W 3 3 5 5  I  

 
 
 
+4
 
 
	4 D        '0  I YL$$]B77   r   N)T)r   dataclassesr   typingr   r    langchain_core.utils.json_schemar   r
   r   boolr=   r   r   r   <module>rB      s    7 7 ! ! ! ! ! !         = = = = = = $+ + + + + + + + 8 8d 8 8AS 8 8 8 8 8 8r   