|
1 | 1 | """OpenAPI core shortcuts module"""
|
2 |
| -import warnings |
3 | 2 | from typing import Any
|
4 | 3 | from typing import Dict
|
5 | 4 | from typing import Optional
|
6 | 5 | from typing import Union
|
7 | 6 |
|
8 |
| -from lazy_object_proxy import Proxy |
9 |
| - |
10 | 7 | from openapi_core.exceptions import SpecError
|
11 | 8 | from openapi_core.finders import SpecClasses
|
12 | 9 | from openapi_core.finders import SpecFinder
|
|
23 | 20 | from openapi_core.unmarshalling.request.protocols import (
|
24 | 21 | WebhookRequestUnmarshaller,
|
25 | 22 | )
|
26 |
| -from openapi_core.unmarshalling.request.proxies import ( |
27 |
| - SpecRequestValidatorProxy, |
28 |
| -) |
29 | 23 | from openapi_core.unmarshalling.request.types import AnyRequestUnmarshallerType
|
30 | 24 | from openapi_core.unmarshalling.request.types import RequestUnmarshallerType
|
31 | 25 | from openapi_core.unmarshalling.request.types import (
|
|
41 | 35 | from openapi_core.unmarshalling.response.protocols import (
|
42 | 36 | WebhookResponseUnmarshaller,
|
43 | 37 | )
|
44 |
| -from openapi_core.unmarshalling.response.proxies import ( |
45 |
| - SpecResponseValidatorProxy, |
46 |
| -) |
47 | 38 | from openapi_core.unmarshalling.response.types import (
|
48 | 39 | AnyResponseUnmarshallerType,
|
49 | 40 | )
|
@@ -287,56 +278,14 @@ def validate_request(
|
287 | 278 | request: AnyRequest,
|
288 | 279 | spec: Spec,
|
289 | 280 | base_url: Optional[str] = None,
|
290 |
| - validator: Optional[SpecRequestValidatorProxy] = None, |
291 | 281 | cls: Optional[AnyRequestValidatorType] = None,
|
292 | 282 | **validator_kwargs: Any,
|
293 | 283 | ) -> Optional[RequestUnmarshalResult]:
|
294 |
| - if isinstance(spec, (Request, WebhookRequest)) and isinstance( |
295 |
| - request, Spec |
296 |
| - ): |
297 |
| - warnings.warn( |
298 |
| - "spec parameter as a first argument is deprecated. " |
299 |
| - "Move it to second argument instead.", |
300 |
| - DeprecationWarning, |
301 |
| - ) |
302 |
| - request, spec = spec, request |
303 |
| - |
304 | 284 | if not isinstance(request, (Request, WebhookRequest)):
|
305 | 285 | raise TypeError("'request' argument is not type of (Webhook)Request")
|
306 | 286 | if not isinstance(spec, Spec):
|
307 | 287 | raise TypeError("'spec' argument is not type of Spec")
|
308 | 288 |
|
309 |
| - if validator is not None and isinstance(request, Request): |
310 |
| - warnings.warn( |
311 |
| - "validator parameter is deprecated. Use cls instead.", |
312 |
| - DeprecationWarning, |
313 |
| - ) |
314 |
| - result = validator.validate(spec, request, base_url=base_url) |
315 |
| - result.raise_for_errors() |
316 |
| - return result |
317 |
| - |
318 |
| - # redirect to unmarshaller for backward compatibility |
319 |
| - if cls is None or issubclass( |
320 |
| - cls, (RequestUnmarshaller, WebhookRequestUnmarshaller) |
321 |
| - ): |
322 |
| - result = unmarshal_request( |
323 |
| - request, |
324 |
| - spec=spec, |
325 |
| - base_url=base_url, |
326 |
| - cls=cls, |
327 |
| - **validator_kwargs, |
328 |
| - ) |
329 |
| - |
330 |
| - def return_result() -> RequestUnmarshalResult: |
331 |
| - warnings.warn( |
332 |
| - "validate_request is deprecated for unmarshalling data " |
333 |
| - "and it will not return any result in the future. " |
334 |
| - "Use unmarshal_request function instead.", |
335 |
| - DeprecationWarning, |
336 |
| - ) |
337 |
| - return result |
338 |
| - |
339 |
| - return Proxy(return_result) # type: ignore |
340 | 289 | if isinstance(request, WebhookRequest):
|
341 | 290 | if cls is None or issubclass(cls, WebhookRequestValidator):
|
342 | 291 | validate_webhook_request(
|
@@ -370,62 +319,16 @@ def validate_response(
|
370 | 319 | response: Union[Response, Request, WebhookRequest],
|
371 | 320 | spec: Union[Spec, Response],
|
372 | 321 | base_url: Optional[str] = None,
|
373 |
| - validator: Optional[SpecResponseValidatorProxy] = None, |
374 | 322 | cls: Optional[AnyResponseValidatorType] = None,
|
375 | 323 | **validator_kwargs: Any,
|
376 | 324 | ) -> Optional[ResponseUnmarshalResult]:
|
377 |
| - if ( |
378 |
| - isinstance(request, Spec) |
379 |
| - and isinstance(response, (Request, WebhookRequest)) |
380 |
| - and isinstance(spec, Response) |
381 |
| - ): |
382 |
| - warnings.warn( |
383 |
| - "spec parameter as a first argument is deprecated. " |
384 |
| - "Move it to third argument instead.", |
385 |
| - DeprecationWarning, |
386 |
| - ) |
387 |
| - args = request, response, spec |
388 |
| - spec, request, response = args |
389 |
| - |
390 | 325 | if not isinstance(request, (Request, WebhookRequest)):
|
391 | 326 | raise TypeError("'request' argument is not type of (Webhook)Request")
|
392 | 327 | if not isinstance(response, Response):
|
393 | 328 | raise TypeError("'response' argument is not type of Response")
|
394 | 329 | if not isinstance(spec, Spec):
|
395 | 330 | raise TypeError("'spec' argument is not type of Spec")
|
396 | 331 |
|
397 |
| - if validator is not None and isinstance(request, Request): |
398 |
| - warnings.warn( |
399 |
| - "validator parameter is deprecated. Use cls instead.", |
400 |
| - DeprecationWarning, |
401 |
| - ) |
402 |
| - result = validator.validate(spec, request, response, base_url=base_url) |
403 |
| - result.raise_for_errors() |
404 |
| - return result |
405 |
| - |
406 |
| - # redirect to unmarshaller for backward compatibility |
407 |
| - if cls is None or issubclass( |
408 |
| - cls, (ResponseUnmarshaller, WebhookResponseUnmarshaller) |
409 |
| - ): |
410 |
| - result = unmarshal_response( |
411 |
| - request, |
412 |
| - response, |
413 |
| - spec=spec, |
414 |
| - base_url=base_url, |
415 |
| - cls=cls, |
416 |
| - **validator_kwargs, |
417 |
| - ) |
418 |
| - |
419 |
| - def return_result() -> ResponseUnmarshalResult: |
420 |
| - warnings.warn( |
421 |
| - "validate_response is deprecated for unmarshalling data " |
422 |
| - "and it will not return any result in the future. " |
423 |
| - "Use unmarshal_response function instead.", |
424 |
| - DeprecationWarning, |
425 |
| - ) |
426 |
| - return result |
427 |
| - |
428 |
| - return Proxy(return_result) # type: ignore |
429 | 332 | if isinstance(request, WebhookRequest):
|
430 | 333 | if cls is None or issubclass(cls, WebhookResponseValidator):
|
431 | 334 | validate_webhook_response(
|
|
0 commit comments