
    h
                     r    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y)z1Quick and dirty representation for OpenAPI specs.    )	dataclass)ListTuple)dereference_refsT)frozenc                   H    e Zd ZU dZee   ed<   eed<   eeeeef      ed<   y)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        m/var/www/html/eduruby.in/venv/lib/python3.12/site-packages/langchain_community/agent_toolkits/openapi/spec.pyr	   r	   	   s/     $ZE#sD.)**r   r	   specdereferencereturnc                    | d   j                         D cg c]H  \  }}|j                         D ]0  \  }}|dv r'|j                          d| |j                  d      |f2 J }}}}}|r%|D cg c]  \  }}}||t        ||       f }}}}dt        dt        fd}	|D cg c]  \  }}}|| |	|      f }}}}t        | d	   | d
   j                  dd      |      S c c}}}}w c c}}}w c c}}}w )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.
    paths)getpostpatchputdelete r   )full_schemadocsr   c                 V   i }| j                  d      r| j                  d      |d<   | j                  d      r4| j                  dg       D cg c]  }|j                  d      r| c}|d<   d| d   v r| d   d   |d<   | j                  d      r| j                  d      |d<   |S c c}w )Nr   
parametersrequired200	responsesrequestBody)r   )r#   out	parameters      r   reduce_endpoint_docsz1reduce_openapi_spec.<locals>.reduce_endpoint_docs:   s    88M"!%-!8C88L! "&,!;!==, !C
 D%%#K07C88M"!%-!8C
!s   B&r
   info )r
   r   r   )itemsupperr   r   r   r	   )
r   r   route	operationoperation_namer#   r   namer   r,   s
             r   reduce_openapi_specr5      sJ   $ !%W 3 3 5 E9$-OO$5 !NDFF   "#1UG	,dhh}.EtLLI   ,5
 
'k4 ; 04 HI
	 
4 D $ (1 #D+t 
{067I  YL$$]B7 I
,s   AC&
3C.(C5N)T)r   dataclassesr   typingr   r    langchain_core.utils.json_schemar   r	   r   boolr5   r   r   r   <module>r:      sJ    7 !  = $+ + + 8d 8 8AS 8r   