Skip to content

Commit

Permalink
adapter.http: use Referable.validate_id_short() to validate id_shorts
Browse files Browse the repository at this point in the history
... instead of the previous way of creating a `MultiLanguageProperty`
to validate id_shorts.
  • Loading branch information
jkhsjdhjs committed Mar 15, 2024
1 parent 2e00cff commit 6667a41
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions basyx/aas/adapter/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 6667a41

Please sign in to comment.