validate negative one distance as None
This commit is contained in:
parent
82bec77995
commit
97d18892e1
1 changed files with 7 additions and 2 deletions
|
@ -1,9 +1,10 @@
|
||||||
from typing import Annotated, Union, Optional
|
from typing import Annotated, Union, Optional, Any
|
||||||
from uuid import UUID
|
from uuid import UUID
|
||||||
|
|
||||||
from annotated_types import Lt
|
from annotated_types import Lt
|
||||||
from pydantic import Field as APIField
|
from pydantic import Field as APIField
|
||||||
from pydantic import NegativeInt, PositiveInt
|
from pydantic import NegativeInt, PositiveInt
|
||||||
|
from pydantic.functional_validators import BeforeValidator
|
||||||
from pydantic.types import NonNegativeInt, NonNegativeFloat
|
from pydantic.types import NonNegativeInt, NonNegativeFloat
|
||||||
from pydantic_extra_types.mac_address import MacAddress
|
from pydantic_extra_types.mac_address import MacAddress
|
||||||
|
|
||||||
|
@ -75,6 +76,10 @@ class LocateWifiPeerSchema(BaseSchema):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def negative_one_is_none(value: Any):
|
||||||
|
return None if value == -1 else value
|
||||||
|
|
||||||
|
|
||||||
class LocateIBeaconPeerSchema(BaseSchema):
|
class LocateIBeaconPeerSchema(BaseSchema):
|
||||||
uuid: UUID = APIField(
|
uuid: UUID = APIField(
|
||||||
title="UUID",
|
title="UUID",
|
||||||
|
@ -87,7 +92,7 @@ class LocateIBeaconPeerSchema(BaseSchema):
|
||||||
minor: Annotated[NonNegativeInt, Lt(2 ** 16)] = APIField(
|
minor: Annotated[NonNegativeInt, Lt(2 ** 16)] = APIField(
|
||||||
title="minor value of the iBeacon",
|
title="minor value of the iBeacon",
|
||||||
)
|
)
|
||||||
distance: Optional[NonNegativeFloat] = APIField(
|
distance: Annotated[Optional[NonNegativeFloat], BeforeValidator(negative_one_is_none)] = APIField(
|
||||||
default=None,
|
default=None,
|
||||||
title="determined iBeacon distance in meters",
|
title="determined iBeacon distance in meters",
|
||||||
)
|
)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue