fed8b2eed7
Backend release / release (push) Waiting to run
Bandit Security Scan / bandit_scan (push) Waiting to run
Build and push multi-arch DocsGPT Docker image / build (linux/amd64, ubuntu-latest, amd64) (push) Waiting to run
Build and push multi-arch DocsGPT Docker image / build (linux/arm64, ubuntu-24.04-arm, arm64) (push) Waiting to run
Build and push multi-arch DocsGPT Docker image / manifest (push) Blocked by required conditions
Build and push DocsGPT FE Docker image for development / build (linux/amd64, ubuntu-latest, amd64) (push) Waiting to run
Build and push DocsGPT FE Docker image for development / build (linux/arm64, ubuntu-24.04-arm, arm64) (push) Waiting to run
Build and push DocsGPT FE Docker image for development / manifest (push) Blocked by required conditions
Python linting / ruff (push) Waiting to run
Run python tests with pytest / Run tests and count coverage (3.12) (push) Waiting to run
React Widget Build / build (push) Waiting to run
35 lines
1.0 KiB
Python
35 lines
1.0 KiB
Python
from typing import Any, Dict, Optional
|
|
|
|
|
|
class JsonSchemaValidationError(ValueError):
|
|
"""Raised when a JSON schema payload is invalid."""
|
|
|
|
|
|
def normalize_json_schema_payload(json_schema: Any) -> Optional[Dict[str, Any]]:
|
|
"""
|
|
Normalize accepted JSON schema payload shapes to a plain schema object.
|
|
|
|
Accepted inputs:
|
|
- None
|
|
- A raw schema object with a top-level "type"
|
|
- A wrapped payload with a top-level "schema" object
|
|
"""
|
|
if json_schema is None:
|
|
return None
|
|
|
|
if not isinstance(json_schema, dict):
|
|
raise JsonSchemaValidationError("must be a valid JSON object")
|
|
|
|
wrapped_schema = json_schema.get("schema")
|
|
if wrapped_schema is not None:
|
|
if not isinstance(wrapped_schema, dict):
|
|
raise JsonSchemaValidationError('field "schema" must be a valid JSON object')
|
|
return wrapped_schema
|
|
|
|
if "type" not in json_schema:
|
|
raise JsonSchemaValidationError(
|
|
'must include either a "type" or "schema" field'
|
|
)
|
|
|
|
return json_schema
|