
    hA                        S SK Jr  S SKrS SKrS SKJr  S SKJrJrJ	r	  SSK
JrJr  SrSS.     SS	 jjrSS
S.       SS jjrSS jrS rSS jrSS jrSS jr " S S5      rg)    )annotationsN)Iterable)AnyOptionalCallable   )inspectto_builtins)schemaschema_componentsschema_hookc               :    [        U 4US9u  u  p#U(       a  X2S'   U$ )a  Generate a JSON Schema for a given type.

Any schemas for (potentially) shared components are extracted and stored in
a top-level ``"$defs"`` field.

If you want to generate schemas for multiple types, or to have more control
over the generated schema you may want to use ``schema_components`` instead.

Parameters
----------
type : type
    The type to generate the schema for.
schema_hook : callable, optional
    An optional callback to use for generating JSON schemas of custom
    types. Will be called with the custom type, and should return a dict
    representation of the JSON schema for that type.

Returns
-------
schema : dict
    The generated JSON Schema.

See Also
--------
schema_components
r   z$defs)r   )typer   out
componentss       N/home/james-whalen/.local/lib/python3.13/site-packages/msgspec/_json_schema.pyr   r      s&    : +D7LFS!GJ    #/$defs/{name})r   ref_templatec          	       ^
 [         R                  " U 5      n[        U5      n[        U5      n[	        XQU5      m
[        U
4S jU 5       5      nUR                  5        VVs0 s H  u  pxXW   T
R                  US5      _M     n	nnXi4$ s  snnf )ag  Generate JSON Schemas for one or more types.

Any schemas for (potentially) shared components are extracted and returned
in a separate ``components`` dict.

Parameters
----------
types : Iterable[type]
    An iterable of one or more types to generate schemas for.
schema_hook : callable, optional
    An optional callback to use for generating JSON schemas of custom
    types. Will be called with the custom type, and should return a dict
    representation of the JSON schema for that type.
ref_template : str, optional
    A template to use when generating ``"$ref"`` fields. This template is
    formatted with the type name as ``template.format(name=name)``. This
    can be useful if you intend to store the ``components`` mapping
    somewhere other than a top-level ``"$defs"`` field. For example, you
    might use ``ref_template="#/components/{name}"`` if generating an
    OpenAPI schema.

Returns
-------
schemas : tuple[dict]
    A tuple of JSON Schemas, one for each type in ``types``.
components : dict
    A mapping of name to schema for any shared components used by
    ``schemas``.

See Also
--------
schema
c              3  F   >#    U  H  nTR                  U5      v   M     g 7fN)	to_schema).0tgens     r   	<genexpr>$schema_components.<locals>.<genexpr>_   s     9jCMM!$$js   !F)mimulti_type_info_collect_component_types_build_name_map_SchemaGeneratortupleitemsr   )typesr   r   
type_infoscomponent_typesname_mapschemasclsr   r   r   s             @r   r   r   0   s    N ##E*J.z:O/H
8,
?C9j99G >M=R=R=T=T63s}}Q..=T   s   "!B	c                >   ^^ 0 mUU4S jmU  H  nT" U5        M     T$ )zFind all types in the type tree that are "nameable" and worthy of being
extracted out into a shared top-level components mapping.

