|
| 1 | +# coding: utf-8 |
| 2 | + |
| 3 | +""" |
| 4 | + STACKIT Cloud Foundry API |
| 5 | +
|
| 6 | + API endpoints for managing STACKIT Cloud Foundry |
| 7 | +
|
| 8 | + The version of the OpenAPI document: 1.0.0 |
| 9 | + Contact: support@stackit.cloud |
| 10 | + Generated by OpenAPI Generator (https://openapi-generator.tech) |
| 11 | +
|
| 12 | + Do not edit the class manually. |
| 13 | +""" # noqa: E501 |
| 14 | + |
| 15 | +from __future__ import annotations |
| 16 | + |
| 17 | +import json |
| 18 | +import pprint |
| 19 | +import re # noqa: F401 |
| 20 | +from datetime import datetime |
| 21 | +from typing import Any, ClassVar, Dict, List, Optional, Set |
| 22 | + |
| 23 | +from pydantic import BaseModel, ConfigDict, Field, StrictStr, field_validator |
| 24 | +from typing_extensions import Self |
| 25 | + |
| 26 | + |
| 27 | +class IsolationSegment(BaseModel): |
| 28 | + """ |
| 29 | + IsolationSegment |
| 30 | + """ # noqa: E501 |
| 31 | + |
| 32 | + created_at: datetime = Field(alias="createdAt") |
| 33 | + guid: StrictStr |
| 34 | + name: StrictStr |
| 35 | + org_id: StrictStr = Field(alias="orgId") |
| 36 | + platform_id: StrictStr = Field(alias="platformId") |
| 37 | + project_id: StrictStr = Field(alias="projectId") |
| 38 | + region: StrictStr |
| 39 | + updated_at: datetime = Field(alias="updatedAt") |
| 40 | + __properties: ClassVar[List[str]] = [ |
| 41 | + "createdAt", |
| 42 | + "guid", |
| 43 | + "name", |
| 44 | + "orgId", |
| 45 | + "platformId", |
| 46 | + "projectId", |
| 47 | + "region", |
| 48 | + "updatedAt", |
| 49 | + ] |
| 50 | + |
| 51 | + @field_validator("created_at", mode="before") |
| 52 | + def created_at_change_year_zero_to_one(cls, value): |
| 53 | + """Workaround which prevents year 0 issue""" |
| 54 | + if isinstance(value, str): |
| 55 | + # Check for year "0000" at the beginning of the string |
| 56 | + # This assumes common date formats like YYYY-MM-DDTHH:MM:SS+00:00 or YYYY-MM-DDTHH:MM:SSZ |
| 57 | + if value.startswith("0000-01-01T") and re.match( |
| 58 | + r"^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\+\d{2}:\d{2}|Z)$", value |
| 59 | + ): |
| 60 | + # Workaround: Replace "0000" with "0001" |
| 61 | + return "0001" + value[4:] # Take "0001" and append the rest of the string |
| 62 | + return value |
| 63 | + |
| 64 | + @field_validator("updated_at", mode="before") |
| 65 | + def updated_at_change_year_zero_to_one(cls, value): |
| 66 | + """Workaround which prevents year 0 issue""" |
| 67 | + if isinstance(value, str): |
| 68 | + # Check for year "0000" at the beginning of the string |
| 69 | + # This assumes common date formats like YYYY-MM-DDTHH:MM:SS+00:00 or YYYY-MM-DDTHH:MM:SSZ |
| 70 | + if value.startswith("0000-01-01T") and re.match( |
| 71 | + r"^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\+\d{2}:\d{2}|Z)$", value |
| 72 | + ): |
| 73 | + # Workaround: Replace "0000" with "0001" |
| 74 | + return "0001" + value[4:] # Take "0001" and append the rest of the string |
| 75 | + return value |
| 76 | + |
| 77 | + model_config = ConfigDict( |
| 78 | + populate_by_name=True, |
| 79 | + validate_assignment=True, |
| 80 | + protected_namespaces=(), |
| 81 | + ) |
| 82 | + |
| 83 | + def to_str(self) -> str: |
| 84 | + """Returns the string representation of the model using alias""" |
| 85 | + return pprint.pformat(self.model_dump(by_alias=True)) |
| 86 | + |
| 87 | + def to_json(self) -> str: |
| 88 | + """Returns the JSON representation of the model using alias""" |
| 89 | + # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead |
| 90 | + return json.dumps(self.to_dict()) |
| 91 | + |
| 92 | + @classmethod |
| 93 | + def from_json(cls, json_str: str) -> Optional[Self]: |
| 94 | + """Create an instance of IsolationSegment from a JSON string""" |
| 95 | + return cls.from_dict(json.loads(json_str)) |
| 96 | + |
| 97 | + def to_dict(self) -> Dict[str, Any]: |
| 98 | + """Return the dictionary representation of the model using alias. |
| 99 | +
|
| 100 | + This has the following differences from calling pydantic's |
| 101 | + `self.model_dump(by_alias=True)`: |
| 102 | +
|
| 103 | + * `None` is only added to the output dict for nullable fields that |
| 104 | + were set at model initialization. Other fields with value `None` |
| 105 | + are ignored. |
| 106 | + """ |
| 107 | + excluded_fields: Set[str] = set([]) |
| 108 | + |
| 109 | + _dict = self.model_dump( |
| 110 | + by_alias=True, |
| 111 | + exclude=excluded_fields, |
| 112 | + exclude_none=True, |
| 113 | + ) |
| 114 | + return _dict |
| 115 | + |
| 116 | + @classmethod |
| 117 | + def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: |
| 118 | + """Create an instance of IsolationSegment from a dict""" |
| 119 | + if obj is None: |
| 120 | + return None |
| 121 | + |
| 122 | + if not isinstance(obj, dict): |
| 123 | + return cls.model_validate(obj) |
| 124 | + |
| 125 | + _obj = cls.model_validate( |
| 126 | + { |
| 127 | + "createdAt": obj.get("createdAt"), |
| 128 | + "guid": obj.get("guid"), |
| 129 | + "name": obj.get("name"), |
| 130 | + "orgId": obj.get("orgId"), |
| 131 | + "platformId": obj.get("platformId"), |
| 132 | + "projectId": obj.get("projectId"), |
| 133 | + "region": obj.get("region"), |
| 134 | + "updatedAt": obj.get("updatedAt"), |
| 135 | + } |
| 136 | + ) |
| 137 | + return _obj |
0 commit comments