|
| 1 | +# coding: utf-8 |
| 2 | + |
| 3 | +""" |
| 4 | + Book Store API |
| 5 | +
|
| 6 | + Book Store Web API |
| 7 | +
|
| 8 | + The version of the OpenAPI document: v1 |
| 9 | + Generated by OpenAPI Generator (https://openapi-generator.tech) |
| 10 | +
|
| 11 | + Do not edit the class manually. |
| 12 | +""" # noqa: E501 |
| 13 | + |
| 14 | +from __future__ import annotations |
| 15 | + |
| 16 | +import json |
| 17 | +import pprint |
| 18 | +import re # noqa: F401 |
| 19 | +from datetime import datetime |
| 20 | +from typing import Any, ClassVar, Dict, List, Optional, Union |
| 21 | + |
| 22 | +from pydantic import BaseModel, StrictFloat, StrictInt, StrictStr |
| 23 | +from pydantic import Field |
| 24 | + |
| 25 | +try: |
| 26 | + from typing import Self |
| 27 | +except ImportError: |
| 28 | + from typing_extensions import Self |
| 29 | + |
| 30 | + |
| 31 | +class BookModal(BaseModel): |
| 32 | + """ |
| 33 | + |
| 34 | + """ # noqa: E501 |
| 35 | + isbn: Optional[StrictStr] = None |
| 36 | + title: Optional[StrictStr] = None |
| 37 | + sub_title: Optional[StrictStr] = Field(default=None, alias="subTitle") |
| 38 | + author: Optional[StrictStr] = None |
| 39 | + publish_date: Optional[datetime] = None |
| 40 | + publisher: Optional[StrictStr] = None |
| 41 | + pages: Optional[Union[StrictFloat, StrictInt]] = None |
| 42 | + description: Optional[StrictStr] = None |
| 43 | + website: Optional[StrictStr] = None |
| 44 | + __properties: ClassVar[List[str]] = ["isbn", "title", "subTitle", "author", "publish_date", "publisher", "pages", |
| 45 | + "description", "website"] |
| 46 | + |
| 47 | + model_config = { |
| 48 | + "populate_by_name": True, |
| 49 | + "validate_assignment": True, |
| 50 | + "protected_namespaces": (), |
| 51 | + } |
| 52 | + |
| 53 | + def to_str(self) -> str: |
| 54 | + """Returns the string representation of the model using alias""" |
| 55 | + return pprint.pformat(self.model_dump(by_alias=True)) |
| 56 | + |
| 57 | + def to_json(self) -> str: |
| 58 | + """Returns the JSON representation of the model using alias""" |
| 59 | + # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead |
| 60 | + return json.dumps(self.to_dict()) |
| 61 | + |
| 62 | + @classmethod |
| 63 | + def from_json(cls, json_str: str) -> Self: |
| 64 | + """Create an instance of BookModal from a JSON string""" |
| 65 | + return cls.from_dict(json.loads(json_str)) |
| 66 | + |
| 67 | + def to_dict(self) -> Dict[str, Any]: |
| 68 | + """Return the dictionary representation of the model using alias. |
| 69 | +
|
| 70 | + This has the following differences from calling pydantic's |
| 71 | + `self.model_dump(by_alias=True)`: |
| 72 | +
|
| 73 | + * `None` is only added to the output dict for nullable fields that |
| 74 | + were set at model initialization. Other fields with value `None` |
| 75 | + are ignored. |
| 76 | + """ |
| 77 | + _dict = self.model_dump( |
| 78 | + by_alias=True, |
| 79 | + exclude={ |
| 80 | + }, |
| 81 | + exclude_none=True, |
| 82 | + ) |
| 83 | + return _dict |
| 84 | + |
| 85 | + @classmethod |
| 86 | + def from_dict(cls, obj: Dict) -> Self: |
| 87 | + """Create an instance of BookModal from a dict""" |
| 88 | + if obj is None: |
| 89 | + return None |
| 90 | + |
| 91 | + if not isinstance(obj, dict): |
| 92 | + return cls.model_validate(obj) |
| 93 | + |
| 94 | + _obj = cls.model_validate({ |
| 95 | + "isbn": obj.get("isbn"), |
| 96 | + "title": obj.get("title"), |
| 97 | + "subTitle": obj.get("subTitle"), |
| 98 | + "author": obj.get("author"), |
| 99 | + "publish_date": obj.get("publish_date"), |
| 100 | + "publisher": obj.get("publisher"), |
| 101 | + "pages": obj.get("pages"), |
| 102 | + "description": obj.get("description"), |
| 103 | + "website": obj.get("website") |
| 104 | + }) |
| 105 | + return _obj |
0 commit comments