schema: accept direction='both' in marker schemas, normalize to None

This commit is contained in:
YueGuobin 2026-08-03 00:31:45 +08:00
parent b6959f8214
commit 9323ea4cec
No known key found for this signature in database

View File

@ -14,7 +14,7 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
from pydantic import BaseModel, Field from pydantic import BaseModel, Field, field_validator
from typing import List, Optional, Tuple from typing import List, Optional, Tuple
from enum import Enum from enum import Enum
from uuid import UUID, uuid4 from uuid import UUID, uuid4
@ -177,8 +177,8 @@ class MarkerCreate(BaseModel):
) )
direction: Optional[str] = Field( direction: Optional[str] = Field(
None, None,
pattern=r"^(tx|rx)$", pattern=r"^(tx|rx|both)$",
description="Direction filter: 'tx' = capture node sending only, 'rx' = capture node receiving only. Omitted or null = both directions.", description="Direction filter: 'tx' = capture node sending only, 'rx' = capture node receiving only, 'both' or null = both directions.",
) )
capture_node_id: Optional[UUID] = Field( capture_node_id: Optional[UUID] = Field(
None, None,
@ -190,6 +190,11 @@ class MarkerCreate(BaseModel):
), ),
) )
@field_validator("direction", mode="before")
@classmethod
def _both_to_none(cls, v):
return None if v == "both" else v
class MarkerUpdate(BaseModel): class MarkerUpdate(BaseModel):
""" """
@ -204,8 +209,8 @@ class MarkerUpdate(BaseModel):
tag: Optional[int] = None tag: Optional[int] = None
direction: Optional[str] = Field( direction: Optional[str] = Field(
None, None,
pattern=r"^(tx|rx)$", pattern=r"^(tx|rx|both)$",
description="Direction filter; an explicit null clears it to both. Omit to keep.", description="Direction filter; 'both' or an explicit null clears it to both. Omit to keep.",
) )
color: Optional[str] = Field(None, description="Hex color render hint, e.g. '#ff5722'") color: Optional[str] = Field(None, description="Hex color render hint, e.g. '#ff5722'")
highlight_duration: Optional[int] = Field( highlight_duration: Optional[int] = Field(
@ -213,6 +218,11 @@ class MarkerUpdate(BaseModel):
) )
enabled: Optional[bool] = Field(None, description="Toggle the marker on/off (instant).") enabled: Optional[bool] = Field(None, description="Toggle the marker on/off (instant).")
@field_validator("direction", mode="before")
@classmethod
def _both_to_none(cls, v):
return None if v == "both" else v
class MarkerDefinitionCreate(BaseModel): class MarkerDefinitionCreate(BaseModel):
""" """
@ -246,8 +256,13 @@ class MarkerDefinitionCreate(BaseModel):
) )
direction: Optional[str] = Field( direction: Optional[str] = Field(
None, None,
pattern=r"^(tx|rx)$", pattern=r"^(tx|rx|both)$",
description="Direction filter: 'tx' = capture node sending only, 'rx' = capture node receiving only. Omitted or null = both directions.", description="Direction filter: 'tx' = capture node sending only, 'rx' = capture node receiving only, 'both' or null = both directions.",
) )
@field_validator("direction", mode="before")
@classmethod
def _both_to_none(cls, v):
return None if v == "both" else v