File size: 465 Bytes
f3aae92
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
from typing import Any, Dict

from fastapi import HTTPException
from jsonschema import exceptions
from jsonschema.validators import Draft202012Validator


def validate_json_schema(schema: Dict[str, Any]) -> None:
    """Validate a JSON schema."""
    try:
        Draft202012Validator.check_schema(schema)
    except exceptions.ValidationError as e:
        raise HTTPException(
            status_code=422, detail=f"Not a valid JSON schema: {e.message}"
        )