Add mockapi source files and tests
This commit is contained in:
@@ -19,12 +19,7 @@ class RequestValidator:
|
||||
"""Validates incoming requests against OpenAPI spec."""
|
||||
|
||||
def __init__(self, spec: Dict[str, Any], strict: bool = False):
|
||||
"""Initialize the request validator.
|
||||
|
||||
Args:
|
||||
spec: OpenAPI specification
|
||||
strict: Enable strict validation mode
|
||||
"""
|
||||
"""Initialize the request validator."""
|
||||
self.spec = spec
|
||||
self.strict = strict
|
||||
|
||||
@@ -36,18 +31,7 @@ class RequestValidator:
|
||||
headers: Dict[str, str],
|
||||
body: Optional[Any] = None,
|
||||
) -> Tuple[bool, List[Dict[str, Any]]]:
|
||||
"""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)
|
||||
"""
|
||||
"""Validate a request against the spec."""
|
||||
errors = []
|
||||
|
||||
path_params = self._extract_path_params(method, path)
|
||||
@@ -97,12 +81,7 @@ class ValidationMiddleware(BaseHTTPMiddleware):
|
||||
"""Middleware that validates requests."""
|
||||
|
||||
def __init__(self, app, validator: RequestValidator):
|
||||
"""Initialize the validation middleware.
|
||||
|
||||
Args:
|
||||
app: The ASGI application
|
||||
validator: RequestValidator instance
|
||||
"""
|
||||
"""Initialize the validation middleware."""
|
||||
super().__init__(app)
|
||||
self.validator = validator
|
||||
|
||||
@@ -124,4 +103,4 @@ class ValidationMiddleware(BaseHTTPMiddleware):
|
||||
},
|
||||
)
|
||||
|
||||
return await call_next(request)
|
||||
return await call_next(request)
|
||||
|
||||
Reference in New Issue
Block a user