Skip to content

Commit

Permalink
Merge pull request #20 from rwth-iat/http_api/simplify_id_short_valid…
Browse files Browse the repository at this point in the history
…ation

adapter.http: simplify `id_short` validation
  • Loading branch information
jkhsjdhjs committed Mar 16, 2024
2 parents 80eeb44 + 6667a41 commit 79d82aa
Showing 1 changed file with 3 additions and 12 deletions.
15 changes: 3 additions & 12 deletions basyx/aas/adapter/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,24 +374,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:
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]:
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 79d82aa

Please sign in to comment.