File: shortcuts.py

package info (click to toggle)
python-openapi-schema-validator 0.6.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 372 kB
  • sloc: python: 1,186; makefile: 46
file content (23 lines) | stat: -rw-r--r-- 590 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from typing import Any
from typing import Hashable
from typing import Mapping
from typing import Type

from jsonschema.exceptions import best_match
from jsonschema.protocols import Validator

from openapi_schema_validator.validators import OAS31Validator


def validate(
    instance: Any,
    schema: Mapping[Hashable, Any],
    cls: Type[Validator] = OAS31Validator,
    *args: Any,
    **kwargs: Any
) -> None:
    cls.check_schema(schema)
    validator = cls(schema, *args, **kwargs)
    error = best_match(validator.iter_errors(instance))
    if error is not None:
        raise error