Skip to content

pydantic_modelsの追加 #698

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
"""
swagger-api-components.yaml に記載されたschemaを出力するためのヘッダ部分

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, Optional, Set

from pydantic import BaseModel, ConfigDict, Field, StrictStr
from typing_extensions import Self


class AcceptOrganizationInvitationRequest(BaseModel):
"""
AcceptOrganizationInvitationRequest
"""

token: StrictStr = Field(
description="[inviteOrganizationMember](#operation/inviteOrganizationMember) APIで送信された招待メールに記載されているトークンです。 メールに記載されているURLの`invitation-token`クエリパラメータの値が、トークンになります。 "
)
__properties: ClassVar[List[str]] = ["token"]

model_config = ConfigDict(
populate_by_name=True,
validate_assignment=True,
protected_namespaces=(),
)

def to_str(self) -> str:
"""Returns the string representation of the model using alias"""
return pprint.pformat(self.model_dump(by_alias=True))

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())

@classmethod
def from_json(cls, json_str: str) -> Optional[Self]:
"""Create an instance of AcceptOrganizationInvitationRequest from a JSON string"""
return cls.from_dict(json.loads(json_str))

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,
)
return _dict

@classmethod
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
"""Create an instance of AcceptOrganizationInvitationRequest from a dict"""
if obj is None:
return None

if not isinstance(obj, dict):
return cls.model_validate(obj)

_obj = cls.model_validate({"token": obj.get("token")})
return _obj
128 changes: 128 additions & 0 deletions annofabapi/pydantic_models/account.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
"""
swagger-api-components.yaml に記載されたschemaを出力するためのヘッダ部分

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 Annotated, Any, ClassVar, Dict, List, Optional, Set

from pydantic import BaseModel, ConfigDict, Field, StrictStr, field_validator
from typing_extensions import Self

from annofabapi.pydantic_models.key_layout import KeyLayout
from annofabapi.pydantic_models.lang import Lang


class Account(BaseModel):
"""
Account
"""

account_id: StrictStr = Field(description="アカウントID。[値の制約についてはこちら。](#section/API-Convention/APIID) ")
user_id: StrictStr = Field(description="ユーザーID。[値の制約についてはこちら。](#section/API-Convention/APIID) ")
username: StrictStr = Field(description="ユーザー名")
email: StrictStr = Field(description="メールアドレス")
lang: Lang
biography: Optional[Annotated[str, Field(min_length=0, strict=True, max_length=100)]] = Field(
default=None,
description="人物紹介、略歴。 この属性は、Annofab外の所属先や肩書などを表すために用います。 Annofab上の「複数の組織」で活動する場合、本籍を示すのに便利です。 ",
)
keylayout: KeyLayout
authority: StrictStr = Field(description="システム内部用のプロパティ")
account_type: StrictStr = Field(
description="アカウントの種別 * `annofab` - 通常の手順で登録されたアカウント。後から[外部アカウントとの紐付け](/docs/faq/#yyyub0)をしたアカウントの場合もこちらになります。 * `external` - [外部アカウントだけで作成したアカウント](/docs/faq/#v1u344) * `project_guest` - [issueProjectGuestUserToken](#operation/issueProjectGuestUserToken)によって作成されたされたアカウント "
)
updated_datetime: str = Field(description="更新日時")
__properties: ClassVar[List[str]] = [
"account_id",
"user_id",
"username",
"email",
"lang",
"biography",
"keylayout",
"authority",
"account_type",
"updated_datetime",
]

@field_validator("account_type")
def account_type_validate_enum(cls, value):
"""Validates the enum"""
if value not in set(["annofab", "external", "project_guest"]):
raise ValueError("must be one of enum values ('annofab', 'external', 'project_guest')")
return value

model_config = ConfigDict(
populate_by_name=True,
validate_assignment=True,
protected_namespaces=(),
)

def to_str(self) -> str:
"""Returns the string representation of the model using alias"""
return pprint.pformat(self.model_dump(by_alias=True))

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())

