
    E6i                         d Z ddlZddlZddlZddlmZ ddlmZ ddlm	Z	  G d de	j                        Z G d d	e      Z ed
      ZdeiZd Zy)z
This module give access to OpenAPI specifications schemas
and allows to validate specs against them.

.. versionadded:: 0.12.1
    N)Mapping)Draft4Validatorerrorsc                   .     e Zd ZdZd fd	Zd ZeZ xZS )SchemaValidationErrorzN
    Raised when specification is not valid

    .. versionadded:: 0.12.1
    c                 :    t         t        |   |       || _        y N)superr   __init__r   )selfmsgr   	__class__s      _/home/azureuser/techstart-app/venv/lib/python3.12/site-packages/flask_restx/schemas/__init__.pyr   zSchemaValidationError.__init__   s    #T3C8    c                    | j                   g}t        | j                  d       D ]  }dj                  |j                        }|j                  dj                  ||j                               t        |j                  d       D ]H  }dj                  |j                        }|j                  dj                  ||j                               J  dj                  |      S )Nc                     | j                   S r
   )pathes    r   <lambda>z/SchemaValidationError.__str__.<locals>.<lambda>   s
    qvv r   )key.z- {}: {}c                     | j                   S r
   )schema_pathr   s    r   r   z/SchemaValidationError.__str__.<locals>.<lambda>"   s
     r   z
  - {}: {}
)
r   sortedr   joinr   appendformatmessagecontextr   )r   r   errorr   suberrors        r   __str__zSchemaValidationError.__str__   s    xxjDKK-=> 	HE88EJJ'DJJz((u}}=>"5==6MN Hxx 4 45

<..tX5E5EFGH	H yy~r   r
   )__name__
__module____qualname____doc__r   r%   __unicode____classcell__r   s   @r   r   r      s     Kr   r   c                   N     e Zd ZdZef fd	Zd Zd Zd Zd Z	e
d        Z xZS )
LazySchemaz
    A thin wrapper around schema file lazy loading the data on first access

    :param filename str: The package relative json schema filename
    :param validator: The jsonschema validator class version

    .. versionadded:: 0.12.1
    c                 T    t         t        |           || _        d | _        || _        y r
   )r   r.   r   filename_schema
_validator)r   r0   	validatorr   s      r   r   zLazySchema.__init__4   s%    j$(* #r   c                     | j                   s_t        j                  t              | j                  z  }t        j                  |      5 }t        j                  |      | _         d d d        y y # 1 sw Y   y xY wr
   )	r1   importlib_resourcesfilesr&   r0   ioopenjsonload)r   refinfiles      r   _loadzLazySchema._load:   s^    ||%++H5EC 1#yy01 1 1 1s   A--A6c                 X    | j                          | j                  j                  |      S r
   )r=   r1   __getitem__)r   r   s     r   r?   zLazySchema.__getitem__A   s     

||'',,r   c                 V    | j                          | j                  j                         S r
   )r=   r1   __iter__r   s    r   rA   zLazySchema.__iter__E   s    

||$$&&r   c                 V    | j                          | j                  j                         S r
   )r=   r1   __len__rB   s    r   rD   zLazySchema.__len__I   s    

||##%%r   c                 $    | j                  |       S )z,The jsonschema validator to validate against)r2   rB   s    r   r3   zLazySchema.validatorM   s     t$$r   )r&   r'   r(   r)   r   r   r=   r?   rA   rD   propertyr3   r+   r,   s   @r   r.   r.   *   s:     ,; $1-'& % %r   r.   zoas-2.0.jsonz2.0c                 .   d| vrt        j                  d      | d   }|t        vr$t        j                  dj                  |            t        |   j                  }t        |j                  |             }|rt        dj                  |      |      y)a  
    Validate an OpenAPI specification.

    Supported OpenAPI versions: 2.0

    :param data dict: The specification to validate
    :returns boolean: True if the specification is valid
    :raises SchemaValidationError: when the specification is invalid
    :raises flask_restx.errors.SpecsError: when it's not possible to determinate
                                              the schema to validate against

    .. versionadded:: 0.12.1
    swaggerz,Unable to determinate OpenAPI schema versionz#Unknown OpenAPI schema version "{}"zOpenAPI {} validation failedr   T)r   
SpecsErrorVERSIONSr    r3   listiter_errorsr   )dataversionr3   validation_errorss       r   validaterP   \   s      NOO9oGh E L LW UVV!++IY22489#*11':CT
 	
 r   )r)   r7   r9   r5   collections.abcr   
jsonschemar   flask_restxr   ValidationErrorr   r.   OAS_20rJ   rP    r   r   <module>rW      s\    
   # & F22 0&% &%T 
N	# 
6
r   