Skip to content

Commit

Permalink
Instantiate JSON mapping validator at top level (#260)
Browse files Browse the repository at this point in the history
  • Loading branch information
pederhan authored Jun 10, 2024
1 parent 5dabdac commit 54a3c09
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions mreg_cli/utilities/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@

T = TypeVar("T")

JsonMappingValidator = TypeAdapter(JsonMapping)


def error(msg: str | Exception, code: int = os.EX_UNAVAILABLE) -> NoReturn:
"""Print an error message and exits with the given code."""
Expand Down Expand Up @@ -362,10 +364,8 @@ def get_list_unique(
ret = get_list_generic(path, params, ok404, expect_one_result=True)
if not ret:
return None

try:
validator = TypeAdapter(JsonMapping)
return validator.validate_python(ret)
return JsonMappingValidator.validate_python(ret)
except ValueError as e:
raise ValidationError(f"Failed to validate response from {path}: {e}") from e

Expand Down

0 comments on commit 54a3c09

Please sign in to comment.