
    @|h]                       d Z ddlmZ ddlZddlZddlmZ ddlmZ ddl	m
Z
 ddlmZmZmZmZmZ dd	lmZmZmZ ej*                  rdd
lmZ g dZedgz   ZeedZ e
d      Z e
d      Z G d d      Z G d d      Zy)z#Core apispec classes and functions.    )annotationsN)Sequence)deepcopy)Version   )APISpecErrorDuplicateComponentNameErrorDuplicateParameterErrorInvalidParameterErrorPluginMethodNotImplementedError)COMPONENT_SUBSECTIONSbuild_reference
deepupdate)
BasePlugin)getpostputpatchdeleteheadoptionstrace)      z2.0z4.0c                  h   e Zd ZdZ	 	 	 	 	 	 ddZddZdd	 	 	 	 	 	 	 	 	 ddZ	 	 	 	 	 	 ddZ	 	 	 	 	 	 ddZ	 ddd	 	 	 	 	 	 	 	 	 dd
Z		 ddd	 	 	 	 	 	 	 	 	 ddZ
	 ddd	 	 	 	 	 	 	 	 	 	 	 ddZdd	 	 	 	 	 	 	 	 	 d dZdd	 	 	 	 	 	 	 d!dZd"dZd#dZd#dZd$dZd#dZd#dZd#dZd#dZd#dZy	)%
ComponentszStores OpenAPI components

    Components are top-level fields in OAS v2.
    They became sub-fields of "components" top-level field in OAS v3.
    c                   || _         || _        i | _        i | _        i | _        i | _        i | _        i | _        i | _        i | _	        i | _
        i | _        i | _        | j                  | j                  | j                  | j
                  | j                  | j                  d| _        | j                  | j                  | j                  | j                  | j                  d| _        y )N)schemaresponse	parameterheaderexamplesecurity_scheme)r   r   r    r!   r"   )_pluginsopenapi_versionschemas	responses
parametersheadersexamplessecurity_schemesschemas_lazyresponses_lazyparameters_lazyheaders_lazyexamples_lazy_subsections_subsections_lazy)selfpluginsr%   s      K/var/www/html/test/engine/venv/lib/python3.12/site-packages/apispec/core.py__init__zComponents.__init__*   s    
  .(**,+-(*)+13-//102-/.0 llll}}#44
 ''++--''))"
    c                    | j                   j                         D ci c]+  \  }}|i k7  r!t        | j                  j                     |   |- c}}S c c}}w N)r1   itemsr   r%   major)r3   kvs      r5   to_dictzComponents.to_dictM   sY     ))//1
1Bw "$"6"6"<"<=a@!C
 	
 
s   0AFlazyc               L    |du r| j                   n| j                  |   }|||<   y )NF)r1   r2   )r3   obj_typecomponent_id	componentr@   
subsections         r5   _register_componentzComponents._register_componentT   s1     ,05=d''d>T>T

 $-
< r7   c                n    | j                   |   }||v r"|j                  |      | j                  |   |<   y y r9   )r2   popr1   )r3   rB   rC   component_buffers       r5   _do_register_lazy_componentz&Components._do_register_lazy_componenta   sF    
  11(;++8H8L8L9Dh'5 ,r7   c                    t        |t              r|S | j                  ||       t        || j                  j
                  |      S )a  Return object or reference

        If obj is a dict, it is assumed to be a complete description and it is returned as is.
        Otherwise, it is assumed to be a reference name as string and the corresponding $ref
        string is returned.

        :param str subsection: "schema", "parameter", "response" or "security_scheme"
        :param dict|str obj: object in dict form or as ref_id string
        )
