|
16 | 16 |
|
17 | 17 | import json |
18 | 18 | import pprint |
| 19 | +import re # noqa: F401 |
19 | 20 | from typing import Any, ClassVar, Dict, List, Optional, Set |
20 | 21 |
|
21 | | -from pydantic import BaseModel, ConfigDict, Field, StrictStr |
| 22 | +from pydantic import BaseModel, ConfigDict, Field, StrictStr, field_validator |
22 | 23 | from pydantic_core import to_jsonable_python |
23 | | -from typing_extensions import Self |
| 24 | +from typing_extensions import Annotated, Self |
24 | 25 |
|
25 | 26 |
|
26 | 27 | class CreateUserPayload(BaseModel): |
27 | 28 | """ |
28 | 29 | CreateUserPayload |
29 | 30 | """ # noqa: E501 |
30 | 31 |
|
31 | | - database: StrictStr |
| 32 | + database: Annotated[str, Field(min_length=3, strict=True, max_length=63)] |
32 | 33 | roles: List[StrictStr] = Field( |
33 | 34 | description="The roles defined for a user. Currently only one role in the list is supported, therefore only the first role from this list is used. The *roles* attribute can contain the following values: 'read', 'readWrite', 'readAnyDatabase', 'readWriteAnyDatabase', 'stackitAdmin'. **The 'readAnyDatabase', 'readWriteAnyDatabase' and 'stackitAdmin' roles will always be created in the admin database.**" |
34 | 35 | ) |
35 | | - username: Optional[StrictStr] = None |
| 36 | + username: Optional[Annotated[str, Field(min_length=3, strict=True, max_length=63)]] = None |
36 | 37 | __properties: ClassVar[List[str]] = ["database", "roles", "username"] |
37 | 38 |
|
| 39 | + @field_validator("database") |
| 40 | + def database_validate_regular_expression(cls, value): |
| 41 | + """Validates the regular expression""" |
| 42 | + if not isinstance(value, str): |
| 43 | + value = str(value) |
| 44 | + |
| 45 | + if not re.match(r"^[A-Za-z_][A-Za-z0-9-_]{1,61}[A-Za-z0-9_]$", value): |
| 46 | + raise ValueError(r"must validate the regular expression /^[A-Za-z_][A-Za-z0-9-_]{1,61}[A-Za-z0-9_]$/") |
| 47 | + return value |
| 48 | + |
| 49 | + @field_validator("username") |
| 50 | + def username_validate_regular_expression(cls, value): |
| 51 | + """Validates the regular expression""" |
| 52 | + if value is None: |
| 53 | + return value |
| 54 | + |
| 55 | + if not isinstance(value, str): |
| 56 | + value = str(value) |
| 57 | + |
| 58 | + if not re.match(r"^[A-Za-z][A-Za-z0-9-]{1,61}[A-Za-z0-9]$", value): |
| 59 | + raise ValueError(r"must validate the regular expression /^[A-Za-z][A-Za-z0-9-]{1,61}[A-Za-z0-9]$/") |
| 60 | + return value |
| 61 | + |
38 | 62 | model_config = ConfigDict( |
39 | 63 | validate_by_name=True, |
40 | 64 | validate_by_alias=True, |
|
0 commit comments