@classmethod
def from_json(cls, json_str: str) -> Optional[Self]:
"""Create an instance of Account from a JSON string"""
return cls.from_dict(json.loads(json_str))

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,
)
return _dict

@classmethod
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
"""Create an instance of Account from a dict"""
if obj is None:
return None

if not isinstance(obj, dict):
return cls.model_validate(obj)

_obj = cls.model_validate(
{
"account_id": obj.get("account_id"),
"user_id": obj.get("user_id"),
"username": obj.get("username"),
"email": obj.get("email"),
"lang": obj.get("lang"),
"biography": obj.get("biography"),
"keylayout": obj.get("keylayout"),
"authority": obj.get("authority"),
"account_type": obj.get("account_type"),
"updated_datetime": obj.get("updated_datetime"),
}
)
return _obj
115 changes: 115 additions & 0 deletions annofabapi/pydantic_models/account_worktime_statistics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
"""
swagger-api-components.yaml に記載されたschemaを出力するためのヘッダ部分

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, Optional, Set

from pydantic import BaseModel, ConfigDict, Field, StrictStr
from typing_extensions import Self

from annofabapi.pydantic_models.worktime_statistics_item import WorktimeStatisticsItem


class AccountWorktimeStatistics(BaseModel):
"""
AccountWorktimeStatistics
"""

account_id: StrictStr = Field(description="アカウントID。[値の制約についてはこちら。](#section/API-Convention/APIID) ")
by_tasks: List[WorktimeStatisticsItem] = Field(
description="タスクごとに計算した「画像1枚あたりの作業時間平均」の統計(動画プロジェクトの場合は空リスト)"
)
by_inputs: List[WorktimeStatisticsItem] = Field(description="画像1枚あたりの作業時間情報(動画プロジェクトの場合は空リスト)")
by_minutes: List[WorktimeStatisticsItem] = Field(description="動画1分あたりの作業時間情報(画像プロジェクトの場合は空リスト)")
__properties: ClassVar[List[str]] = ["account_id", "by_tasks", "by_inputs", "by_minutes"]

model_config = ConfigDict(
populate_by_name=True,
validate_assignment=True,
protected_namespaces=(),
)

def to_str(self) -> str:
"""Returns the string representation of the model using alias"""
return pprint.pformat(self.model_dump(by_alias=True))

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())

@classmethod
def from_json(cls, json_str: str) -> Optional[Self]:
"""Create an instance of AccountWorktimeStatistics from a JSON string"""
return cls.from_dict(json.loads(json_str))

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 each item in by_tasks (list)
_items = []
if self.by_tasks:
for _item_by_tasks in self.by_tasks:
if _item_by_tasks:
_items.append(_item_by_tasks.to_dict())
_dict["by_tasks"] = _items
# override the default output from pydantic by calling `to_dict()` of each item in by_inputs (list)
_items = []
if self.by_inputs:
for _item_by_inputs in self.by_inputs:
if _item_by_inputs:
_items.append(_item_by_inputs.to_dict())
_dict["by_inputs"] = _items
# override the default output from pydantic by calling `to_dict()` of each item in by_minutes (list)
_items = []
if self.by_minutes:
for _item_by_minutes in self.by_minutes:
if _item_by_minutes:
_items.append(_item_by_minutes.to_dict())
_dict["by_minutes"] = _items
return _dict

@classmethod
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
"""Create an instance of AccountWorktimeStatistics from a dict"""
if obj is None:
return None

if not isinstance(obj, dict):
return cls.model_validate(obj)

_obj = cls.model_validate(
{
"account_id": obj.get("account_id"),
"by_tasks": [WorktimeStatisticsItem.from_dict(_item) for _item in obj["by_tasks"]] if obj.get("by_tasks") is not None else None,
"by_inputs": [WorktimeStatisticsItem.from_dict(_item) for _item in obj["by_inputs"]] if obj.get("by_inputs") is not None else None,
"by_minutes": [WorktimeStatisticsItem.from_dict(_item) for _item in obj["by_minutes"]] if obj.get("by_minutes") is not None else None,
}
)
return _obj
Loading
Loading