annotation.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. """
  2. Pydantic schemas for Annotation API.
  3. Defines request and response models for annotation operations.
  4. """
  5. from datetime import datetime
  6. from typing import Any
  7. from pydantic import BaseModel, Field
  8. class AnnotationCreate(BaseModel):
  9. """Schema for creating a new annotation."""
  10. task_id: str = Field(..., min_length=1, description="Task ID this annotation belongs to")
  11. user_id: str = Field(..., min_length=1, description="User ID who created this annotation")
  12. result: dict = Field(..., description="Annotation result data (JSON object)")
  13. class Config:
  14. json_schema_extra = {
  15. "example": {
  16. "task_id": "task_456def",
  17. "user_id": "user_001",
  18. "result": {
  19. "annotations": [
  20. {
  21. "id": "ann_1",
  22. "type": "rectanglelabels",
  23. "value": {
  24. "x": 10,
  25. "y": 20,
  26. "width": 100,
  27. "height": 50,
  28. "rectanglelabels": ["Cat"]
  29. }
  30. }
  31. ]
  32. }
  33. }
  34. }
  35. class AnnotationUpdate(BaseModel):
  36. """Schema for updating an existing annotation."""
  37. result: dict = Field(..., description="Updated annotation result data (JSON object)")
  38. class Config:
  39. json_schema_extra = {
  40. "example": {
  41. "result": {
  42. "annotations": [
  43. {
  44. "id": "ann_1",
  45. "type": "rectanglelabels",
  46. "value": {
  47. "x": 15,
  48. "y": 25,
  49. "width": 110,
  50. "height": 55,
  51. "rectanglelabels": ["Dog"]
  52. }
  53. }
  54. ]
  55. }
  56. }
  57. }
  58. class AnnotationResponse(BaseModel):
  59. """Schema for annotation response."""
  60. id: str = Field(..., description="Annotation unique identifier")
  61. task_id: str = Field(..., description="Task ID this annotation belongs to")
  62. user_id: str = Field(..., description="User ID who created this annotation")
  63. result: dict = Field(..., description="Annotation result data (JSON object)")
  64. created_at: datetime = Field(..., description="Annotation creation timestamp")
  65. updated_at: datetime = Field(..., description="Annotation last update timestamp")
  66. class Config:
  67. json_schema_extra = {
  68. "example": {
  69. "id": "ann_789ghi",
  70. "task_id": "task_456def",
  71. "user_id": "user_001",
  72. "result": {
  73. "annotations": [
  74. {
  75. "id": "ann_1",
  76. "type": "rectanglelabels",
  77. "value": {
  78. "x": 10,
  79. "y": 20,
  80. "width": 100,
  81. "height": 50,
  82. "rectanglelabels": ["Cat"]
  83. }
  84. }
  85. ]
  86. },
  87. "created_at": "2024-01-12T12:00:00",
  88. "updated_at": "2024-01-12T12:30:00"
  89. }
  90. }