isinstancedictrJ   r   r%   r;   )r3   rB   obj_or_component_ids      r5   get_refzComponents.get_refm   sG     )40&&((3FGd**002E
 	
r7   Nc               :   || j                   v rt        d| d      t        |      xs i }| j                  D ]*  }	 |j	                   |j
                  ||fi |xs i        , | j                  |       | j                  d|||       | S # t        $ r Y `w xY w)aw  Add a new schema to the spec.

        :param str component_id: identifier by which schema may be referenced
        :param dict component: schema definition
        :param bool lazy: register component only when referenced in the spec
        :param kwargs: plugin-specific arguments

        .. note::

            If you are using `apispec.ext.marshmallow`, you can pass fields' metadata as
            additional keyword arguments.

            For example, to add ``enum`` and ``description`` to your field: ::

                status = fields.String(
                    required=True,
                    metadata={
                        "description": "Status (open or closed)",
                        "enum": ["open", "closed"],
                    },
                )

        https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#schemaObject
        zAnother schema with name "" is already registered.r   r?   )	r&   r	   r   r$   updateschema_helperr   _resolve_refs_in_schemarF   r3   rC   rD   r@   kwargsretplugins          r5   r   zComponents.schema   s    @ 4<<'-,\N:RS  y!'Rmm 	F

/6//cLVLRPRS	
 	$$S)  <4 H	 3 s   'B	BBc               8   || j                   v rt        d| d      t        |      xs i }| j                  D ])  }	 |j	                   |j
                  |fi |xs i        + | j                  |       | j                  d|||       | S # t        $ r Y _w xY w)a  Add a response which can be referenced.

        :param str component_id: ref_id to use as reference
        :param dict component: response fields
        :param bool lazy: register component only when referenced in the spec
        :param kwargs: plugin-specific arguments
        zAnother response with name "rQ   r   r?   )	r'   r	   r   r$   rR   response_helperr   _resolve_refs_in_responserF   rU   s          r5   r   zComponents.response   s     4>>)-.|n<TU  y!'Rmm 	F

1611#@@FBG	
 	&&s+  \3T J	 3    &B	BBc               z   || j                   v rt        d| d      t        |      xs i }|j                  d|       ||d<   |dk(  rd|d<   | j                  D ])  }	 |j                   |j                  |fi |xs i        + | j                  |       | j                  d|||	       | S # t        $ r Y _w xY w)
ai  Add a parameter which can be referenced.

        :param str component_id: identifier by which parameter may be referenced
        :param str location: location of the parameter
        :param dict component: parameter fields
        :param bool lazy: register component only when referenced in the spec
        :param kwargs: plugin-specific arguments
        zAnother parameter with name "rQ   nameinpathTrequiredr    r?   )
r(   r	   r   
setdefaultr$   rR   parameter_helperr   $_resolve_refs_in_parameter_or_headerrF   )r3   rC   locationrD   r@   rV   rW   rX   s           r5   r    zComponents.parameter   s    " 4??*-/~=UV  y!'Rv|,D	 v"C
O mm 	F

26223A&AGRH	
 	11#6  lCd K	 3 s   &B..	B:9B:c               8   t        |      xs i }|| j                  v rt        d| d      | j                  D ])  }	 |j	                   |j
                  |fi |xs i        + | j                  |       | j                  d|||       | S # t        $ r Y _w xY w)a  Add a header which can be referenced.

        :param str component_id: identifier by which header may be referenced
        :param dict component: header fields
        :param bool lazy: register component only when referenced in the spec
        :param kwargs: plugin-specific arguments

        https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md#headerObject
        zAnother header with name "rQ   r!   r?   )	r   r)   r	   r$   rR   header_helperr   rd   rF   rU   s          r5   r!   zComponents.header   s    " y!'R4<<'-,\N:RS  mm 	F

/6//>v>D"E	
 	11#6  <4 H	 3 r\   c               j    || j                   v rt        d| d      | j                  d|||       | S )a]  Add an example which can be referenced

        :param str component_id: identifier by which example may be referenced
        :param dict component: example fields
        :param bool lazy: register component only when referenced in the spec

        https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md#exampleObject
        zAnother example with name "rQ   r"   r?   )r*   r	   rF   )r3   rC   rD   r@   s       r5   r"   zComponents.example  sH     4==(--l^;ST  	  L)$ Or7   c                f    || j                   v rt        d| d      | j                  d||       | S )zAdd a security scheme which can be referenced.

        :param str component_id: component_id to use as reference
        :param dict component: security scheme fields
        z#Another security scheme with name "rQ   r#   )r+   r	   rF   )r3   rC   rD   s      r5   r#   zComponents.security_scheme)  sF     4000-5l^C[\  	  !2L)Lr7   c                f    d|v r-| j                  d|d         |d<   | j                  |d          yy)zpReplace schema reference as string with a $ref if needed

        Also resolve references in the schema
        r   NrO   rT   )r3   objs     r5   _resolve_schemazComponents._resolve_schema6  s:    
 s? LL3x=ACM((X7 r7   c                    |j                  di       j                         D ]  \  }}| j                  d|      |d   |<    y)z/Replace example reference as string with a $refr*   r"   N)r   r:   rO   )r3   rl   r^   r"   s       r5   _resolve_exampleszComponents._resolve_examples?  sD     WWZ4::< 	EMD'$(LLG$DC
