|
| 1 | +# coding: utf-8 |
| 2 | + |
| 3 | +""" |
| 4 | +Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT. |
| 5 | +""" |
| 6 | + |
| 7 | +from __future__ import annotations |
| 8 | + |
| 9 | +from json import loads |
| 10 | +from typing import Any, ClassVar, Dict, List, Optional, Self |
| 11 | + |
| 12 | +from pydantic import BaseModel, ConfigDict, StrictStr |
| 13 | + |
| 14 | + |
| 15 | +class ErrorBase(BaseModel): |
| 16 | + """ |
| 17 | + Error. |
| 18 | + """ |
| 19 | + |
| 20 | + message: Optional[StrictStr] = None |
| 21 | + additional_properties: Dict[str, Any] = {} |
| 22 | + __properties: ClassVar[List[str]] = ["message"] |
| 23 | + |
| 24 | + model_config = ConfigDict( |
| 25 | + use_enum_values=True, populate_by_name=True, validate_assignment=True |
| 26 | + ) |
| 27 | + |
| 28 | + def to_json(self) -> str: |
| 29 | + return self.model_dump_json(by_alias=True, exclude_unset=True) |
| 30 | + |
| 31 | + @classmethod |
| 32 | + def from_json(cls, json_str: str) -> Self: |
| 33 | + """Create an instance of ErrorBase from a JSON string""" |
| 34 | + return cls.from_dict(loads(json_str)) |
| 35 | + |
| 36 | + def to_dict(self) -> Dict[str, Any]: |
| 37 | + """Return the dictionary representation of the model using alias. |
| 38 | +
|
| 39 | + This has the following differences from calling pydantic's |
| 40 | + `self.model_dump(by_alias=True)`: |
| 41 | +
|
| 42 | + * `None` is only added to the output dict for nullable fields that |
| 43 | + were set at model initialization. Other fields with value `None` |
| 44 | + are ignored. |
| 45 | + * Fields in `self.additional_properties` are added to the output dict. |
| 46 | + """ |
| 47 | + _dict = self.model_dump( |
| 48 | + by_alias=True, |
| 49 | + exclude={ |
| 50 | + "additional_properties", |
| 51 | + }, |
| 52 | + exclude_none=True, |
| 53 | + ) |
| 54 | + # puts key-value pairs in additional_properties in the top level |
| 55 | + if self.additional_properties is not None: |
| 56 | + for _key, _value in self.additional_properties.items(): |
| 57 | + _dict[_key] = _value |
| 58 | + |
| 59 | + return _dict |
| 60 | + |
| 61 | + @classmethod |
| 62 | + def from_dict(cls, obj: Dict) -> Self: |
| 63 | + """Create an instance of ErrorBase from a dict""" |
| 64 | + if obj is None: |
| 65 | + return None |
| 66 | + |
| 67 | + if not isinstance(obj, dict): |
| 68 | + return cls.model_validate(obj) |
| 69 | + |
| 70 | + _obj = cls.model_validate({"message": obj.get("message")}) |
| 71 | + # store additional fields in additional_properties |
| 72 | + for _key in obj.keys(): |
| 73 | + if _key not in cls.__properties: |
| 74 | + _obj.additional_properties[_key] = obj.get(_key) |
| 75 | + |
| 76 | + return _obj |
0 commit comments