Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Enforces regex constraints in some fields #6021

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/models-library/src/models_library/basic_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
PositiveInt,
)

from .basic_regex import UUID_RE, VERSION_RE
from .basic_regex import SEMANTIC_VERSION_RE_W_CAPTURE_GROUPS, UUID_RE, VERSION_RE


class NonNegativeDecimal(ConstrainedDecimal):
Expand Down Expand Up @@ -46,6 +46,10 @@ class VersionStr(ConstrainedStr):
regex = re.compile(VERSION_RE)


class SemanticVersionStr(ConstrainedStr):
regex = re.compile(SEMANTIC_VERSION_RE_W_CAPTURE_GROUPS)


# checksums
# sha1sum path/to/file
class SHA1Str(ConstrainedStr):
Expand Down
12 changes: 10 additions & 2 deletions packages/models-library/src/models_library/services_io.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import re
from typing import Any, ClassVar

from pydantic import (
BaseModel,
ConstrainedStr,
Extra,
Field,
StrictBool,
Expand All @@ -21,6 +23,13 @@
)


class PropertyTypeStr(ConstrainedStr):
regex = re.compile(PROPERTY_TYPE_RE)

class Config:
frozen = True


class BaseServiceIOModel(BaseModel):
"""
Base class for service input/outputs
Expand All @@ -44,7 +53,7 @@ class BaseServiceIOModel(BaseModel):
)

# mathematical and physics descriptors
property_type: str = Field(
property_type: PropertyTypeStr = Field(
...,
alias="type",
description="data type expected on this input glob matching for data type is allowed",
Expand All @@ -61,7 +70,6 @@ class BaseServiceIOModel(BaseModel):
"data:application/hdf5",
"data:application/[email protected]",
],
regex=PROPERTY_TYPE_RE,
)

content_schema: dict[str, Any] | None = Field(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from pydantic import Extra, Field, NonNegativeInt

from .basic_regex import SEMANTIC_VERSION_RE_W_CAPTURE_GROUPS
from .basic_types import SemanticVersionStr
from .boot_options import BootOption, BootOptions
from .emails import LowerCaseEmailStr
from .services_authoring import Author, Badge
Expand Down Expand Up @@ -112,11 +112,10 @@ class ServiceMetaDataPublished(ServiceKeyVersion, ServiceBase):
" A timestamp string should be formatted as YYYY-MM-DD[T]HH:MM[:SS[.ffffff]][Z or [±]HH[:]MM]",
)

integration_version: str | None = Field(
integration_version: SemanticVersionStr | None = Field(
None,
alias="integration-version",
description="This version is used to maintain backward compatibility when there are changes in the way a service is integrated into the framework",
regex=SEMANTIC_VERSION_RE_W_CAPTURE_GROUPS,
)

service_type: ServiceType = Field(
Expand Down
Loading