1515
1616from agent_utilities .exceptions import (
1717 ParameterError ,
18- MissingParameterError ,
1918)
2019
2120
@@ -44,6 +43,16 @@ class BranchModel(BaseModel):
4443 page : Optional [int ] = Field (description = "Pagination page" , default = 1 )
4544 per_page : Optional [int ] = Field (description = "Results per page" , default = 100 )
4645
46+ @field_validator ("project_id" )
47+ def validate_project_id (cls , v ):
48+ """
49+ Validate project_id.
50+ Strips quotes and converts to string.
51+ """
52+ if v is None :
53+ return v
54+ return str (v ).strip ("'\" " )
55+
4756 def model_post_init (self , __context ):
4857 """
4958 Build the API parameters
@@ -144,6 +153,16 @@ class CommitModel(BaseModel):
144153 page : Optional [int ] = Field (description = "Pagination page" , default = 1 )
145154 per_page : Optional [int ] = Field (description = "Results per page" , default = 100 )
146155
156+ @field_validator ("project_id" , "pipeline_id" , "start_project" )
157+ def validate_ids (cls , v ):
158+ """
159+ Validate ID fields.
160+ Strips quotes and converts to string.
161+ """
162+ if v is None :
163+ return v
164+ return str (v ).strip ("'\" " )
165+
147166 def model_post_init (self , __context ):
148167 """
149168 Build the API parameters
@@ -419,20 +438,14 @@ def model_post_init(self, __context):
419438 def validate_project_id (cls , v ):
420439 if not v :
421440 raise ValueError ("Project ID or path cannot be empty" )
422- return str (v )
441+ return str (v ). strip ( "' \" " )
423442
424443 @field_validator ("tag" )
425444 def validate_tag (cls , v ):
426445 if v and not v .strip ():
427446 raise ValueError ("Tag name cannot be empty or whitespace" )
428447 return v
429448
430- @field_validator ("ref" )
431- def validate_ref (cls , v ):
432- if v and not v .strip ():
433- raise ValueError ("Ref cannot be empty or whitespace" )
434- return v
435-
436449
437450class PipelineScheduleModel (BaseModel ):
438451 project_id : Union [int , str ] = Field (..., description = "Project ID or full path" )
@@ -481,7 +494,7 @@ class IssueModel(BaseModel):
481494 def validate_project_id (cls , v ):
482495 if not v :
483496 raise ValueError ("Project ID or path cannot be empty" )
484- return str (v )
497+ return str (v ). strip ( "' \" " )
485498
486499 @field_validator ("title" )
487500 def validate_title (cls , v ):
@@ -497,9 +510,9 @@ def validate_state(cls, v):
497510
498511 @field_validator ("issue_iid" )
499512 def validate_issue_iid (cls , v ):
500- if v is not None and v <= 0 :
501- raise ValueError ( "Issue IID must be a positive integer" )
502- return v
513+ if v is None :
514+ return v
515+ return str ( v ). strip ( "' \" " )
503516
504517
505518class DeployTokenModel (BaseModel ):
@@ -565,24 +578,12 @@ def validate_expires_at(cls, v):
565578 @field_validator ("project_id" , "group_id" , "token" )
566579 def validate_optional_parameters (cls , v , values ):
567580 """
568- Validate optional parameters to ensure they are provided only when 'project_id' or 'group_id' is provided.
569-
570- Args:
571- - v: The value of the parameter.
572- - values: Dictionary of all values.
573-
574- Returns:
575- - Any: The validated parameter value.
576-
577- Raises:
578- - MissingParameterError: If the parameter is provided and 'project_id' and 'group_id' are None.
581+ Validate optional parameters.
582+ Strips quotes and converts to string.
579583 """
580- if (
581- "project_id" in values .lower () or "group_id" in values .lower ()
582- ) and v is not None :
583- return v .lower ()
584- else :
585- raise MissingParameterError
584+ if v is None :
585+ return v
586+ return str (v ).strip ("'\" " )
586587
587588 @field_validator ("name" , "username" , "scopes" )
588589 def validate_string_parameters (cls , v ):
@@ -873,23 +874,15 @@ def validate_visibility(cls, value):
873874 raise ValueError ("Invalid visibility" )
874875 return value .lower ()
875876
876- @field_validator ("group_id" )
877- def validate_group_id (cls , v ):
877+ @field_validator ("group_id" , "file_template_project_id" )
878+ def validate_ids (cls , v ):
878879 """
879- Validate the 'group_id' parameter to ensure it is provided.
880-
881- Args:
882- - v: The value of 'group_id'.
883-
884- Returns:
885- - Union[int, str]: The validated 'group_id' value.
886-
887- Raises:
888- - MissingParameterError: If 'group_id' is None.
880+ Validate ID fields.
881+ Strips quotes and converts to string.
889882 """
890883 if v is None :
891- raise MissingParameterError
892- return v
884+ return v
885+ return str ( v ). strip ( "' \" " )
893886
894887 def model_post_init (self , __context ):
895888 """
@@ -942,6 +935,16 @@ class JobModel(BaseModel):
942935 job_variable_attributes : Optional [Dict ] = None
943936 api_parameters : Optional [Dict ] = Field (description = "API Parameters" , default = None )
944937
938+ @field_validator ("project_id" , "pipeline_id" , "job_id" )
939+ def validate_ids (cls , v ):
940+ """
941+ Validate ID fields.
942+ Strips quotes and converts to string.
943+ """
944+ if v is None :
945+ return v
946+ return str (v ).strip ("'\" " )
947+
945948 @field_validator ("per_page" , "page" )
946949 def validate_positive_integer (cls , v ):
947950 """
@@ -1071,6 +1074,16 @@ class MembersModel(BaseModel):
10711074 page : Optional [int ] = Field (description = "Pagination page" , default = 1 )
10721075 api_parameters : Optional [Dict ] = Field (description = "API Parameters" , default = None )
10731076
1077+ @field_validator ("project_id" , "group_id" )
1078+ def validate_ids (cls , v ):
1079+ """
1080+ Validate ID fields.
1081+ Strips quotes and converts to string.
1082+ """
1083+ if v is None :
1084+ return v
1085+ return str (v ).strip ("'\" " )
1086+
10741087 @field_validator ("per_page" , "page" )
10751088 def validate_positive_integer (cls , v ):
10761089 """
@@ -1469,28 +1482,22 @@ def validate_boolean(cls, v):
14691482 raise ParameterError
14701483 return v
14711484
1472- @field_validator ("assignee_id" , "milestone_id" , "target_project_id" )
1473- def validate_positive_integer (cls , v ):
1485+ @field_validator (
1486+ "assignee_id" ,
1487+ "milestone_id" ,
1488+ "target_project_id" ,
1489+ "project_id" ,
1490+ "author_id" ,
1491+ "reviewer_id" ,
1492+ )
1493+ def validate_ids (cls , v ):
14741494 """
1475- Validate positive integer fields.
1476-
1477- Args:
1478- - v: The value of the positive integer field.
1479-
1480- Returns:
1481- - The validated value if valid.
1482-
1483- Raises:
1484- - ParameterError: If 'v' is not a valid positive integer.
1495+ Validate ID fields.
1496+ Strips quotes and converts to string.
14851497 """
1486- if isinstance (v , str ):
1487- try :
1488- v = int (v )
1489- except Exception as e :
1490- raise e
1491- if not isinstance (v , int ) or v < 0 :
1492- raise ParameterError
1493- return v
1498+ if v is None :
1499+ return v
1500+ return str (v ).strip ("'\" " )
14941501
14951502 @field_validator ("assignee_ids" , "reviewer_ids" )
14961503 def validate_list_of_integers (cls , v ):
0 commit comments