diff --git a/porter/fields/base.py b/porter/fields/base.py index f25da86..8d1ef47 100644 --- a/porter/fields/base.py +++ b/porter/fields/base.py @@ -1,9 +1,9 @@ import json from base64 import b64decode, b64encode -import re import click from marshmallow import fields +from packaging.version import Version, parse from porter.fields.exceptions import InvalidInputData @@ -114,15 +114,11 @@ def _deserialize(self, value, attr, data, **kwargs): class VersionString(String): def _serialize(self, value, attr, obj, **kwargs) -> str: - if (type(value) is not list or len(value) == 0 or len(value) > 3): + if type(value) is not Version: raise InvalidInputData( - f"Unexpected object type, {type(value)}; expected list[3]") - - return ".".join(value) + f"Unexpected object type, {type(value)}; expected Version" + ) + return str(value) def _deserialize(self, value, attr, data, **kwargs) -> list: - pattern = r'(\d+\.)?(\d+\.)?(\d+)' - match = re.findall(pattern, value) - if len(match) != 1: - raise InvalidInputData("Minimum version must have x.x.x format") - return match[0] + return parse(value) diff --git a/porter/schema.py b/porter/schema.py index 88e9468..17b2eac 100644 --- a/porter/schema.py +++ b/porter/schema.py @@ -8,8 +8,8 @@ Integer, NonNegativeInteger, PositiveInteger, - VersionString, StringList, + VersionString, ) from porter.fields.exceptions import InvalidArgumentCombo, InvalidInputData from porter.fields.retrieve import CapsuleFrag, RetrievalKit