File size: 971 Bytes
557ab38
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
"""Schema discovery routes.

GET /schemas               -> list of registered document types
GET /schemas/{doc_type}    -> full JSON Schema for that type

The JSON Schema is what OpenAI's structured outputs uses internally — exposing
it lets clients validate uploads client-side, or auto-generate forms.
"""
from __future__ import annotations

from fastapi import APIRouter

from src.api.errors import UnsupportedDocType
from src.schemas.registry import get_json_schema, list_doc_types

router = APIRouter(prefix="/schemas", tags=["schemas"])


@router.get("")
def list_schemas() -> dict:
    """Return all registered document type keys."""
    return {"doc_types": list_doc_types()}


@router.get("/{doc_type}")
def get_schema_json(doc_type: str) -> dict:
    """Return the JSON Schema for one document type."""
    try:
        return get_json_schema(doc_type)
    except KeyError as e:
        raise UnsupportedDocType(str(e), details={"doc_type": doc_type}) from e