"""Vendor related endpoints.""" import asyncio import logging from typing import Annotated from fastapi import APIRouter, Body, Depends, HTTPException, Request, WebSocket, WebSocketDisconnect from fastapi.responses import JSONResponse from sqlalchemy.ext.asyncio import AsyncSession from spoolman.api.v1.models import Message, SettingEvent, SettingResponse from spoolman.database import setting from spoolman.database.database import get_db_session from spoolman.exceptions import ItemNotFoundError from spoolman.extra_field_registry import invalidate_extra_field_cache, validate_extra_field_setting from spoolman.settings import SETTINGS, parse_setting from spoolman.ws import websocket_manager router = APIRouter( prefix="/setting", tags=["setting"], ) # ruff: noqa: D103 logger = logging.getLogger(__name__) async def require_json_content_type(request: Request) -> None: """Reject a request body that is not declared as JSON. This endpoint takes a bare ``str`` body, and FastAPI only JSON-parses ``application/*json``; anything else arrives as raw bytes that lax-mode ``str`` happily coerces. That makes a ``text/plain`` body acceptable, which is exactly what ``