
    k7i<                     R   S r SSKrSSKrSSKJr  SSKJrJrJr  \R                  " \
5      r SS\S\S\S	\\-  4S
 jjrS\S\S	\\\4   4S jrS\S-  S	\4S jrSS\S\S	\4S jjr  SS\S\\   S-  S\S-  S	\4S jjr  SS\S\\\4   S\\   S-  S\S-  S	\4
S jjr/ SQrg)z6Parameter formatting functions for OpenAPI operations.    N)Any   )
JsonSchemaParameterInfoRequestBodyInfovaluesparameter_nameis_query_parameterreturnc           	         [        S U  5       5      (       a  SR                  S U  5       5      $  / nU  H  n[        U[        5      (       aS  / nUR	                  5        H  u  pgUR                  U SU 35        M     UR                  SR                  U5      5        Mk  UR                  [        U5      5        M     SR                  U5      $ ! [         a  nU(       a  SOSn	[        R                  SU	 S	U S
U 35        U(       a  U s SnA$ [        U 5      R                  SS5      R                  SS5      R                  SS5      R                  SS5      n
U
s SnA$ SnAff = f)aJ  
Format an array parameter according to OpenAPI specifications.

Args:
    values: List of values to format
    parameter_name: Name of the parameter (for error messages)
    is_query_parameter: If True, can return list for explode=True behavior

Returns:
    String (comma-separated) or list (for query params with explode=True)
c              3   l   #    U  H*  n[        U[        [        -  [        -  [        -  5      v   M,     g 7fN)
isinstancestrintfloatbool).0items     k/home/james-whalen/.local/lib/python3.13/site-packages/fastmcp/experimental/utilities/openapi/formatters.py	<genexpr>)format_array_parameter.<locals>.<genexpr>   s(     
I&$:dC#I-455&s   24,c              3   8   #    U  H  n[        U5      v   M     g 7fr   )r   )r   vs     r   r   r      s     /1As   :.querypathzFailed to format complex array z parameter 'z': N[ ]'")alljoinr   dictitemsappendr   	Exceptionloggerwarningreplace)r   r	   r
   formatted_partsr   
item_partskr   e
param_type	str_values              r   format_array_parameterr4      sC    
I&
IIIxx//// D$%%
 JJLDA%%1QCj1 )&&sxx
';<&&s4y1  xx((  2W
-j\nEUUXYZX[\	
 M Fb!b!b!b!  %s+   BC 
E'1E"
E'AE"E'"E'param_valuec                     [        U [        5      (       d&  [        R                  SU S[	        U 5       35        0 $ 0 nU R                  5        H  u  p4U SU S3n[        U5      X%'   M     U$ )a  
Format a dictionary parameter for deepObject style serialization.

According to OpenAPI 3.0 spec, deepObject style with explode=true serializes
object properties as separate query parameters with bracket notation.

For example: {"id": "123", "type": "user"} becomes:
param[id]=123&param[type]=user

Args:
    param_value: Dictionary value to format
    parameter_name: Name of the parameter

Returns:
    Dictionary with bracketed parameter names as keys
zdeepObject style parameter 'z' expected dict, got r    r"   )r   r'   r+   r,   typer(   r   )r5   r	   resultkeyvaluebracketed_keys         r   format_deep_object_parameterr<   B   s~    & k4((*>*::OPTU`PaObc	
 	F!'')
)*!C52 #E
 *
 M    schemac                    U (       a  [        U [        5      (       d  gSU ;   a  U S   $ SU ;   a*  [        U S   [        5      (       a  U S   (       a  U S   S   $ SU ;   a*  [        U S   [        5      (       a  U S   (       a  U S   S   $ SU ;   a  U S   $ U R                  S5      nUS:X  a  0 nU R                  S	0 5      n[        U[        5      (       a|  [	        U R                  S
/ 5      5      n[        UR                  5       5      SS nU H  nXc;   d  M
  [        X6   5      X&'   M     U H   nXr;  d  M
  Xs;   d  M  [        X7   5      X''   M"     U(       a  U$ SS0$ US:X  a<  U R                  S5      n[        U[        5      (       a  [        U5      n	U	b  U	/$ / $ S/$ US:X  a5  U R                  S5      n
U
S:X  a  gU
S:X  a  gU
S:X  a  gU
S:X  a  gU
S:X  a  ggUS:X  a  gUS :X  a  g!US":X  a  g#US$:X  a  gg%)&zm
Generate a simple example value from a JSON schema dictionary.
Very basic implementation focusing on types.
unknowndefaultenumr   examplesexampler7   object
propertiesrequiredN   r9   r:   arrayr(   example_itemstringformatz	date-timez2024-01-01T12:00:00Zdatez
2024-01-01emailzuser@example.comuuidz$123e4567-e89b-12d3-a456-426614174000bytezZXhhbXBsZQ==integerr   numberg      ?booleanTnullunknown_type)r   r'   listgetsetkeysgenerate_example_from_schema)r>   schema_typer8   rF   required_propsprops_to_include	prop_namereq_propitems_schemaitem_exampleformat_types              r   rZ   rZ   d   s4   
 FD11 Fi  Jvf~t<<f~a   	fvj)400:j!!$$Fi  **V$KhZZb1
j$'' J!;<N#JOO$56  .	*(D"-)F% . +)h.D'C",(F$ +
  v5eW%55		zz'*lD))7EL%1%=L>E2E		 jj*+%)& '!%& 9& !			!		 			!		 r=   dataindentc                 d     [         R                  " XS9nSU S3$ ! [         a	    SU  S3s $ f = f)z8Formats Python data as a JSON string block for markdown.rd   z```json
z
```z!```
Could not serialize to JSON: )jsondumps	TypeError)rc   rd   json_strs      r   format_json_for_descriptionrk      sE    @::d28*E** @3D6??@s    //base_description
parametersrequest_bodyc                 F   U /nU(       a  U Vs/ s H)  oDR                   S:X  d  M  UR                  (       d  M'  UPM+     nnU(       aE  UR                  S5        U H.  nUR                  SUR                   SUR                   35        M0     SR	                  U5      $ s  snf )a  
Formats a simple description for MCP objects (tools, resources, prompts).
Excludes response details, examples, and verbose status codes.

Args:
    base_description (str): The initial description to be formatted.
    parameters (list[ParameterInfo] | None, optional): A list of parameter information.
    request_body (RequestBodyInfo | None, optional): Information about the request body.

Returns:
    str: The formatted description string with minimal details.
r   

**Path Parameters:**
- ****: 
)locationdescriptionr)   namer&   )rl   rm   rn   
desc_partsppath_paramsparams          r   format_simple_descriptionr{      s    " ##J ",W*Q

f0Dqq*W89$!!F5::,d5;L;L:M"NO % 99Z   Xs   BBB	responsesc           
      
  ^ U /nU(       Ga(  U Vs/ s H  oUR                   S:X  d  M  UPM     nnU(       aj  SnUR                  U5        U HQ  nUR                  (       a  SOSn	SUR                   SU	 SUR                  =(       d    S 3n
UR                  U
5        MS     U Vs/ s H  oUR                   S	:X  d  M  UPM     nnU(       aj  S
nUR                  U5        U HQ  nUR                  (       a  SOSn	SUR                   SU	 SUR                  =(       d    S 3n
UR                  U
5        MS     U(       Gac  UR                  (       GaQ  SnUR                  U5        UR                  (       a  SOSn	UR                  SUR                   U	 35        UR
                  (       a  SUR
                  ;   a  SO[        [        UR
                  5      S5      nU(       a  UR
                  R                  U0 5      n[        U[        5      (       a  SU;   a  UR                  S5        US   R                  5        Ha  u  nn[        U[        5      (       d  M  SU;   d  M%  XR                  S/ 5      ;   nU(       a  SOSnUR                  SU SU SUS    35        Mc     T(       Ga  SnSn1 Skn[        U4S jU 5       S5      nTR                  5       n[        U5       GHI  u  nnU(       d  UR                  U5        SnUU:X  a  SOSnUR                  SU SU SUR                  =(       d    S 35        UR
                  (       d  Mk  SUR
                  ;   a  SO[        [        UR
                  5      S5      nU(       d  M  UR
                  R                  U5      nUR                  SU S35        [        U[        5      (       Ga  UR                  S5      S:X  a  SU;   a  US   n[        U[        5      (       am  SU;   ag  UR                  S5        US   R                  5        H?  u  nn[        U[        5      (       d  M  SU;   d  M%  UR                  SU S US    35        MA     OmSU;   ag  UR                  S!5        US   R                  5        H?  u  nn[        U[        5      (       d  M  SU;   d  M%  UR                  SU S US    35        MA     U(       d  GM  [        U5      nUS":w  d  GM  Uc  GM  UR                  S#5        UR                  [        US$S%95        GML     SR                  U5      $ s  snf s  snf )&a$  
Formats the base description string with response, parameter, and request body information.

Args:
    base_description (str): The initial description to be formatted.
    responses (dict[str, Any]): A dictionary of response information, keyed by status code.
    parameters (list[ParameterInfo] | None, optional): A list of parameter information,
        including path and query parameters. Each parameter includes details such as name,
        location, whether it is required, and a description.
    request_body (RequestBodyInfo | None, optional): Information about the request body,
        including its description, whether it is required, and its content schema.

Returns:
    str: The formatted description string with additional details about responses, parameters,
    and the request body.
r   rp   z (Required)r!   rq   z**z: zNo description.r   z

**Query Parameters:**z

**Request Body:**rs   zapplication/jsonNrF   z

**Request Properties:**ru   rG   z

**Responses:**F>   200201202204c              3   6   >#    U  H  oT;   d  M
  Uv   M     g 7fr    )r   sr|   s     r   r   4format_description_with_responses.<locals>.<genexpr>5  s     J-Q	>qq-s   		Tz
 (Success)z  - Content-Type: ``r7   rI   r(   z"
  - **Response Item Properties:**z	
    - **rr   z
  - **Response Properties:**rU   z
  - **Example:**   rf   )rt   r)   rG   rv   ru   content_schemanextiterrW   r   r'   r(   sortedrZ   rk   r&   )rl   r|   rm   rn   rw   rx   ry   param_sectionrz   required_marker
param_descquery_paramsreq_body_section
media_typer>   r^   prop_schemarG   req_markresponse_sectionadded_response_sectionsuccess_codessuccess_statusresponses_to_processstatus_code	resp_infostatus_markerr`   rD   s    `                           r   !format_description_with_responsesr      s   0 ##J ",E*Q

f0Dq*E6Mm,$38>>-r%ejj\O3DBuGXGXGm\mFno
!!*- % $.G:aw1F:G7Mm,%38>>-r%ejj\O3DBuGXGXGm\mFno
!!*- & 0002*++7+@+@-bB|7788IJK && &)D)DD #$|::;TB 
 %4488RHfd++0F%%&CD282F2L2L2N.	;&{D99 - <'0JJz24N'NH8@}bH&--"(2hZr+mB\A] ^ 3O /!& 5J-JDQ  )0&,-A&B"K)!!"23)-&,7>,ILrMRb9N9N9cRc8de
 ''' *Y-E-EE 'd9#;#;<dC  :&5599*EF%%(;J<q&IJ "&$//!::f-8W=N+1'?L *< > >$0L$@ * 1 12W X>J$0?""'%'?*$:I{ )3;(E(E,9[,H(2(9(9.84TaHbGc,d)*?* *V3&--.NO:@:N:T:T:V 6	;$.{D$A$A(5(D$.$5$5*4YKtKP]D^C_(`%& ;W v">v"F"n49L&--.BC&-- ;GA Ny 'C@ 99Z  y F Hs   U U %U<U)r4   r<   r   rk   r{   rZ   )F)r   )NN)__doc__rg   loggingtypingr   modelsr   r   r   	getLogger__name__r+   rV   r   r   r4   r'   r<   rZ   r   rk   r{   r   __all__r   r=   r   <module>r      s]   <    > >			8	$ CH33"%3;?34Z3l'*	#s(^DPd): Ps Pf@c @3 @s @ .2+/!!]#d*! "D(! 		!L .2+/Y!Y!SY!
 ]#d*Y! "D(Y! 	Y!zr=   