Source code for annofabapi.pydantic_models.label_v3
"""
No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
The version of the OpenAPI document: 1.0.0
Generated by OpenAPI Generator (https://openapi-generator.tech)
Do not edit the class manually.
"""
from __future__ import annotations
import json
import pprint
import re # noqa: F401
from typing import Any, ClassVar, Dict, List, Set
from pydantic import BaseModel, ConfigDict, Field, StrictStr
from typing_extensions import Self
from annofabapi.pydantic_models.annotation_type import AnnotationType
from annofabapi.pydantic_models.annotation_type_field_value import AnnotationTypeFieldValue
from annofabapi.pydantic_models.color import Color
from annofabapi.pydantic_models.internationalization_message import InternationalizationMessage
from annofabapi.pydantic_models.keybind import Keybind
[docs]
class LabelV3(BaseModel):
"""
LabelV3
"""
label_id: StrictStr = Field(description="ラベルID。[値の制約についてはこちら。](#section/API-Convention/APIID) ")
label_name: InternationalizationMessage
keybind: List[Keybind] = Field(description="ショートカットキー")
annotation_type: AnnotationType
field_values: Dict[str, AnnotationTypeFieldValue] = Field(
description="KeyがフィールドIdであるDictionaryです。 カスタムの[組織プラグイン](#operation/putOrganizationPlugin)で利用される[UserDefinedAnnotationTypeDefinition](#tag/x-data-types/UserDefinedAnnotationTypeDefinition).`field_definitions`で定義されます。 "
)
additional_data_definitions: List[StrictStr] = Field(description="ラベルに所属する属性のID")
color: Color
metadata: Dict[str, StrictStr] | None = Field(default=None, description="ユーザーが自由に登録できるkey-value型のメタデータです。 ")
__properties: ClassVar[List[str]] = [
"label_id",
"label_name",
"keybind",
"annotation_type",
"field_values",
"additional_data_definitions",
"color",
"metadata",
]
model_config = ConfigDict(
populate_by_name=True,
validate_assignment=True,
protected_namespaces=(),
)
[docs]
def to_str(self) -> str:
"""Returns the string representation of the model using alias"""
return pprint.pformat(self.model_dump(by_alias=True))
[docs]
def to_json(self) -> str:
"""Returns the JSON representation of the model using alias"""
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
return json.dumps(self.to_dict())
[docs]
@classmethod
def from_json(cls, json_str: str) -> Self | None:
"""Create an instance of LabelV3 from a JSON string"""
return cls.from_dict(json.loads(json_str))
[docs]
def to_dict(self) -> Dict[str, Any]:
"""Return the dictionary representation of the model using alias.
This has the following differences from calling pydantic's
`self.model_dump(by_alias=True)`:
* `None` is only added to the output dict for nullable fields that
were set at model initialization. Other fields with value `None`
are ignored.
"""
excluded_fields: Set[str] = set([])
_dict = self.model_dump(
by_alias=True,
exclude=excluded_fields,
exclude_none=True,
)
# override the default output from pydantic by calling `to_dict()` of label_name
if self.label_name:
_dict["label_name"] = self.label_name.to_dict()
# override the default output from pydantic by calling `to_dict()` of each item in keybind (list)
_items = []
if self.keybind:
for _item_keybind in self.keybind:
if _item_keybind:
_items.append(_item_keybind.to_dict())
_dict["keybind"] = _items
# override the default output from pydantic by calling `to_dict()` of annotation_type
if self.annotation_type:
_dict["annotation_type"] = self.annotation_type.to_dict()
# override the default output from pydantic by calling `to_dict()` of each value in field_values (dict)
_field_dict = {}
if self.field_values:
for _key_field_values in self.field_values:
if self.field_values[_key_field_values]:
_field_dict[_key_field_values] = self.field_values[_key_field_values].to_dict()
_dict["field_values"] = _field_dict
# override the default output from pydantic by calling `to_dict()` of color
if self.color:
_dict["color"] = self.color.to_dict()
return _dict
[docs]
@classmethod
def from_dict(cls, obj: Dict[str, Any] | None) -> Self | None:
"""Create an instance of LabelV3 from a dict"""
if obj is None:
return None
if not isinstance(obj, dict):
return cls.model_validate(obj)
_obj = cls.model_validate(
{
"label_id": obj.get("label_id"),
"label_name": InternationalizationMessage.from_dict(obj["label_name"]) if obj.get("label_name") is not None else None,
"keybind": [Keybind.from_dict(_item) for _item in obj["keybind"]] if obj.get("keybind") is not None else None,
"annotation_type": AnnotationType.from_dict(obj["annotation_type"]) if obj.get("annotation_type") is not None else None,
"field_values": dict((_k, AnnotationTypeFieldValue.from_dict(_v)) for _k, _v in obj["field_values"].items())
if obj.get("field_values") is not None
else None,
"additional_data_definitions": obj.get("additional_data_definitions"),
"color": Color.from_dict(obj["color"]) if obj.get("color") is not None else None,
"metadata": obj.get("metadata"),
}
)
return _obj