
    @|h:*                     $    d dl mZ  G d d      Zy)   )resolve_schema_instancec                   :    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
y	)
SchemaResolvera  Resolve marshmallow Schemas in OpenAPI components and translate to OpenAPI
    `schema objects
    <https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#schema-object>`_,
    `parameter objects
    <https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#parameter-object>`_
    or `reference objects
    <https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#reference-object>`_.
    c                      || _         || _        y )N)openapi_version	converter)selfr   r   s      f/var/www/html/test/engine/venv/lib/python3.12/site-packages/apispec/ext/marshmallow/schema_resolver.py__init__zSchemaResolver.__init__   s    ."    c                    |j                         D ]  }t        |t              sd|v r| j                  |d         |d<   | j                  j
                  dk\  r9| j                  |j                  di              d|v r| j                  |d          |j                  di       j                         D ]  }| j                  |         y)zResolve marshmallow Schemas in a dict mapping operation to OpenApi `Operation Object
        https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#operationObject`_
        
parameters   	callbacksrequestBody	responsesN)
values
isinstancedictresolve_parametersr   majorresolve_callbackgetresolve_schemaresolve_response)r	   
operationskwargs	operationresponses        r
   resolve_operationsz!SchemaResolver.resolve_operations   s    
 $**, 	0Ii.y(*.*A*Al++	,' ##))Q.%%immK&DE I-''	-(@A%MM+r:AAC 0%%h/0	0r   c                     |j                         D ]9  }t        |t              s|j                         D ]  }| j                  |        ; y)a  Resolve marshmallow Schemas in a dict mapping callback name to OpenApi `Callback Object
        https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#callbackObject`_.

        This is done recursively, so it is possible to define callbacks in your callbacks.

        Example: ::

            # Input
            {
                "userEvent": {
                    "https://my.example/user-callback": {
                        "post": {
                            "requestBody": {
                                "content": {"application/json": {"schema": UserSchema}}
                            }
                        },
                    }
                }
            }

            # Output
            {
                "userEvent": {
                    "https://my.example/user-callback": {
                        "post": {
                            "requestBody": {
                                "content": {
                                    "application/json": {
                                        "schema": {"$ref": "#/components/schemas/User"}
                                    }
                                }
                            }
                        },
                    }
                }
            }


        N)r   r   r   r    )r	   r   callbackpaths       r
   r   zSchemaResolver.resolve_callback%   sK    P "((* 	2H(D)$OO- 2D++D12	2r   c           	      \   g }|D ]  }t        |t              rpt        |j                  di       t              sPd|v rLt        |j	                  d            }| | j
                  j                  |fd|j	                  d      i|z  }| j                  |       |j                  |        |S )a  Resolve marshmallow Schemas in a list of OpenAPI `Parameter Objects
        <https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#parameter-object>`_.
        Each parameter object that contains a Schema will be translated into
        one or more Parameter Objects.

        If the value of a `schema` key is marshmallow Schema class, instance or
        a string that resolves to a Schema Class each field in the Schema will
        be expanded as a separate Parameter Object.

        Example: ::

            # Input
            class UserSchema(Schema):
                name = fields.String()
                id = fields.Int()


            [{"in": "query", "schema": "UserSchema"}]

            # Output
            [
                {
                    "in": "query",
                    "name": "id",
                    "required": False,
                    "schema": {"type": "integer"},
                },
                {
                    "in": "query",
                    "name": "name",
                    "required": False,
                    "schema": {"type": "string"},
                },
            ]

        If the Parameter Object contains a `content` key a single Parameter
        Object is returned with the Schema translated into a Schema Object or
        Reference Object.

        Example: ::

            # Input
            [
                {
                    "in": "query",
                    "name": "pet",
                    "content": {"application/json": {"schema": "PetSchema"}},
                }
            ]

            # Output
            [
                {
                    "in": "query",
                    "name": "pet",
                    "content": {
                        "application/json": {"schema": {"$ref": "#/components/schemas/Pet"}}
                    },
                }
            ]


        :param list parameters: the list of OpenAPI parameter objects to resolve.
        schemainlocation)	r   r   r   r   popr   schema2parametersr   append)r	   r   resolved	parameterschema_instances        r
   r   z!SchemaResolver.resolve_parametersR   s    B # 	+I9d+"9==2#>EI%"9)--:Q"R<DNN<<#.7mmD.AEN  ##I.	*	+ r   c                     | j                  |       d|v r*|d   j                         D ]  }| j                  |        yy)a  Resolve marshmallow Schemas in OpenAPI `Response Objects
        <https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#responseObject>`_.
        Schemas may appear in either a Media Type Object or a Header Object.

        Example: ::

            # Input
            {
                "content": {"application/json": {"schema": "PetSchema"}},
                "description": "successful operation",
                "headers": {"PetHeader": {"schema": "PetHeaderSchema"}},
            }

            # Output
            {
                "content": {
                    "application/json": {"schema": {"$ref": "#/components/schemas/Pet"}}
                },
                "description": "successful operation",
                "headers": {
                    "PetHeader": {"schema": {"$ref": "#/components/schemas/PetHeader"}}
                },
            }

        :param dict response: the response object to resolve.
        headersN)r   r   )r	   r   headers      r
   r   zSchemaResolver.resolve_response   sJ    6 	H% "9-446 ,##F+, !r   c                    t        |t              syd|v r| j                  |d         |d<   | j                  j                  dk\  r:d|v r5|d   j                         D ]  }d|v s| j                  |d         |d<     yyy)a+  Resolve marshmallow Schemas in an OpenAPI component or header -
        modifies the input dictionary to translate marshmallow Schemas to OpenAPI
        Schema Objects or Reference Objects.

        OpenAPIv3 Components: ::

            # Input
            {
                "description": "user to add to the system",
                "content": {"application/json": {"schema": "UserSchema"}},
            }

            # Output
            {
                "description": "user to add to the system",
                "content": {
                    "application/json": {"schema": {"$ref": "#/components/schemas/User"}}
                },
            }

        :param dict|str data: either a parameter or response dictionary that may
            contain a schema, or a reference provided as string
        Nr%   r   content)r   r   resolve_schema_dictr   r   r   )r	   datar2   s      r
   r   zSchemaResolver.resolve_schema   s    0 $% t!55d8nEDN%%*D #I557 XG7*,0,D,DWXEV,W)X ! +r   c                 
   t        |t              r|j                  d      dk(  rd|v r| j                  |d         |d<   |j                  d      dk(  r=d|v r9|d   j	                         D ci c]  \  }}|| j                  |       c}}|d<   dD ],  }||v s||   D cg c]  }| j                  |       c}||<   . d|v r| j                  |d         |d<   |S | j
                  j                  |      S c c}}w c c}w )a  Resolve a marshmallow Schema class, object, or a string that resolves
        to a Schema class or a schema reference or an OpenAPI Schema Object
        containing one of the above to an OpenAPI Schema Object or Reference Object.

        If the input is a marshmallow Schema class, object or a string that resolves
        to a Schema class the Schema will be translated to an OpenAPI Schema Object
        or Reference Object.

        Example: ::

            # Input
            "PetSchema"

            # Output
            {"$ref": "#/components/schemas/Pet"}

        If the input is a dictionary representation of an OpenAPI Schema Object
        recursively search for a marshmallow Schemas to resolve. For `"type": "array"`,
        marshmallow Schemas may appear as the value of the `items` key. For
        `"type": "object"` Marshmalow Schemas may appear as values in the `properties`
        dictionary.

        Examples: ::

            # Input
            {"type": "array", "items": "PetSchema"}

            # Output
            {"type": "array", "items": {"$ref": "#/components/schemas/Pet"}}

            # Input
            {"type": "object", "properties": {"pet": "PetSchcema", "user": "UserSchema"}}

            # Output
            {
                "type": "object",
                "properties": {
                    "pet": {"$ref": "#/components/schemas/Pet"},
                    "user": {"$ref": "#/components/schemas/User"},
                },
            }

        :param string|Schema|dict schema: the schema to resolve.
        typearrayitemsobject
properties)oneOfanyOfallOfnot)r   r   r   r3   r8   r   resolve_nested_schema)r	   r%   kvkeywordss         r
   r3   z"SchemaResolver.resolve_schema_dict   s   Z fd#zz&!W,F1B"&":":6'?"Kwzz&!X-,&2H !'| 4 : : <(1 t//22(|$ 7 f$=CG_'89003'F7O
  $ 8 8 GuM~~33F;;('s   .C:"D N)__name__
__module____qualname____doc__r   r    r   r   r   r   r3    r   r
   r   r      s0    #0&+2ZOb,@#XJ><r   r   N)commonr   r   rH   r   r
   <module>rJ      s    +b< b<r   