1"""GitLab Group model implementation.
2
3Implements :any:`/specs/spec_model_mapping` §2.1 for Group entity mapping.
4"""
5
6from __future__ import annotations
7
8from pydantic import BaseModel, Field, field_validator
9
10
[docs]
11class Group(BaseModel):
12 """GitLab Group domain model.
13
14 Implements :any:`/specs/spec_model_mapping` §2.1, mapping the following fields:
15
16 * id (str) - Preserved as string for consistency
17 * name (str)
18 """
19
20 id: str = Field(..., description="Group ID")
21 name: str = Field(..., description="Group name")
22 path: str | None = Field(None, description="URL path")
23 web_url: str | None = Field(None, description="Web URL of the group")
24 description: str | None = None
25 visibility: str | None = Field(
26 None, description="Visibility of the group (public, private, internal)"
27 )
28
[docs]
29 @field_validator("id", mode="before")
30 @classmethod
31 def coerce_id_to_str(cls, v):
32 if isinstance(v, int):
33 return str(v)
34 return v
35
[docs]
36 @classmethod
37 def from_api_json(cls, data: dict) -> "Group": # noqa: D401
38 """Create Group from GitLab API JSON dict."""
39 return cls.model_validate(data, from_attributes=False)
40
41 model_config = {
42 "extra": "ignore",
43 "populate_by_name": True,
44 }
45
46
47__all__ = ["Group"]