From 2e00cff7566e43cffcfe47ce3a267189e69dd6e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leon=20M=C3=B6ller?= Date: Fri, 15 Mar 2024 19:14:46 +0100 Subject: [PATCH 1/2] adapter.http: skip validation of id_shorts in URLs created by us --- basyx/aas/adapter/http.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/basyx/aas/adapter/http.py b/basyx/aas/adapter/http.py index e55fddff3..d5ad6e7fd 100644 --- a/basyx/aas/adapter/http.py +++ b/basyx/aas/adapter/http.py @@ -396,9 +396,6 @@ def validate_id_short(cls, id_short: str) -> bool: return True def to_url(self, value: List[str]) -> str: - for id_short in value: - if not self.validate_id_short(id_short): - raise ValueError(f"{id_short} is not a valid id_short!") return super().to_url(self.id_short_sep.join(id_short for id_short in value)) def to_python(self, value: str) -> List[str]: From 6667a41fdfd3250e41a0270ac652f18617cadadf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leon=20M=C3=B6ller?= Date: Fri, 15 Mar 2024 19:15:28 +0100 Subject: [PATCH 2/2] adapter.http: use `Referable.validate_id_short()` to validate id_shorts ... instead of the previous way of creating a `MultiLanguageProperty` to validate id_shorts. --- basyx/aas/adapter/http.py | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/basyx/aas/adapter/http.py b/basyx/aas/adapter/http.py index d5ad6e7fd..b26b0ea10 100644 --- a/basyx/aas/adapter/http.py +++ b/basyx/aas/adapter/http.py @@ -387,21 +387,15 @@ def to_python(self, value: str) -> model.Identifier: class IdShortPathConverter(werkzeug.routing.UnicodeConverter): id_short_sep = "." - @classmethod - def validate_id_short(cls, id_short: str) -> bool: - try: - model.MultiLanguageProperty(id_short) - except model.AASConstraintViolation: - return False - return True - def to_url(self, value: List[str]) -> str: return super().to_url(self.id_short_sep.join(id_short for id_short in value)) def to_python(self, value: str) -> List[str]: id_shorts = super().to_python(value).split(self.id_short_sep) for id_short in id_shorts: - if not self.validate_id_short(id_short): + try: + model.Referable.validate_id_short(id_short) + except (ValueError, model.AASConstraintViolation): raise BadRequest(f"{id_short} is not a valid id_short!") return id_shorts