OD!	Er7   c                   d|v r?|d   D ]7  }| j                  d|d   |         |d   |<   | j                  |d   |          9 d|v r,| j                  d|d         |d<   | j                  |d          dD ]H  }||v s||   D cg c]  }| j                  d|       c}||<   ||   D ]  }| j                  |        J d|v r-| j                  d|d         |d<   | j                  |d          y y c c}w )N
propertiesr   r:   )allOfoneOfanyOfnotrk   )r3   r   keysschs        r5   rT   z"Components._resolve_refs_in_schemaD  s-   6!l+ H,0LLf\237-|$S) ,,VL-A#-FG	H
 f"ll8VG_EF7O((9. 	6Cf}BH+NQt||Ha8Ns!#; 6C0056	6
 F? LL6%=AF5M((7  Os   C3c                    | j                  |       | j                  |       |j                  di       j                         D ]  }| j                  |        y Ncontent)rm   ro   r   values)r3   parameter_or_header
media_types      r5   rd   z/Components._resolve_refs_in_parameter_or_headerW  sS    0123-11)R@GGI 	-J  ,	-r7   c                x    |d   j                         D ]$  }| j                  |       | j                  |       & y rz   )r|   rm   ro   )r3   request_bodyr~   s      r5   _resolve_refs_in_request_bodyz(Components._resolve_refs_in_request_body^  s;    &y188: 	/J  ,"":.	/r7   c                   | j                   j                  dk  r| j                  |       y |j                  di       j	                         D ]$  }| j                  |       | j                  |       & |j                  di       j                         D ]4  \  }}| j                  d|      |d   |<   | j                  |d   |          6 y )Nr   r{   r)   r!   )	r%   r;   rm   r   r|   ro   r:   rO   rd   )r3   r   r~   r^   r!   s        r5   r[   z$Components._resolve_refs_in_responsed  s    %%)  *&ll9b9@@B 3
$$Z0&&z23 !)Y ; A A C Uf,0LL6,J#D)99(9:Md:STUr7   c                
   d|v rEg }|d   D ]6  }| j                  d|      }| j                  |       |j                  |       8 ||d<   d|v rO|d   j                         D ]9  }t	        |t
              s|j                         D ]  }| j                  |        ; d|v r| j                  |d          d|v rKi }|d   j                         D ]-  \  }}| j                  d|      }| j                  |       |||<   / ||d<   y y )Nr(   r    	callbacksrequestBodyr'   r   )
rO   rd   appendr|   rL   rM   resolve_refs_in_pathr   r:   r[   )	r3   	operationr(   r    callbackr`   r'   coder   s	            r5   _resolve_refs_in_operationz%Components._resolve_refs_in_operationp  s1   9$J&|4 -	 LLi@	99)D!!),- '1Il#)#%k299; 8h- ( 1 811$788 I%..y/GH)#I"+K"8">">"@ +h<<
H=..x8"*	$+ &/Ik" $r7   c                    d|v rEg }|d   D ]6  }| j                  d|      }| j                  |       |j                  |       8 ||d<   dD ]  }||v s| j                  ||           y )Nr(   r    )r   r   r   r   r   r   r   r   )rO   rd   r   r   )r3   r`   r(   r    methods        r5   r   zComponents.resolve_refs_in_path  s    4J!,/ -	 LLi@	99)D!!),- ",D	
 	>F ~//V=	>r7   )r4   Sequence[BasePlugin]r%   r   returnNone)r   dict[str, dict])
rB   strrC   r   rD   rM   r@   boolr   r   )rB   r   rC   r   r   r   )rB   r   rN   z
dict | strr   rM   r9   )
rC   r   rD   dict | Noner@   r   rV   
typing.Anyr   r   )rC   r   re   r   rD   r   r@   r   rV   r   r   r   )
rC   r   rD   rM   r@   r   rV   r   r   r   )rC   r   rD   rM   r@   r   r   r   )rC   r   rD   rM   r   r   )r   r   )r   rM   r   r   )__name__
__module____qualname____doc__r6   r>   rF   rJ   rO   r   r   r    r!   r"   r#   rm   ro   rT   rd   r   r[   r   r    r7   r5   r   r   #   s   !
%!
 !!
 
	!
