diff --git a/src/otaclient_common/typing.py b/src/otaclient_common/typing.py index b487a818a..a51831650 100644 --- a/src/otaclient_common/typing.py +++ b/src/otaclient_common/typing.py @@ -19,7 +19,7 @@ from pathlib import Path from typing import Any, Callable, TypeVar, Union -from pydantic import Field +from pydantic import BeforeValidator, Field from typing_extensions import Annotated, Concatenate, ParamSpec P = ParamSpec("P") @@ -31,7 +31,11 @@ # pydantic helpers -NetworkPort = Annotated[int, Field(ge=1, le=65535)] +NetworkPort = Annotated[ + int, + BeforeValidator(lambda x: int(x)), + Field(ge=1, le=65535), +] def gen_strenum_validator( diff --git a/tests/test_otaclient/test_configs/test_proxy_info.py b/tests/test_otaclient/test_configs/test_proxy_info.py index 9fa0d1def..57a539be3 100644 --- a/tests/test_otaclient/test_configs/test_proxy_info.py +++ b/tests/test_otaclient/test_configs/test_proxy_info.py @@ -95,6 +95,11 @@ "enable_ota_proxy: true\ngateway: false\n", DEFAULT_PROXY_INFO, ), + # ------ case 7(20240626): NetworkPort allow str value ------ # + ( + 'local_ota_proxy_listen_port: "8082"', + ProxyInfo(local_ota_proxy_listen_port=8082), + ), ), ) def test_proxy_info(tmp_path: Path, _input_yaml: str, _expected: ProxyInfo):