o
    "i                     @   s   d dl mZ d dlmZmZmZmZmZmZm	Z	 d dl
mZ d dlmZ er2d dlmZ d dlmZ eeef ZG dd ded ZG d	d
 d
ed
 ZG dd ded ZG dd ded ZG dd ded ZdS )    )abstractmethod)TYPE_CHECKINGAnyDictListOptionalTypeUnion)OpenApiGeneratorExtension)	Direction)APIView)
AutoSchemac                
   @   s   e Zd ZU dZg Zeed   ed< ee	ee	 f ed< dddee
e	ee f ee
e	ee f  f fddZedddeeee f fd	d
ZdS )OpenApiAuthenticationExtensionaC  
    Extension for specifying authentication schemes.

    The common use-case usually consists of setting a ``name`` string and returning a dict from
    ``get_security_definition``. To model a group of headers that go together, set a list
    of names and return a corresponding list of definitions from ``get_security_definition``.

    The view class is available via ``auto_schema.view``, while the original authentication class
    can be accessed via ``self.target``. If you want to override an included extension, be sure to
    set a higher matching priority by setting the class attribute ``priority = 1`` or higher.

    get_security_requirement is expected to return a dict with security object names as keys and a
    scope list as value (usually just []). More than one key in the dict means that each entry is
    required (AND). If you need alternate variations (OR), return a list of those dicts instead.

    ``get_security_definition()`` is expected to return a valid `OpenAPI security scheme object
    <https://spec.openapis.org/oas/v3.0.3#security-scheme-object>`_
    	_registrynameauto_schemar   returnc                 C   s4   | j sJ dt| j tr| j g iS dd | j D S )Nzname(s) must be specifiedc                 S   s   i | ]}|g qS  r   ).0r   r   r   _/var/www/html/crm_dreinet/venv_linux/lib/python3.10/site-packages/drf_spectacular/extensions.py
<dictcomp>.   s    zKOpenApiAuthenticationExtension.get_security_requirement.<locals>.<dictcomp>)r   
isinstancestrselfr   r   r   r   get_security_requirement'   s   
z7OpenApiAuthenticationExtension.get_security_requirementc                 C      d S Nr   r   r   r   r   get_security_definition0      z6OpenApiAuthenticationExtension.get_security_definitionN)__name__
__module____qualname____doc__r   r   r   __annotations__r	   r   r   r   r   r   _SchemaTyper   r   r   r   r   r      s   
 &
	$r   c                   @   sl   e Zd ZU dZg Zeed   ed< dddede	e
 fddZdddedefd	d
ZdddedefddZdS )OpenApiSerializerExtensiona  
    Extension for replacing an insufficient or specifying an unknown Serializer schema.

    The existing implementation of ``map_serializer()`` will generate the same result
    as *drf-spectacular* would. Either augment or replace the generated schema. The
    view instance is available via ``auto_schema.view``, while the original serializer
    can be accessed via ``self.target``.

    ``map_serializer()`` is expected to return a valid `OpenAPI schema object
    <https://spec.openapis.org/oas/v3.0.3#schema-object>`_.
    r   r   r   	directionr   c                 C      dS )z3 return str for overriding default name extraction Nr   r   r   r'   r   r   r   get_nameC   r   z#OpenApiSerializerExtension.get_namec                 C   r(   )zQ return anything to compare instances of target. Target will be used by default. Nr   r)   r   r   r   get_identityG   r   z'OpenApiSerializerExtension.get_identityc                 C   s   |j | j|ddS )z, override for customized serializer mapping T)bypass_extensions)_map_serializertarget_classr)   r   r   r   map_serializerK   s   z)OpenApiSerializerExtension.map_serializerN)r    r!   r"   r#   r   r   r   r$   r   r   r   r*   r   r+   r%   r/   r   r   r   r   r&   5   s   
 r&   c                   @   sR   e Zd ZU dZg Zeed   ed< dee	 fddZ
edddedefd	d
ZdS )OpenApiSerializerFieldExtensiona<  
    Extension for replacing an insufficient or specifying an unknown SerializerField schema.

    To augment the default schema, you can get what *drf-spectacular* would generate with
    ``auto_schema._map_serializer_field(self.target, direction, bypass_extensions=True)``.
    and edit the returned schema at your discretion. Beware that this may still emit
    warnings, in which case manual construction is advisable.

    ``map_serializer_field()`` is expected to return a valid `OpenAPI schema object
    <https://spec.openapis.org/oas/v3.0.3#schema-object>`_.
    r   r   c                 C   r(   )zH return str for breaking out field schema into separate named component Nr   r   r   r   r   r*   ^   r   z(OpenApiSerializerFieldExtension.get_namer   r   r'   c                 C   r(   )z2 override for customized serializer field mapping Nr   r)   r   r   r   map_serializer_fieldb   s   z4OpenApiSerializerFieldExtension.map_serializer_fieldN)r    r!   r"   r#   r   r   r   r$   r   r   r*   r   r   r%   r2   r   r   r   r   r0   P   s   
 r0   c                       sH   e Zd ZU dZg Zeed   ed< e fddZ	e
d	ddZ  ZS )
OpenApiViewExtensionaF  
    Extension for replacing discovered views with a more schema-appropriate/annotated version.

    ``view_replacement()`` is expected to return a subclass of ``APIView`` (which includes
    ``ViewSet`` et al.). The discovered original view instance can be accessed with
    ``self.target`` and be subclassed if desired.
    r   c                    s(   t    t| jdr| jj| _d S d S )Ncls)super_load_classhasattrr.   r4   )r4   	__class__r   r   r6   r   s   
z OpenApiViewExtension._load_classr   Type[APIView]c                 C   r   r   r   r1   r   r   r   view_replacementy   r   z%OpenApiViewExtension.view_replacement)r   r:   )r    r!   r"   r#   r   r   r   r$   classmethodr6   r   r;   __classcell__r   r   r8   r   r3   h   s   
 r3   c                   @   s@   e Zd ZU dZg Zeed   ed< edddee	 fddZ
dS )	OpenApiFilterExtensiona.  
    Extension for specifying a list of filter parameters for a given ``FilterBackend``.

    The original filter class object can be accessed via ``self.target``. The attached view
    is accessible via ``auto_schema.view``.

    ``get_schema_operation_parameters()`` is expected to return either an empty list or a list
    of valid raw `OpenAPI parameter objects
    <https://spec.openapis.org/oas/v3.0.3#parameter-object>`_.
    Using ``drf_spectacular.plumbing.build_parameter_type`` is recommended to generate
    the appropriate raw dict objects.
    r   r   r   r   c                 O   r   r   r   )r   r   argskwargsr   r   r   get_schema_operation_parameters   r   z6OpenApiFilterExtension.get_schema_operation_parametersN)r    r!   r"   r#   r   r   r   r$   r   r%   rA   r   r   r   r   r>   ~   s
   
 r>   N)abcr   typingr   r   r   r   r   r   r	   drf_spectacular.plumbingr
   drf_spectacular.utilsr   rest_framework.viewsr   drf_spectacular.openapir   r   r%   r   r&   r0   r3   r>   r   r   r   r   <module>   s    $%