fix: update validator

This commit is contained in:
montezdesousa
2024-02-12 11:14:08 +00:00
parent eadc0eccea
commit 4f5d44cb75
2 changed files with 6 additions and 6 deletions

View File

@@ -25,7 +25,7 @@ class QueryParams(BaseModel):
for v, fields in cls.__validator_dict__.items():
for f in fields:
if f in values and (func := VALIDATORS.get(v)):
values[f] = func(values[f])
values[f] = func(f, values[f])
return values
def model_dump(self, *args, **kwargs):

View File

@@ -3,12 +3,12 @@
from typing import Optional
def check_single(v: Optional[str]) -> Optional[str]:
def check_single(field: str, value: Optional[str]) -> Optional[str]:
"""Check that string is a single value."""
if v:
if "," in v or ";" in v:
raise ValueError("multiple values not allowed")
return v
if value:
if "," in value or ";" in value:
raise ValueError(f"multiple values not allowed for field '{field}'")
return value
VALIDATORS = {"check_single": check_single}