Currently this looks for Struct, Dataclass, NamedTuple, TypedDict, and Enum
types.
c                  > [        U [        R                  [        R                  [        R                  [        R
                  45      (       aF  U R                  T;  a5  U TU R                  '   U R                   H  nT" UR                  5        M     g g [        U [        R                  5      (       a  U TU R                  '   g [        U [        R                  5      (       a  T" U R                  5        g [        U [        R                  5      (       a  T" U R                  5        g [        U [        R                  5      (       a  U R                   H  nT" U5        M     g [        U [        R                  5      (       a%  T" U R                   5        T" U R"                  5        g [        U [        R$                  5      (       a  U R&                   H  nT" U5        M     g g r   )
isinstancer    
StructTypeTypedDictTypeDataclassTypeNamedTupleTyper,   fieldsr   EnumTypeMetadataCollectionType	item_type	TupleType
item_typesDictTypekey_type
value_type	UnionTyper'   )r   fstcollectr   s      r   rA   )_collect_component_types.<locals>.collectp   sD   r//1A1A2CTCTU
 
 uuJ&$%
155!AAFFO " ' 2;;'' !Jquu2;;''AFFO2,,--AKK 2<<((ll #2;;''AJJALL!2<<((gg  )r    )r(   r   rA   r   s     @@r   r"   r"   g   s*     J0 
  r   c                Z    [        U [        5      (       a  U R                  $ [        U 5      $ r   )r/   r   __name__repr)objs    r   
_type_reprrH      s!    %c4003<<?d3i?r   c                    [        U S5      (       a@  U R                  R                  nSR                  S U R                   5       5      nU SU S3$ U R                  $ )N
__origin__z, c              3  8   #    U  H  n[        U5      v   M     g 7fr   )rH   )r   as     r   r   "_get_class_name.<locals>.<genexpr>   s     =1A   [])hasattrrJ   rE   join__args__)r,   nameargss      r   _get_class_namerV      sS    sL!!~~&&yy===qa  <<r   c                   [        U S5      (       d   e[        U R                  SU R                  5      n[        USS5      nU(       d  g[        R                  " U5      R                  S5      n[        U [        R                  5      (       a
  US:X  a  g U$ [        U [        R                  [        R                  45      (       a:  UR                  UR                   S35      (       a  UR                  S5      (       a  gU$ )	Nr,   rJ   __doc__ z
zAn enumeration.())rQ   getattrr,   textwrapdedentstripr/   r    r5   r3   r2   
startswithrE   endswith)r   r,   docs      r   _get_docrc      s    1e
!%%quu
-C
#y"
%C
//#

$
$V
,C!R[[!!## $
 J 
A))2+;+;<	=	=>>S\\N!,--#,,s2C2CJr   c                D  ^	 S m	U	4S jn[        5       n0 nU  HZ  nT	" [        U5      5      nXS;   a,  UR                  U5      nUR                  U5        XcU" U5      '   XR;   a  XCU" U5      '   MV  XCU'   M\     UR	                  5        VVs0 s H  u  pxX_M	     snn$ s  snnf )zA mapping from nameable subcomponents to a generated name.

The generated name is usually a normalized version of the class name. In
the case of conflicts, the name will be expanded to also include the full
import path.
c                2    [         R                  " SSU 5      $ )Nz[^a-zA-Z0-9.\-_]_)resubrT   s    r   	normalize"_build_name_map.<locals>.normalize   s    vv)355r   c                F   > T" U R                    SU R                   35      $ )N.)
__module____qualname__)r,   rj   s    r   fullname!_build_name_map.<locals>.fullname   s%    CNN+1S-=-=,>?@@r   )setrV   popaddr&   )
r)   rp   	conflictsnamesr,   rT   oldkvrj   s
            @r   r#   r#      s    6A IE-.=))D/CMM$#&(3- #&(3- $K  #[[]+]TQAD]+++s   
Bc                  >    \ rS rSr  S     SS jjrSS	S jjrSrg)
r$      Nc                (    Xl         X l        X0l        g r   )r*   r   r   )selfr*   r   r   s       r   __init___SchemaGenerator.__init__   s     !&(r   c           	        0 n[        U[        R                  5      (       aM  [        R                  " X1R                  5      nUR
                  n[        U[        R                  5      (       a  MM  U(       a[  [        US5      (       aJ  U R                  R                  UR                  5      =n(       a  U R                  R                  US9US'   U$ [        U[        R                  [        R                  45      (       a   U$ [        U[        R                  5      (       a  SUS'   U$ [        U[        R                  5      (       a  SUS'   U$ [        U[        R                   [        R"                  45      (       a  [        U[        R                   5      (       a  SOSUS'   UR$                  b  UR$                  US
'   UR&                  b  UR&                  US'   UR(                  b  UR(                  US'   UR*                  b  UR*                  US'   UR,                  b  UR,                  US'   U$ [        U[        R.                  5      (       a[  SUS'   UR0                  b  UR0                  US'   UR2                  b  UR2                  US'   UR4                  b  UR4                  US'   U$ [        U[        R6                  [        R8                  [        R:                  45      (       aV  SUS'   SUS'   UR0                  b  SUR0                  S-   S-  -  US'   UR2                  b  SUR2                  S-   S-  -  US'   U$ [        U[        R<                  5      (       a  SUS'   UR>                  SL a  SUS'   U$ [        U[        R@                  5      (       a1  SUS'   UR>                  SL a  SUS'   U$ UR>                  SL a  SUS'   U$ [        U[        RB                  5      (       a  SUS'   SUS'   U$ [        U[        RD                  5      (       a  SUS'   SUS'   U$ [        U[        RF                  5      (       a  SUS'   S US'   U$ [        U[        RH                  5      (       a  SUS'   S!US'   U$ [        U[        RJ                  5      (       a  S"US'   [        URL                  [        R                  5      (       d  U RO                  URL                  5      US#'   UR0                  b  UR0                  US$'   UR2                  b  UR2                  US%'   U$ [        U[        RP                  5      (       ah  S"US'   [S        URT                  5      =US%'   US$'   URT                  (       a3  URT                   Vs/ s H  oPRO                  U5      PM     snUS&'   SUS#'   U$ [        U[        RV                  5      (       Ga  S'US'   [        URX                  =n[        R.                  5      (       aa  0 nUR2                  b  UR2                  US'   UR0                  b  UR0                  US'   UR4                  b  UR4                  US'   U(       a  XsS('   [        URZ                  [        R                  5      (       d  U RO                  URZ                  5      US)'   UR0                  b  UR0                  US*'   UR2                  b  UR2                  US+'   U$ [        U[        R\                  5      (       Ga  0 n/ n	S	n
UR^                   H  nUn[        U[        R                  5      (       a-  UR
                  n[        U[        R                  5      (       a  M-  [        U[        R`                  5      (       a-  URb                  (       d  URd                  n
XURf                  '   M  U	Ri                  U5        M     U	 Vs/ s H  oRO                  U5      PM     nn[S        U5      S:  a  URk                  5        VVs0 s H6  u  nnXR                  R                  U R                  UR                     S9_M8     nnnURm                  5        Vs/ s H  nU RO                  U5      PM     snU
US,.S-.nU(       a  URi                  U5        XS.'   U$ URo                  U5         U$ [S        U5      S/:X  a9  URq                  5       u  nnURi                  U RO                  U5      5        XS.'   U$ XS.'    U$ [        U[        Rr                  5      (       a  [u        URl                  5      US0'   U$ [        U[        Rv                  5      (       ak  URy                  S1UR                  Rz                  5        [}        U5      =n(       a  URy                  S2U5        [u        S3 UR                   5       5      US0'   U$ [        U[        R`                  5      (       Gag  URy                  S1[        UR                  5      5        [}        U5      =n(       a  URy                  S2U5        / n/ n/ nURd                  bT  URi                  URd                  5        URi                  URd                  5        URi                  S0URf                  /05        UR                   H  nU RO                  UR
                  5      nUR                  (       a  URi                  UR                  5        OlUR                  [        R                  La  [        UR                  SS49US5'   O7UR                  [        [        [        [        4;   a  UR                  5       US5'   URi                  UR                  5        URi                  U5        M     URb                  (       ay  S6n[        [        UR                  5      5       H  u  nnUR                  (       d  M    O   S"US'   UUS&'   [S        U5      U-
  US%'   UR                  (       a  [S        U5      US$'   U$ S'US'   [        [        UU5      5      US7'   UUS8'   UR                  (       a  SUS)'   U$ [        U[        R                  [        R                  [        R                  45      (       Gav  URy                  S1[        UR                  5      5        [}        U5      =n(       a  URy                  S2U5        / n/ n/ nUR                   H  nU RO                  UR
                  5      nUR                  (       a  URi                  UR                  5        O4UR                  [        R                  La  [        UR                  SS49US5'   URi                  UR                  5        URi                  U5        M     [        U[        R                  5      (       a(  S"US'   UUS&'   [S        U5      US%'   [S        U5      US$'   U$ S'US'   [        [        UU5      5      US7'   UUS8'    U$ [        U[        R                  5      (       a  [        S95      e[        U[        R                  5      (       af  U R                  (       a1   [        R                  " U R                  UR                  5      U5      nU(       d  [        S:UR                  < S;35      e U$ [        S<U< 35      es  snf s  snf s  snnf s  snf ! [         a     NTf = f)=z!Converts a Type to a json-schema.r,   ri   z$refnullr   booleanintegernumberNminimumexclusiveMinimummaximumexclusiveMaximum
multipleOfstring	maxLength	minLengthpatternbase64contentEncoding         Tz	date-timeformattimeFzpartial-timedatedurationuuiddecimalarrayr&   maxItemsminItemsprefixItemsobjectpropertyNamesadditionalPropertiesmaxPropertiesminProperties)propertyNamemapping)anyOfdiscriminatorr   r   enumtitledescriptionc              3  8   #    U  H  oR                   v   M     g 7fr   )value)r   es     r   r   -_SchemaGenerator.to_schema.<locals>.<genexpr>b  s     #;UGGUrN   )str_keysdefaultr   
propertiesrequiredz-json-schema doesn't support msgpack Ext typeszGenerating JSON schema for custom types requires either:
- specifying a `schema_hook`
- annotating the type with `Meta(extra_json_schema=...)`

type z is not supportedz!json-schema doesn't support type )Wr/   r    r6   _merge_jsonextra_json_schemar   rQ   r*   getr,   r   r   AnyTypeRawTypeNoneTypeBoolTypeIntType	FloatTypegegtleltmultiple_ofStrType
max_length
min_lengthr   	BytesTypeByteArrayTypeMemoryViewTypeDateTimeTypetzTimeTypeDateTypeTimeDeltaTypeUUIDTypeDecimalTyper7   r8   r   r9   lenr:   r;   r<   r=   r>   r'   r0   
array_like	tag_fieldtagappendr&   valuesupdatepopitemLiteralTypesortedr5   
setdefaultrE   rc   rV   r4   r   encode_namer   	NODEFAULTr
   default_factorylistdictrr   	bytearray	enumeratereversedforbid_unknown_fieldszipr1   r2   r3   ExtType	TypeError
CustomTyper   NotImplementedError)r}   r   	check_refr   rT   ir<   property_namesstructsotherr   subtype	real_typerL   optionsrx   ry   r   struct_schemarf   rb   r   rv   r4   fieldfield_scheman_trailing_defaultsr?   s                               r   r   _SchemaGenerator.to_schema   s   !#BKK((^^F,?,?@FA BKK(( E**}}((//t/!%!2!2!9!9t!9!Dva"**bjj122l k 2;;''#F6Nh g 2;;''&F6Nd c BJJ566*4Q

*C*CYF6Ntt$%DDy!tt-.TT)*tt$%DDy!tt-.TT)*}}('(}}|$L K 2::&&%F6N||'&'ll{#||'&'ll{#yy$$%IIy!| { BLL"*:*:B<M<MNOO%F6N(0F$%||'&'ALL1,<+B&C{#||'&'ALL1,<+B&C{#n m 2??++%F6Nttt|#.x f e 2;;''%F6Nttt|#)x ^ ] #1x Z Y 2;;''%F6N%F8T S 2++,,%F6N)F8N M 2;;''%F6N%F8H G 2>>**%F6N(F8B A 2,,--$F6Nakk2::66"&.."=w||'%&\\z"||'%&\\z"r q 2<<(($F6N69!,,6GGF:
!3||DELL(QLq):L(Q}%"'wf e 2;;''%F6Najj0("**==13&&22:2E2EN;/&&22:2E2EN;/##/080@0@N9-!.<?+allBJJ77151M-.||'*+,,'||'*+,,'@  2<<((GEI77#	 BKK88 )I !BKK88i77	@T@T ) 3 3I-6IMM*LL) # 388%Q~~a(%G87|q  !( /1 ((//T]]1555I/JJ /  
 :A9IJ9IAdnnQ/9IJ6?G%T! NN=1&-7OH E MM-0D C W"$__.
7t~~g67")w| y #*wx w 2>>**#AHH-F6Nt s 2;;''gquu~~6qk!s!!!-5##;QUU#;;F6Nj i 2==))gquu'=>qk!s!!!-5HEF{{&,Q[[)vw/0#~~ejj9>>OOE$5$56]]",,6.9%--RV.WL+**tT3	.JJ.3.C.C.EL+U../l+ " ||&'#.78J.K*'zzz /L ")v(.}%%([3F%Fz"**),VF:&f c "*v'+Cv,>'?|$%-z"**5:F12Z Y B,,b.>.>@Q@QRSSgquu'=>qk!s!!!-5EFH#~~ejj9>>OOE$5$56]]",,6.9%--RV.WL+U../l+ " !R..//!(v(.}%%(]z"%([z"2 / "*v'+Cv,>'?|$%-z"* ) 2::&&KLL2==))^^D,<,<QUU,CVLF  EE9$5	7    ?uEFFe )RF 9
 Kv + s*   ;z.<z3:=z8z>0{ 
{{)r*   r   r   )Nr   )r*   dict[Any, str]r   *Optional[Callable[[type], dict[str, Any]]]r   str)T)r   mi.Typer   boolreturndict[str, Any])rE   rn   ro   __firstlineno__r~   r   __static_attributes__rC   r   r   r$   r$      s:     CG,	) ) @) 	)d dr   r$   )r   r   r   r   r   r   )r'   zIterable[Any]r   r   r   r   r   z1tuple[tuple[dict[str, Any], ...], dict[str, Any]])r(   zIterable[mi.Type]r   dict[Any, mi.Type])r,   r   r   r   )r   r   r   r   )r)   r   r   r   )
__future__r   rg   r]   collections.abcr   typingr   r   r   rY   r	   r    r
   __all__r   r   r"   rH   rV   rc   r#   r$   rC   r   r   <module>r      s    " 	  $ * * (
) MQ 
 I  L ?C(	44 <4 	4
 74n$N@ ,<o or   