Source code for annofabapi.pydantic_models.label_v2

"""


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_editor_feature import AnnotationEditorFeature
from annofabapi.pydantic_models.annotation_type import AnnotationType
from annofabapi.pydantic_models.bounding_box_metadata import BoundingBoxMetadata
from annofabapi.pydantic_models.color import Color
from annofabapi.pydantic_models.internationalization_message import InternationalizationMessage
from annofabapi.pydantic_models.keybind import Keybind
from annofabapi.pydantic_models.segmentation_metadata import SegmentationMetadata


[docs] class LabelV2(BaseModel): """ LabelV2 """ label_id: StrictStr = Field(description="ラベルID。[値の制約についてはこちら。](#section/API-Convention/APIID) ") label_name: InternationalizationMessage keybind: List[Keybind] = Field(description="ショートカットキー") annotation_type: AnnotationType bounding_box_metadata: BoundingBoxMetadata | None = None segmentation_metadata: SegmentationMetadata | None = None additional_data_definitions: List[StrictStr] = Field(description="ラベルに所属する属性のID") color: Color annotation_editor_feature: AnnotationEditorFeature metadata: Dict[str, StrictStr] | None = Field(default=None, description="ユーザーが自由に登録できるkey-value型のメタデータです。 ") __properties: ClassVar[List[str]] = [ "label_id", "label_name", "keybind", "annotation_type", "bounding_box_metadata", "segmentation_metadata", "additional_data_definitions", "color", "annotation_editor_feature", "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 LabelV2 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 bounding_box_metadata if self.bounding_box_metadata: _dict["bounding_box_metadata"] = self.bounding_box_metadata.to_dict() # override the default output from pydantic by calling `to_dict()` of segmentation_metadata if self.segmentation_metadata: _dict["segmentation_metadata"] = self.segmentation_metadata.to_dict() # override the default output from pydantic by calling `to_dict()` of color if self.color: _dict["color"] = self.color.to_dict() # override the default output from pydantic by calling `to_dict()` of annotation_editor_feature if self.annotation_editor_feature: _dict["annotation_editor_feature"] = self.annotation_editor_feature.to_dict() return _dict
[docs] @classmethod def from_dict(cls, obj: Dict[str, Any] | None) -> Self | None: """Create an instance of LabelV2 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, "bounding_box_metadata": BoundingBoxMetadata.from_dict(obj["bounding_box_metadata"]) if obj.get("bounding_box_metadata") is not None else None, "segmentation_metadata": SegmentationMetadata.from_dict(obj["segmentation_metadata"]) if obj.get("segmentation_metadata") 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, "annotation_editor_feature": AnnotationEditorFeature.from_dict(obj["annotation_editor_feature"]) if obj.get("annotation_editor_feature") is not None else None, "metadata": obj.get("metadata"), } ) return _obj