diff --git a/src/control_backend/schemas/program.py b/src/control_backend/schemas/program.py index 8f23cb9..1f3d1d9 100644 --- a/src/control_backend/schemas/program.py +++ b/src/control_backend/schemas/program.py @@ -7,7 +7,7 @@ University within the Software Project course. from enum import Enum from typing import Literal -from pydantic import UUID4, BaseModel +from pydantic import UUID4, BaseModel, field_validator class ProgramElement(BaseModel): @@ -24,6 +24,13 @@ class ProgramElement(BaseModel): # To make program elements hashable model_config = {"frozen": True} + @field_validator("name") + @classmethod + def name_must_not_start_with_number(cls, v: str) -> str: + if v and v[0].isdigit(): + raise ValueError('Field "name" must not start with a number.') + return v + class LogicalOperator(Enum): """ @@ -105,6 +112,7 @@ class InferredBelief(ProgramElement): left: Belief right: Belief + class EmotionBelief(ProgramElement): """ Represents a belief that is set when a certain emotion is detected. @@ -115,6 +123,7 @@ class EmotionBelief(ProgramElement): name: str = "" emotion: str + class Norm(ProgramElement): """ Base class for behavioral norms that guide the robot's interactions. @@ -329,4 +338,4 @@ class Program(BaseModel): if __name__ == "__main__": input = input("Enter program JSON: ") program = Program.model_validate_json(input) - print(program) \ No newline at end of file + print(program)