
    k7i!3                        S r SSKJr  SSKJr  \" \5      r1 Skr\\\\	\	\	\S.r
    SS\\\4   S\S-  S	\S
\S\S\\\4   4S jjrS\\\4   S\\\4   4S jrS\\\4   S\4S jrS\\\4   S\4S jrS\\\4   S\S-  S	\S
\S\S\4S jrS\\\4   S	\S
\S\\\4   4S jr SS\\\4   S-  S\S-  S\\\4   4S jjrg)z
Clean OpenAPI 3.0 to JSON Schema converter for the experimental parser.

This module provides a systematic approach to converting OpenAPI 3.0 schemas
to JSON Schema, inspired by py-openapi-schema-to-json-schema but optimized
for our specific use case.
    )Any)
get_logger>   xmlnullablereadOnly	writeOnly
deprecatedexternalDocsdiscriminator)
propertiesitemsadditionalPropertiesallOfanyOfoneOfnotNschemaopenapi_versionremove_read_onlyremove_write_onlyconvert_one_of_to_any_ofreturnc                   ^  [        T [        5      (       d  T $ [        U 4S j[         5       5      =(       dZ    U=(       a    [	        T 5      =(       d?    U=(       a    [        T 5      =(       d$    U=(       a    ST ;   =(       d    [        T UUUU5      nU(       d  T $ T R                  5       nU(       a!  UR                  S5      (       a  [        U5      nU(       a  SU;   a  UR                  S5      US'   [         H  nUR                  US5        M     U(       d  U(       a  [        XbU5      n[        R                  5        H  u  pX;   d  M  U	[        L a  [        Xh   [        5      (       ak  US:X  aP  Xh   R                  5        V
Vs0 s H,  u  pU
[        U[        5      (       a  [        UUUUU5      OU_M.     snn
Xh'   M  [        Xh   UUUU5      Xh'   M  U	[        L d  M  [        Xh   [        5      (       d  M  Xh    Vs/ s H)  n[        U[        5      (       a  [        UUUUU5      OUPM+     snXh'   M     U$ s  snn
f s  snf )a  
Convert an OpenAPI schema to JSON Schema format.

This is a clean, systematic approach that:
1. Removes OpenAPI-specific fields
2. Converts nullable fields to type arrays (for OpenAPI 3.0 only)
3. Converts oneOf to anyOf for overlapping union handling
4. Recursively processes nested schemas
5. Optionally removes readOnly/writeOnly properties

Args:
    schema: OpenAPI schema dictionary
    openapi_version: OpenAPI version for optimization
    remove_read_only: Whether to remove readOnly properties
    remove_write_only: Whether to remove writeOnly properties
    convert_one_of_to_any_of: Whether to convert oneOf to anyOf

Returns:
    JSON Schema compatible dictionary
c              3   ,   >#    U  H	  oT;   v   M     g 7fN ).0fieldr   s     v/home/james-whalen/.local/lib/python3.13/site-packages/fastmcp/experimental/utilities/openapi/json_schema_converter.py	<genexpr>8convert_openapi_schema_to_json_schema.<locals>.<genexpr>F   s     A)@VO)@   r   z3.0r   Nr   )
isinstancedictanyOPENAPI_SPECIFIC_FIELDS_has_read_only_properties_has_write_only_properties_needs_recursive_processingcopy
startswith_convert_nullable_fieldpop_filter_properties_by_accessRECURSIVE_FIELDSr   %convert_openapi_schema_to_json_schemalist)r   r   r   r   r   needs_conversionresultr   
field_name
field_type	prop_nameprop_schemaitems   `            r   r0   r0   &   sV   6 fd## 	A)@AA 
	
B!:6!B
	
D"<V"D
	
 %:F):
	
 '$
   [[]F ?55e<<(0  Gv$5 **W-w )

5$ ) ,-&7

 #3"8"8":
T!j1CT&J&J- 7=6H6N6N6P* 7Q2I " &k488 $I'+,-4$ )) 7Q*F& *O*'()0*F& t#
63Et(L(L !' 2& !3 "$-- :'()0  !3&"5 #;N ME**&s   	3H>0Ic                 *   SU ;  a  U $ U R                  5       nUR                  S5      nU(       d  U$ SU;   aG  US   n[        U[        5      (       a  US/US'   O[        U[        5      (       a  SU;  a	  / UQSPUS'   OxSU;   a  / UR                  S5      QSS0PUS'   OWSU;   a1  [        S US    5       5      (       d  US   R                  SS05        O SU;   a  SUR                  S5      0SS0/US'   SU;   a  S	US   ;  a  US   S	/-   US'   U$ )
z9Convert OpenAPI nullable field to JSON Schema type array.r   typenullr   r   c              3   H   #    U  H  oR                  S 5      S:H  v   M     g7f)r:   r;   N)get)r   r8   s     r   r    *_convert_nullable_field.<locals>.<genexpr>   s     J/$88F#v-/s    "r   enumN)r*   r-   r#   strr1   r%   append)r   r3   nullable_valuecurrent_types       r   r,   r,      s;   [[]FZZ
+N f~lC((*F3F6Nd++l0J4|4V4F6N	F	BFJJw/B&&1ABw	F	J&/JJJ7O""FF#34	F	#VZZ%89FF;KLw Dv64&0vM    c                 V    SU ;  a  g[        S U S   R                  5        5       5      $ )z2Quick check if schema has any readOnly properties.r   Fc              3   r   #    U  H-  n[        U[        5      =(       a    UR                  S 5      v   M/     g7f)r   Nr#   r$   r=   r   props     r   r    ,_has_read_only_properties.<locals>.<genexpr>   s/      1D 	47488J#771   57r%   valuesr   s    r   r'   r'      5    6! <(//1  rD   c                 V    SU ;  a  g[        S U S   R                  5        5       5      $ )z3Quick check if schema has any writeOnly properties.r   Fc              3   r   #    U  H-  n[        U[        5      =(       a    UR                  S 5      v   M/     g7f)r   NrG   rH   s     r   r    -_has_write_only_properties.<locals>.<genexpr>   s/      1D 	48488K#881rK   rL   rN   s    r   r(   r(      rO   rD   c           	        ^ ^^^	 [         R                  5        GH\  u  mnTT ;   d  M  U[        L Gau  [        T T   [        5      (       Ga\  TS:X  a  T T   R	                  5        H  m	[        T	[        5      (       d  M  [        U	4S j[         5       5      =(       df    U=(       a    T	R                  S5      =(       dE    U=(       a    T	R                  S5      =(       d$    U=(       a    ST	;   =(       d    [        T	UUUU5      nU(       d  M      g   M  [        UU 4S j[         5       5      =(       df    U=(       a    [        T T   5      =(       dH    U=(       a    [        T T   5      =(       d*    U=(       a    ST T   ;   =(       d    [        T T   UUUU5      nU(       a    gGM  U[        L d  GM  [        T T   [        5      (       d  GM  T T    H  m[        T[        5      (       d  M  [        U4S j[         5       5      =(       dZ    U=(       a    [        T5      =(       d?    U=(       a    [        T5      =(       d$    U=(       a    ST;   =(       d    [        TUUUU5      nU(       d  M      g   GM_     g	)
zaCheck if the schema needs recursive processing (smarter than just checking for recursive fields).r   c              3   .   >#    U  H
  nUT;   v   M     g 7fr   r   )r   r   r7   s     r   r    ._needs_recursive_processing.<locals>.<genexpr>   s      $"1H %*[$81Hs   r   r   r   Tc              3   4   >#    U  H  nUTT   ;   v   M     g 7fr   r   )r   r   r4   r   s     r   r    rU      s"      )@ "VJ%77)@s   c              3   ,   >#    U  H	  oT;   v   M     g 7fr   r   )r   r   r8   s     r   r    rU     s     S;R%;Rr"   F)r/   r   r$   r#   rM   r%   r&   r=   r)   r'   r(   r1   )
r   r   r   r   r   r5   nested_needs_conversionr4   r8   r7   s
   `      @@@r   r)   r)      sE    #3"8"8":
JT!j
1CT&J&J-'-j'9'@'@'B%k488 # $"1H$" !" !" %5$T9T	!"
 %6$V+//+:V!" %=$WKAW!" $?$/$3$4$5$<$" 4   76'+' (C.  )@  
 - N 9&:L M . O :6*;M N 5VF:DV9V 7":.+,-4 ,, /# /t#
6*3Et(L(L":.D!$--S;RSS 
 0 T5Nt5T
 1 V6PQU6V
 !9 LW_
  ; $ / 0 1 8  0 32#'! /k #;L rD   c                    SU ;  a  U $ U R                  5       n0 nUS   R                  5        Hh  u  pV[        U[        5      (       d  XdU'   M   U=(       a    UR	                  S5      =(       d    U=(       a    UR	                  S5      nU(       a  Md  XdU'   Mj     XCS'   SU;   aB  U(       a;  US    Vs/ s H  oU;   d  M
  UPM     snUS'   US   (       d  UR                  S5        U$ s  snf )z8Remove readOnly and/or writeOnly properties from schema.r   r   r   required)r*   r   r#   r$   r=   r-   )	r   r   r   r3   filtered_propertiesr6   r7   should_removerI   s	            r   r.   r.     s     6![[]F"("6"<"<">	+t,,-8	*)Ikooj.I 
>+//+"> 	 }-8	* #? /< V 3#J/
/T;N3ND/
z j!JJz"M
s   2	C(?C(schema_definitionsc           
          U (       d  0 $ U R                  5        VVs0 s H  u  p4U[        XA40 UD6_M     snn$ s  snnf )aF  
Convert a dictionary of OpenAPI schema definitions to JSON Schema.

Args:
    schema_definitions: Dictionary of schema definitions
    openapi_version: OpenAPI version for optimization
    **kwargs: Additional arguments passed to convert_openapi_schema_to_json_schema

Returns:
    Dictionary of converted schema definitions
)r   r0   )r]   r   kwargsnamer   s        r   convert_schema_definitionsra   B  sN      	 /4466LD 	3FVvVV6  s   :)NFFTr   )__doc__typingr   fastmcp.utilities.loggingr   __name__loggerr&   r$   r1   r/   r@   boolr0   r,   r'   r(   r)   r.   ra   r   rD   r   <module>rh      s    0	H	     #'"#%)mcNm4Zm m 	m
 #m 
#s(^m`!DcN !tCH~ !Hd38n  tCH~ $ NcNN4ZN N 	N
 #N 
Nb cN .2 GK 	#s(^ J #'S#X-4Z 
#s(^	rD   