F
 -- - 	- - 
-

 
 
	


 (
 
	
2 "&-
 -- -
 - - 
-d "&
  
   
D "&	% %% % 	% % % 
%X  
   
B CH,0;?	$8E
8&-/	U/.>r7   r   c                      e Zd ZdZ	 d	 	 	 	 	 	 	 	 	 	 	 ddZddZdddZddZ	 dddddd	 	 	 	 	 	 	 	 	 	 	 	 	 ddZ	 	 	 	 dd	Z		 	 	 	 dd
Z
y)APISpecaO  Stores metadata that describes a RESTful API using the OpenAPI specification.

    :param str title: API title
    :param str version: API version
    :param list|tuple plugins: Plugin instances.
        See https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#infoObject
    :param str openapi_version: OpenAPI Specification version.
        Should be in the form '2.x' or '3.x.x' to comply with the OpenAPI standard.
    :param options: Optional top-level keys
        See https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#openapi-object
    c                `   || _         || _        || _        || _        t	        |      | _        t        | j
                  cxk  r	t        k  sn t        d|       g | _	        i | _
        t        | j                  | j
                        | _        | j                  D ]  }|j                  |         y )Nz$Not a valid OpenAPI version number: )titleversionr   r4   r   r%   MIN_INCLUSIVE_OPENAPI_VERSIONMAX_EXCLUSIVE_OPENAPI_VERSIONr   _tags_pathsr   
components	init_spec)r3   r   r   r%   r4   r   rX   s          r5   r6   zAPISpec.__init__  s     
&7)##,+, !EoEVWXX "$
 %T\\43G3GH ll 	#FT"	#r7   c                   | j                   | j                  | j                  dd}| j                  r| j                  |d<   | j                  j
                  dk  rBt        | j                        |d<   |j                  | j                  j                                n9t        | j                        |d<   | j                  j                         }|r||d<   t        || j                        }|S )N)r   r   )pathsinfotagsr   swaggeropenapir   )r   r   r   r   r%   r;   r   rR   r   r>   r   r   )r3   rW   components_dicts      r5   r>   zAPISpec.to_dict  s    [["jjT\\B&
 ::**CK%%) !5!56C	NJJt..01 !5!56C	N"oo557O$3L!dll+
r7   Nc                <    ddl m}  || j                         |      S )zRender the spec to YAML. Requires PyYAML to be installed.

        :param dict yaml_dump_kwargs: Additional keyword arguments to pass to `yaml.dump`
        r   )dict_to_yaml)
yaml_utilsr   r>   )r3   yaml_dump_kwargsr   s      r5   to_yamlzAPISpec.to_yaml  s    
 	-DLLN,<==r7   c                <    | j                   j                  |       | S )zsStore information about a tag.

        :param dict tag: the dictionary storing information about the tag.
        )r   r   )r3   tags     r5   r   zAPISpec.tag  s    
 	

#r7   )
operationssummarydescriptionr(   c                  t        |      xs i }t        |      xs g }| j                  D ]  }	  |j                  d|||d|}||}  |st	        d      | j                  D ]  }	  |j
                  d||d|  | j                  |       | j                  j                  ||      j                  |       ||| j                  |   d<   ||| j                  |   d<   |r#| j                  |      }|| j                  |   d<   | j                  j                  | j                  |          | S # t        $ r Y w xY w# t        $ r Y w xY w)a  Add a new path object to the spec.

        https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#path-item-object

        :param str|None path: URL path component
        :param dict|None operations: describes the http methods and options for `path`
        :param str summary: short summary relevant to all operations in this path
        :param str description: long description relevant to all operations in this path
        :param list|None parameters: list of parameters relevant to all operations in this path
        :param kwargs: parameters used by any path helpers see :meth:`register_path_helper`
        )r`   r   r(   zPath template is not specified.)r`   r   r   r   r(   r   )r   r4   path_helperr   r   operation_helper_clean_operationsr   rb   rR   _clean_parametersr   r   )	r3   r`   r   r   r   r(   rV   rX   rW   s	            r5   r`   zAPISpec.path  s   . j)/R
j)/R
 ll 	F(f(( *OU
 	 @AA ll 	F'''STjSFS	 	z*tZ077
C+2DKKi("/:DKKm,//
;J.8DKKl+,,T[[->?7 3  3 s#   D3)E3	E ?E 	EEc                `   t               }|D cg c]  }t        |t              s| c}D ]u  }dD cg c]	  }||vs| }}|rt        d| d      |d   |d   f}||v r!t	        dj                  |d   |d               |j                  |       |d   dk(  sqd|d	<   w |S c c}w c c}w )
a  Ensure that all parameters with "in" equal to "path" are also required
        as required by the OpenAPI specification, as well as normalizing any
        references to global parameters and checking for duplicates parameters

        See https ://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#parameterObject.

        :param list parameters: List of parameters mapping
        )r^   r_   zMissing keys z for parameterr^   r_   z0Duplicate parameter with name {} and location {}r`   Tra   )setrL   rM   r   r
   formatadd)r3   r(   seenpr    attrmissing_attrs
unique_keys           r5   r   zAPISpec._clean_parameters)  s     u%/G:a3F!G 	-I.<VdI@UTVMV+#M?.A  $F+Yt_=JT!-FMM!&)9T? 
 HHZ  &((,	*%+	-. / HVs   B&B&	B+B+c                   t        |      }t        t        | j                  j                           }||z
  D ch c]  }|j	                  d      r| }}|r)t        dj                  dj                  |                  |xs i j                         D ]^  }d|v r| j                  |d         |d<   d|v s#i }|d   j                         D ]  \  }}		 t        |      }|	|t#        |      <   ! ||d<   ` yc c}w # t        t        f$ r= | j                  j                  dk  r!|dk7  rt        j                  dt         d	
       Y hw xY w)a  Ensure that all parameters with "in" equal to "path" are also required
        as required by the OpenAPI specification, as well as normalizing any
        references to global parameters. Also checks for invalid HTTP methods.

        See https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#parameterObject.

        :param dict operations: Dict mapping status codes to operations
        zx-z(One or more HTTP methods are invalid: {}z, r(   r'   r   defaultz+Non-integer code not allowed in OpenAPI < 3r   )
stacklevelN)r   VALID_METHODSr%   r;   
startswithr   r   joinr|   r   r:   int	TypeError
ValueErrorwarningswarnUserWarningr   )
r3   r   operation_namesvalid_methodsrv   invalidr   r'   r   r   s
             r5   r   zAPISpec._clean_operationsO  sf    j/M$*>*>*D*DEF*]:
