Chore: describe the zone OCR responses in the API schema

The run status and skip reason were string literals, and the test zone
and 404 bodies had no schema. Add enums and response serializers for
them. The JSON is unchanged.
This commit is contained in:
stumpylog committed 2026-11-19 13:54:59 -08:00
1 parent 8f1a6d21ce
commit 246f4e53b1
4 files changed
+152 -14

No files matched your search

+37
View File
@@ -101,6 +101,8 @@ from documents.versioning import has_prefetched_effective_content
from documents.versioning import sort_versions_newest_first
from documents.zone_ocr import ZoneOcrReason
from documents.zone_ocr import ZoneOcrResult
from documents.zone_ocr import ZoneOcrRunStatus
from documents.zone_ocr import ZoneOcrSkipReason
from documents.zone_ocr import field_key
if TYPE_CHECKING:
@@ -1853,6 +1855,28 @@ class ZoneOcrResultSerializer(serializers.Serializer[ZoneOcrResult]):
)
class RunZoneOcrResponseSerializer(serializers.Serializer[dict[str, Any]]):
"""The response of running zone OCR on one document."""
status = serializers.ChoiceField(
choices=[status.value for status in ZoneOcrRunStatus],
read_only=True,
)
reason = serializers.ChoiceField(
choices=[reason.value for reason in ZoneOcrSkipReason],
read_only=True,
required=False,
help_text="Present only when the run was skipped.",
)
results = ZoneOcrResultSerializer(many=True, read_only=True)
class OcrErrorSerializer(serializers.Serializer[dict[str, Any]]):
"""The body of an error response from the OCR template actions."""
error = serializers.CharField(read_only=True)
class RunZoneOcrDocumentsSerializer(DocumentSelectionSerializer, RunZoneOcrSerializer):
from_webui = serializers.BooleanField(required=False, default=False)
@@ -3944,6 +3968,19 @@ class OcrTemplateTestSerializer(serializers.Serializer[dict[str, Any]]):
)
class OcrTemplateTestResultSerializer(serializers.Serializer[dict[str, Any]]):
"""The extraction preview returned for an ad-hoc zone."""
raw_text = serializers.CharField(read_only=True, allow_null=True)
value = serializers.CharField(read_only=True, allow_null=True)
regex = serializers.CharField(read_only=True, allow_null=True)
regex_match = serializers.BooleanField(
read_only=True,
allow_null=True,
help_text="Whether the value fully matches the regex, or null when not checked.",
)
class OcrTemplateSerializer(MatchRuleSerializer, OwnedObjectSerializer):
zones = OcrTemplateZoneSerializer(many=True, required=False)
combine_formats = serializers.DictField(