Add mockapi source files and tests
Some checks failed
CI / test (push) Has been cancelled
CI / build (push) Has been cancelled

This commit is contained in:
2026-03-22 21:59:18 +00:00
parent 0a28cc443a
commit 0a5789130c

View File

@@ -19,12 +19,7 @@ class RequestValidator:
"""Validates incoming requests against OpenAPI spec.""" """Validates incoming requests against OpenAPI spec."""
def __init__(self, spec: Dict[str, Any], strict: bool = False): def __init__(self, spec: Dict[str, Any], strict: bool = False):
"""Initialize the request validator. """Initialize the request validator."""
Args:
spec: OpenAPI specification
strict: Enable strict validation mode
"""
self.spec = spec self.spec = spec
self.strict = strict self.strict = strict
@@ -36,18 +31,7 @@ class RequestValidator:
headers: Dict[str, str], headers: Dict[str, str],
body: Optional[Any] = None, body: Optional[Any] = None,
) -> Tuple[bool, List[Dict[str, Any]]]: ) -> Tuple[bool, List[Dict[str, Any]]]:
"""Validate a request against the spec. """Validate a request against the spec."""
Args:
method: HTTP method
path: Request path
query_params: Query parameters
headers: Request headers
body: Request body
Returns:
Tuple of (is_valid, errors)
"""
errors = [] errors = []
path_params = self._extract_path_params(method, path) path_params = self._extract_path_params(method, path)
@@ -97,12 +81,7 @@ class ValidationMiddleware(BaseHTTPMiddleware):
"""Middleware that validates requests.""" """Middleware that validates requests."""
def __init__(self, app, validator: RequestValidator): def __init__(self, app, validator: RequestValidator):
"""Initialize the validation middleware. """Initialize the validation middleware."""
Args:
app: The ASGI application
validator: RequestValidator instance
"""
super().__init__(app) super().__init__(app)
self.validator = validator self.validator = validator
@@ -124,4 +103,4 @@ class ValidationMiddleware(BaseHTTPMiddleware):
}, },
) )
return await call_next(request) return await call_next(request)