#..QUBVC
 
 :AA$))GBTU  %*224 	3Iy(*.*@*@l++	,' i'	&/&<&B&B&D 
4ND("4y ,4Ic$i(
4 *3	+&%	3
$ &z2 //559di>O$MM M ++,s   C7C7C<<A	EE)r   )r   r   r   r   r%   r   r4   r   r   r   r   r   )r   zdict[str, typing.Any]r9   )r   ztyping.Any | Noner   r   )r   rM   r   r   )r`   
str | Noner   zdict[str, typing.Any] | Noner   r   r   r   r(   zlist[dict] | NonerV   r   r   r   )r(   
list[dict]r   r   )r   r   r   r   )r   r   r   r   r6   r>   r   r   r`   r   r   r   r7   r5   r   r     s    
" )+## # 	#
 &# # 
#>$>  ; 48""&(,;; 1	;
 ;  ; &; ; 
;z$$ 
$L(3#(3 
(3r7   r   )r   
__future__r   typingr   collections.abcr   copyr   packaging.versionr   
exceptionsr   r	   r
   r   r   utilsr   r   r   TYPE_CHECKINGrX   r   VALID_METHODS_OPENAPI_V2VALID_METHODS_OPENAPI_V3r   r   r   r   r   r   r7   r5   <module>r      s    ) "   $  %  F E	" X 3wi? ,1IJ '  ' w> w>tZ3 Z3r7   