fL i UddlZddlZddlmZddlmZddlmZmZmZm Z ddl m Z ddl m Z ddlmZmZmZmZmZmZddlmZdd lmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)dd l*m+Z+dd l,m-Z-m.Z.dd l/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;mZ>ddl?m@Z@mAZAddlBmCZCmDZDmEZEmFZFmGZGmHZHmIZImJZJmKZKmLZLmMZMmNZNmOZOmPZPmQZQmRZRmSZSmTZTmUZUddlVmWZWmXZXmYZYmZZZm[Z[m\Z\m]Z]m^Z^m_Z_ddl`maZambZbmcZcer ddldmeZeddlfmgZgdZhdZie(e&de&e fZje$ejZkdedde!e<deelefddfdZmddddeidde#e(e&de&d fd!end"e!eld#e!eld$e!eld%eldeeleffd&Zoddeifd'e(e&de&d fd!end$e!eld%eldeeleff d(Zpddeeud?fd@eudAffZye%e%ele(ewe%ewd6ffelfd6fexdB<de>emm7@PQVQbQb@c+EMM:  $ $$ri)rjrmrn known_modelsrrrc t|\}}t|}|r|j|d}t|||||||xs t \} } } d| vr| | | fS|j| || | fS)a Process a Pydantic field and return a tuple with a JSON Schema for it as the first item. Also return a dictionary of definitions with models as keys and their schemas as values. If the passed field is a model and has sub-models, and those sub-models don't have overrides (as ``title``, ``default``, etc), they will be included in the definitions and referenced in the schema instead of included recursively. :param field: a Pydantic ``ModelField`` :param by_alias: use the defined alias (if any) in the returned schema :param model_name_map: used to generate the JSON Schema references to other models included in the definitions :param ref_prefix: the JSON Pointer prefix to use for references to other schemas, if None, the default of #/definitions/ will be used :param ref_template: Use a ``string.format()`` template for ``$ref`` instead of a prefix. This can be useful for references that cannot be represented by ``ref_prefix`` such as a definition stored in another file. For a sibling json file in a ``/schemas`` directory use ``"/schemas/${model}.json#"``. :param known_models: used to solve circular references :return: tuple of the schema for this field and additional definitions Trjrrrrmrnr$ref)rget_field_schema_validationsrwfield_type_schemarb) rZrjrrrmrnrsrvalidation_schemaf_schema f_definitionsf_nested_modelss rgr[r[s406A4U; "#/@ %)!!*SU0,Hm_77 -00ri max_length maxLength min_length minLengthregexpattern._str_types_attrsgtexclusiveMinimumltexclusiveMaximumgeminimumlemaximum multiple_of multipleOf_numeric_types_attrscdi}t|jtr=|jjr%|j |jj|St|jt tfr8tD]/\}}}t|j|d}t||s+|||<1t|jtrRt|jts8tD]/\}}}t|j|d}t||s+|||<1|j%|jjr|j |d<|jjr%|j |jjt|j"dd}|r t%||||S)z Get the JSON Schema validation keywords for a ``field`` with an annotation of a Pydantic ``FieldInfo`` with validation arguments. Nconst__modify_schema__)rUrr rextrarwstrbytesrgetattr isinstance numeric_types issubclassboolrrrrrh)rZr attr_nametkeywordattrrYs rgrr!si "H%++t,    ! ! OOE,,22 3%++U|4%5 ) !Iq'5++Y=D$"$(! )%++}5jVZ>[%9 ) !Iq'5++Y=D$"$(! ) #(8(8(>(>!MM ((../E--/BDIM]E8< Ori unique_modelsc`i}t}|D]t}t|j}||vrt|}|||<-||vr?|j ||j |}||t|<||t|<p|||<v|j Dcic]\}}|| c}}Scc}}w)a Process a set of models and generate unique names for them to be used as keys in the JSON Schema definitions. By default the names are the same as the class name. But if two models in different Python modules have the same name (e.g. "users.Model" and "items.Model"), the generated names will be based on the Python module path for those conflicting models to prevent name collisions. :param unique_models: a Python set of models :return: dict mapping models to names )rbnormalize_name__name__get_long_model_nameaddpopitems)rname_model_mapconflicting_namesrxrconflicting_modelkvs rgruruBsN"%% /#ENN3 * *,U3J).N: & > )  ! !* - . 2 2: > EVN./@A B9>N.u5 6).N: & /,113 4TQAqD 44 4s B*c|xs t}t}|j|||z}ttt|j j }|t||z}|S)a? Take a single ``model`` and generate a set with itself and all the sub-models in the tree. I.e. if you pass model ``Foo`` (subclass of Pydantic ``BaseModel``) as ``model``, and it has a field of type ``Bar`` (also subclass of ``BaseModel``) and that model ``Bar`` has a field of type ``Baz`` (also subclass of ``BaseModel``), the return value will be ``set([Foo, Bar, Baz])``. :param model: a Pydantic ``BaseModel`` subclass :param known_models: used to solve circular references :return: a set with the initial model and all its sub-models r)rbrr#rr3 __fields__valuesget_flat_models_from_fields)rxrrzfieldss rgrr]se (35L #KOOEKL (:&(8(8(?(?(A BF.vLQQK ricrddlm}t}|j}t t |dd|r |j }|jr(t ||s|t|j|z}|St ||r||vr|t||z}|St |tr|j||S)a Take a single Pydantic ``ModelField`` (from a model) that could have been declared as a subclass of BaseModel (so, it could be a submodel), and generate a set with its model and all the sub-models in the tree. I.e. if you pass a field that was declared to be of type ``Foo`` (subclass of BaseModel) as ``field``, and that model ``Foo`` has a field of type ``Bar`` (also subclass of ``BaseModel``) and that model ``Bar`` has a field of type ``Baz`` (also subclass of ``BaseModel``), the return value will be ``set([Foo, Bar, Baz])``. :param field: a Pydantic ``ModelField`` :param known_models: used to solve circular references :return: a set with the model used in the declaration for this field, if any, and all its sub-models rrW__pydantic_model__Nr) pydantic.v1.mainrXrbrrUrr sub_fieldsrrr r)rZrrXrz field_types rgget_flat_models_from_fieldrqs+ #KJ'*.BDI9U22   2:y I253C3CR^__  J 2z7U1*<XX   J - # rircHt}|D]}|t||z}|S)a Take a list of Pydantic ``ModelField``s (from a model) that could have been declared as subclasses of ``BaseModel`` (so, any of them could be a submodel), and generate a set with their models and all the sub-models in the tree. I.e. if you pass a the fields of a model ``Foo`` (subclass of ``BaseModel``) as ``fields``, and on of them has a field of type ``Bar`` (also subclass of ``BaseModel``) and that model ``Bar`` has a field of type ``Baz`` (also subclass of ``BaseModel``), the return value will be ``set([Foo, Bar, Baz])``. :param fields: a list of Pydantic ``ModelField``s :param known_models: used to solve circular references :return: a set with any model declared in the fields, and all their sub-models r)rbr)rrrzrZs rgrrs4!$KT1%lSS T ricDt}|D]}|t|z}|S)a_ Take a list of ``models`` and generate a set with them and all their sub-models in their trees. I.e. if you pass a list of two models, ``Foo`` and ``Bar``, both subclasses of Pydantic ``BaseModel`` as models, and ``Bar`` has a field of type ``Baz`` (also subclass of ``BaseModel``), the return value will be ``set([Foo, Bar, Baz])``. )rbr)rorzrxs rgrtrts0 !$K91%88 9 ricX|jd|jjddS)N__.) __module__ __qualname__rrxs rgrrs. r%"4"4!5 6 > >sD IIri)rrmc ddlm}i}t} |jtt t tttthvr\t||||||\} } } |j| | j| d| d} |jtthvrd| d<n|jtvrdd i} tt|j }t#|j$d d }t||||||\} } } |j| | j| |rt'j(|| i| d <| rZ| | d <nS|jt*k(s)|jt,k(rt/|j$|sg}tt0t|j2}|D]J}t5||||||\}}}|j|| j||j7|Lt9|}|jt,k(r|dk(r|dnd|d}d|gi} nrd||d} |dk\rg|| d<na|jt:t,hvsJ|jt|||||||\} } } |j| | j| |j$|j<k7rH|jt,k(r |j$}n |j<}t#|dd }|r t?||| | || fS)a  Used by ``field_schema()``, you probably should be using that function. Take a single ``field`` and generate the schema for its type only, not including additional information as title, etc. Also return additional schema definitions, from sub-models. rrWrjrrrmrnrarraytyperT uniqueItemsrobjectrNpatternPropertiesadditionalPropertiesallOf)rminItemsmaxItemsrrr) rrXrbshaper,r1r-r.r)r+r(field_singleton_schemarwr'r#r3 key_fieldrrr= _get_patternr0r*rrrrappendlenr/rrh)rZrjrrrnrrmrrXrsr items_schemarrrrr sub_schemarsf sf_schemasf_definitionssf_nested_modelssub_fields_lenall_of_schemasrrYs rgrrs +K!eM {{8N )!%% 8 4 m_ =)_-#l; ;;9o6 6&*H] # + +H%U__5  $77M )!%% 8 4 m_ =)_- .<-H-H-OQ],^H( ) /;H+ ,  # }(DZX]XcXcenMo $z*E,<,<=  )B:K!-%)) ; 7I~'7   ~ .  !1 2   i ( )Z ;;- '.<.AZ]PWblGmN.!12H **H "$.!{{ >>K K>3I )-!%%4 0- =)_- {{e''' ;;- 'J**J ,?F  x @ [- //ri)rjrmrnrrZc~ddlm}m}|xs t}t |t r1t tt |}t||} | itfSt td|}d|jjxs |ji} ||} | r| | d<|j|t||||||\} } } | j| |jj}t!|r1t#||j$dk(r || n|| |n| j|| | | fS) au Used by ``model_schema()``, you probably should be using that function. Take a single ``model`` and generate its schema. Also return additional schema definitions, from sub-models. The sub-models of the returned schema will be referenced, but their definitions will not be included in the schema. All the definitions are returned as the second value. r)getdocr^r`rXrkrlrr)rarr^rbrUr r#r enum_process_schema __config__rkrrmodel_type_schemarw schema_extracallablerrc)rxrjrrrmrnrrZrr^rdocr|r}rrs rgrvrv's'"*(35L%&T$Z' U 3"ce| k"E *E %""((:ENN;A -C -U-> %!! .*Hm]HHX##00L  y&11 2a 7 O E "  m] **ri)rmc i}g}i}t} |jjD]\} } t| |||||\} } }|j| | j||r8| || j<| js\|j| jx| || <| js|j| t|vr1|t}|jjxs |j |d<n d|d}|r||d<|jj"dk(rd|d <||| fS#t$r/}t j |jtYd}~8d}~wwxYw) a) You probably should be using ``model_schema()``, this function is indirectly used by that function. Take a single ``model`` and generate the schema for its type only, not including additional information as title, etc. Also return additional schema definitions, from sub-models. rNrkr)r propertiesrforbidFr)rbrrr[ SkipFieldwarningswarnmessage UserWarningrwrrrrSrrkrr)rxrjrrrnrmrrrrsrrfrrrskip out_schemas rgrrYscJH"$K!eM  &&(#1 7C!-%)) 8 4Hm_ =)_- "*Jqww zz($JqMzz"-#.:) #..44F 7&jA %-Jz " )-2 )* {M 11-  MM$,, 4  sD00 E(9$E##E(r`enumcddl}|j|j|jxsdt t t |Dcgc]}|jc}d}t||t|dd}|r t||||Scc}w)z Take a single `enum` and generate its schema. This is similar to the `model_process_schema` function, but applies to ``Enum`` objects. rNzAn enumeration.)rkrlrr) rarcleandoc__doc__r#rr valueadd_field_type_to_schemarrh)rrZraitemrrYs rgrrs '' (I8IJ(,Xd^T(BCC GT7+D"5t*95zF 9 95KbKb4"Ao   4B=N!-!1%))> :J):    /Gz$9(03  _g$>>/  $ $Z 0  !2 3+ 4,>O,'':+},,YFs0Hstringpath)rformatz date-timerrnumberz time-delta ipv4network ipv6network ipv4interface ipv6interfaceipv4ipv6rbinarybooleanintegeruuidrrr)rrrfield_class_to_schemaz json-stringrrc~tD]4\}}t||s||cxur tus n#|j|yy)a Update the given `schema` with the type-specific metadata for the given `field_type`. This function looks through `field_class_to_schema` for a class that matches the given `field_type`, and then modifies the given `schema` with the information from that type. N)r;rUrrw)rrrt_schemas rgrr$s<1x j% 0J%4R74R NN8 $  rinamecP|rd||zi}nd|j|i}|rd|giS|S)Nrrr)r/)r>rmrnr schema_refs rgrr2s@j4/0 l111=> &6Gj\ "FJFric ddlm}i}t} |j} |jr@|j r|j j s t| |st|||||||S| tus,| tus$| jtk(st| turi|| fSt| rddi|| fSt!| rt#d|j$di} |j %|j j r|j&| d <t)| rt+d t-| D} t/| D chc]} | jc} d kDrt1t3| |||||| S| dj} t5| | d <t7| | nt| t8rB|| }t;||\} }| j=t?||||tA| |||<ntC| rctE| jF||||||^}}t5|djI}| j=d|t/|t/|dn4tK| ds(t7| | tM| dd}|r tO||| | r| || fSttM| dd|r | jF} tQ| |rk|| }| |vr>tE| ||||||\}}}|j=||||<| j=|n| jS|t?||||}||| fStU| }||stV| jXvr| || fSt[d|cc} w)z This function is indirectly used by ``field_schema()``, you should probably be using that function. Take a single Pydantic ``ModelField``, and return its schema and any additional definitions from sub-models. rrWrrnullz Callable zC was excluded from schema since JSON schema has no equivalent type.Nrc3XK|]"}t|tr |jn|$ywN)rr r).0xs rg z)field_singleton_schema..hs"e*Q"5qww1<es(*rrrr`)rjrrrmrnrrZrr)rrrrrrz.Value not declarable with JSON Schema, field: ).rrXrbrrrrrUr,rr __class__r!rLrrQrNrr>rrOtuplerJrr[#multitypes_literal_field_for_schemalistrr rrwrrrPrvrrrrrhrrrKr __bases__ ValueError)rZrjrrrnrrmrrXrsrrrrr enum_namerr items_schemasrYrr*r+r@rfs rgrr:s+"$K!eMJ    e..44=OPZ\e=f0 )-!%%  SJ&0J4H4HG4SWablWmquWu; --Jm;; #)EJJ(>!MMz"eFXYcFdee V, , - 13FEB!-%))  AY(( < X6 J -":. %:5BR%S""y*lL\]^!4Zu!M I z "-  ) ))!%%  QZ 5<<>? & . .   Z!5 6 X6 ,?F  x @m33'*.BDI9U22 *i(#J/ \ )=Q!-%))> :J):    /&0K #  !2 3   j )#J LJZ[ ; 55 J D J4H4H)Hm33 EeWM NN[-s<M'rc jtt}|D] }||jj|"d|j D}t |j tt||j|j|j|j|j|jS)z To support `Literal` with values of different types, we split it into multiple `Literal` with same type e.g. `Literal['qwe', 'asd', 1, 2]` becomes `Union[Literal['qwe', 'asd'], Literal[1, 2]]` c3@K|]}tt|ywrD)r&rI)rEsame_type_valuess rgrGz6multitypes_literal_field_for_schema..sr>N'7!89rs)r>rclass_validators model_configrrrr)rrKrHrrr3r>r"rIrSrTrrrr)rrZliteral_distinct_typesrdistinct_literalss rgrJrJs ). 6q{{+22156rRhRoRoRqr  ZZE+,-//'' kk##  ridftcddlm}t||s t|rt dt |}t|t r6|jDcic]\}}t|t|c}}St|tr |jSt|tttfr|St|ttfr-|j }d|D}t#|r||S||S|yt |Scc}}w)NrrWzdict[str, Any]c32K|]}t|ywrD)r)rErs rgrGz!encode_default..s3!N1%3s)rrXrrr#r4dictrrr rintfloatrrKrIrHrP)rWrXrrrseq_argss rgrrs*#y!\#%6#%5c%:;#tADMAq!>!#44MM C yy C#uc* + C$ ' MM3s3,Q/q(|@Qx[@ $$NsD_map_types_constraint annotationr field_namevalidate_assignmentc|j}t}|rt||\}}|r|jd||z }|r!t d|ddj |d|S)a= Get an annotation with validation implemented for numbers and strings based on the field_info. :param annotation: an annotation from a field specification, as ``str``, ``ConstrainedStr`` :param field_info: an instance of FieldInfo, possibly with declarations for validations and JSON Schema :param field_name: name of the field for use in error messages :param validate_assignment: default False, flag for BaseModel Config value of validate_assignment :return: the same ``annotation`` if unmodified or a new annotation with validation in place allow_mutationz On field "z<" the following field constraints are set but not enforced: z, z\. For more details see https://docs.pydantic.dev/usage/schema/#unenforced-field-constraints)get_constraintsrbget_annotation_with_constraintsrrMjoin)r_rr`ra constraintsused_constraintsunused_constraintss rgget_annotation_from_field_inforjs,,.K!$'FzS]'^$ $-.$'77 $`yy+,-.j k  ricftdtdttffd |fS)a Get an annotation with used constraints implemented for numbers and strings based on the field_info. :param annotation: an annotation from a field specification, as ``str``, ``ConstrainedStr`` :param field_info: an instance of FieldInfo, possibly with declarations for validations and JSON Schema :return: the same ``annotation`` if unmodified or a new annotation along with the used constraints. rr\c Zts+ttsttt t frSt}| t}td|DrS|tur  |dSt|rtt fd|DSt|trm j  j" j$I j'hdt) |d j j" j$St|t*rV j j"> j'ddht- |d j j"St|t.rV j j"> j'ddht1 |d j j"St2tt*t.t4fD]'}t||s|t fd |DcSt|t6rt6|d |d fSd}d}tt8r[tt:t<frd }d t>d t@t>ffd }n(ttBrIttDtFfs3d}ttHrd t>d t@t>ffd }ntJ}nttLr3d}ttNrd t>d t@t>ffd }ntP}nttRr|ttTtVtXtt t tZfsMd}tt\r|dz }tt^r|dz }tafdtRD}tb|}|r] j'te| fd|DDcic] \}}||| } }}| r!tgthdt8f|}|di| SScc}}w)Nc3<K|]}t|tywrD)rr)rEas rgrGz>get_annotation_with_constraints..go..s;:a,;src3.K|] }|ywrDrErngos rgrGz>get_annotation_with_constraints..go..!"7Q2a5"7> max_items min_items unique_items)rvrurwrvru)rvruc3.K|] }|ywrDrprqs rgrGz>get_annotation_with_constraints..go..:rsrtr)rrkwr\c4tjf|SrDrrryrs rgconstraint_funczDget_annotation_with_constraints..go..constraint_funcEs"==ri)rrrc4tjf|SrDr{r|s rgr}zDget_annotation_with_constraints..go..constraint_funcL#ENNUHbAAric4tjf|SrDr{r|s rgr}zDget_annotation_with_constraints..go..constraint_funcUrri)rrrrr) allow_inf_nan) max_digitsdecimal_placesc3<K|]}t|s|ywrD)r)rErrs rgrGz>get_annotation_with_constraints..go..ls#U! 5RS@TA#Usc3:K|]}|t|fywrD)r)rErrs rgrGz>get_annotation_with_constraints..go..ss'kXaGJ 4R(S'ks.rp)5rOrrrUr;r<r9rLrKanyr%rRr"rIrrrvrurwrwrGrrHrrErrrrr?r>rr rr6r5rArIrr@rBrr:r8r7rr\r nextr^rbr#r) roriginrfrattrsr} numeric_typerrr_rrrrhs ` rgrrz+get_annotation_with_constraints..gos E "%,!%/>K_)`aLE"  $,UOD;d;; "$q'{"U"7$"7788&$'$$0''3**6 ''(RStAwK(22(22!+!8!8 &#&J,@,@,LPZPdPdPp ''k(BCbakZ5I5IU_UiUijj&),*2F2F2RV`VjVjVv ''k(BC#BtAwK:;O;O[e[o[oppT3 8< 9fa(U"7$"7788 9&$'DGRQ[011+/9= eT "%)[!9:4>#>$s)>E3' 58VBT0U=eY/BcBd3iB'-OE5)=e[1BcBd3iB'/OE=1*"$&#"( ;@eU+//EeW-==E##U}#UU "7 "E   # #CJ /(lej'k#It#4F "&xT ':O"L&000 s0P')rbrr )r_rrrrhs `@@rgreres:"%i#i$s)iV j>+ ++ric0tjdd|S)zU Normalizes the given name. This can be applied to either a model *or* enum. z[^a-zA-Z0-9.\-_]r)resub)r>s rgrr~s 66%sD 11ric eZdZdZdeddfdZy)rz? Utility exception used to exclude fields from schema. r r\Nc||_yrD)r )selfr s rg__init__zSkipField.__init__s  ri)rrrrrrrprirgrrsrir)FrD)rr collectionsr dataclassesrrrrrdecimalr rr ipaddressr r r rrrpathlibrtypingrrrrrrrrrrrrrrr r!r"r#r:r$typing_extensionsr%r&pydantic.v1.fieldsr'r(r)r*r+r,r-r.r/r0r1r2r3pydantic.v1.jsonr4pydantic.v1.networksr5r6pydantic.v1.typesr7r8r9r:r;r<r=r>r?r@rArBrCrDrErFrGrHrIpydantic.v1.typingrJrKrLrMrNrOrPrQrRpydantic.v1.utilsrSrTrUpydantic.v1.dataclassesrVrrXdefault_prefixdefault_ref_templateTypeModelOrEnum TypeModelSetrrhrrrrr[r[r\rrr__annotations__rrrurrrrtrrrvrrr,rrZrKrIrb frozensetr; json_schemerrrrJrr^rjrer Exceptionrrprirgrs4  #$44ff(0.1*   FE1*!.[)4:56?#  $I& $/7 /C $SWX[]`X`Sa $  $ !% $,2 U4 ,d;.??@ A22 C= 2 # 2  22 #s(^2n $, # k"D$55 6## # #  #s(^ #L%%t%PUVZ[^`c[cVdfjVjPk%2 $,+/01 0101#-. 01  01  01<(01 4S>4S>3s8 3401feW% =+.=+. c9P%c5uT3Y/?)?#@#EFKL =,- =,- =)$ =)$M<0 TeE#uT5s3C-C'Dc"IJCOP tCH~B5l5tOS4S>3s8 34t0t $,+/"&/+ /+/+#-. /+  /+  /+<(/+ J /+ 4S>4S>3s8 34/+p!% 32  3232#-. 32  32  3232 4S>4S>3s8 3432lLPd4jHZ4HTXY\^aYaTb@# $X- X-X-#-. X-  X-  X- X-X- 4S>4S>3s8 34X-| H /0 K89 H /0 H /0\:;8}=>8}=>XABXAB8v678v67 x73468  X 23 FI 69  VX  vx ! H /0 FH  Gb )* Wr *+7R =>2dCD1AuU3S#X#67<=6 =9   tCH~ $ GG(3-GsG^bGgkloqtltguG# $}O }O}O#-. }O  }O  }O }O}O 4S>4S>3s8 34}O@c3h Wa,%%%,:=feXW^`j8ktC#t)!445kZ_!*8;RV #Y:u,u,u,uUYZ]U^`cdg`hUhOiu,p222 ri