From 2e0e8a24031f191a087ecd64fd95f8fc5aa09bd0 Mon Sep 17 00:00:00 2001 From: Prajwal-Microsoft Date: Fri, 8 May 2026 17:03:04 +0530 Subject: [PATCH] fix: Comments fixed --- .github/workflows/broken-links-checker.yml | 4 ++-- .../src/libs/utils/remote_schema_loader.py | 10 ++++++++-- .../app/routers/logics/schema_validator.py | 5 ++++- .../app/routers/logics/schemavault.py | 4 +++- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/.github/workflows/broken-links-checker.yml b/.github/workflows/broken-links-checker.yml index 067dd914..3250b252 100644 --- a/.github/workflows/broken-links-checker.yml +++ b/.github/workflows/broken-links-checker.yml @@ -37,7 +37,7 @@ jobs: uses: lycheeverse/lychee-action@v2.8.0 with: args: > - --verbose --no-progress --exclude ^https?:// + --verbose --no-progress --exclude ^https?:// --root-dir . ${{ steps.changed-markdown-files.outputs.all_changed_files }} failIfEmpty: false env: @@ -50,7 +50,7 @@ jobs: uses: lycheeverse/lychee-action@v2.8.0 with: args: > - --verbose --no-progress --exclude ^https?:// + --verbose --no-progress --exclude ^https?:// --root-dir . '**/*.md' failIfEmpty: false env: diff --git a/src/ContentProcessor/src/libs/utils/remote_schema_loader.py b/src/ContentProcessor/src/libs/utils/remote_schema_loader.py index 4010bb10..abe0f10d 100644 --- a/src/ContentProcessor/src/libs/utils/remote_schema_loader.py +++ b/src/ContentProcessor/src/libs/utils/remote_schema_loader.py @@ -103,7 +103,13 @@ def _download_blob_content( blob_client = blob_service_client.get_blob_client( container=container_name, blob=blob_name ) - return blob_client.download_blob().readall().decode("utf-8") + raw_bytes = blob_client.download_blob().readall() + try: + return raw_bytes.decode("utf-8") + except UnicodeDecodeError as exc: + raise JsonSchemaLoadError( + f"Schema blob '{blob_name}' is not valid UTF-8." + ) from exc class _ModelBuilder: @@ -293,7 +299,7 @@ def _resolve_ref(self, ref: str) -> Any: name = ref[len(prefix_definitions):] else: raise JsonSchemaLoadError( - f"Only local '#/$defs/...' refs are supported (got '{ref}')." + f"Only local '#/$defs/...' and '#/definitions/...' refs are supported (got '{ref}')." ) if name in self._models: diff --git a/src/ContentProcessorAPI/app/routers/logics/schema_validator.py b/src/ContentProcessorAPI/app/routers/logics/schema_validator.py index b3c5e441..00f60d3f 100644 --- a/src/ContentProcessorAPI/app/routers/logics/schema_validator.py +++ b/src/ContentProcessorAPI/app/routers/logics/schema_validator.py @@ -55,7 +55,7 @@ def validate_json_schema(raw_bytes: bytes) -> dict[str, Any]: """ errors: list[str] = [] - if raw_bytes is None: + if not raw_bytes: raise SchemaValidationError(["Empty schema upload."]) if len(raw_bytes) > MAX_SCHEMA_BYTES: @@ -139,6 +139,9 @@ def derive_class_name(document: dict[str, Any], fallback: str) -> str: else: candidate = fallback + # Apply identifier sanitization to all candidates (including title) so + # that titles containing spaces/dashes/etc. cannot produce invalid + # Python class names downstream. cleaned = "".join(ch if ch.isalnum() or ch == "_" else "_" for ch in candidate) if not cleaned or not (cleaned[0].isalpha() or cleaned[0] == "_"): cleaned = "Schema_" + cleaned diff --git a/src/ContentProcessorAPI/app/routers/logics/schemavault.py b/src/ContentProcessorAPI/app/routers/logics/schemavault.py index e0227cc1..61b0cb29 100644 --- a/src/ContentProcessorAPI/app/routers/logics/schemavault.py +++ b/src/ContentProcessorAPI/app/routers/logics/schemavault.py @@ -3,6 +3,8 @@ """Business logic for individual schema registration, update, and deletion.""" +from typing import Literal + from fastapi import UploadFile from pydantic import BaseModel, ConfigDict, Field @@ -72,7 +74,7 @@ def Update( file: UploadFile, schema_id: str, class_name: str, - storage_format: str = "json", + storage_format: Literal["json"] = "json", ) -> Schema: """Replace the schema file in blob storage and update Cosmos metadata.""" schemas = self.mongoHelper.find_document(query={"Id": schema_id})