|
| 1 | +# coding: utf-8 |
| 2 | + |
| 3 | +""" |
| 4 | + Manticore Search Client |
| 5 | +
|
| 6 | + Сlient for Manticore Search. |
| 7 | +
|
| 8 | + The version of the OpenAPI document: 5.0.0 |
| 9 | + Contact: info@manticoresearch.com |
| 10 | + Generated by OpenAPI Generator (https://openapi-generator.tech) |
| 11 | +
|
| 12 | + Do not edit the class manually. |
| 13 | +""" # noqa: E501 |
| 14 | + |
| 15 | + |
| 16 | +from __future__ import annotations |
| 17 | +import json |
| 18 | +import pprint |
| 19 | +from pydantic import BaseModel, ConfigDict, Field, StrictInt, StrictStr, ValidationError, field_validator |
| 20 | +from typing import Any, List, Optional |
| 21 | +from pydantic import StrictStr, Field |
| 22 | +from typing import Union, List, Set, Optional, Dict |
| 23 | +from typing_extensions import Literal, Self |
| 24 | + |
| 25 | +HITSHITSID_ONE_OF_SCHEMAS = ["int", "str"] |
| 26 | + |
| 27 | +class HitsHitsId(BaseModel): |
| 28 | + """ |
| 29 | + HitsHitsId |
| 30 | + """ |
| 31 | + # data type: str |
| 32 | + oneof_schema_1_validator: Optional[StrictStr] = Field(default=None, description="The ID of the matched document") |
| 33 | + # data type: int |
| 34 | + oneof_schema_2_validator: Optional[StrictInt] = Field(default=None, description="The ID of the matched document") |
| 35 | + actual_instance: Optional[Union[int, str]] = None |
| 36 | + one_of_schemas: Set[str] = { "int", "str" } |
| 37 | + |
| 38 | + model_config = ConfigDict( |
| 39 | + validate_assignment=True, |
| 40 | + protected_namespaces=(), |
| 41 | + ) |
| 42 | + |
| 43 | + |
| 44 | + def __init__(self, *args, **kwargs) -> None: |
| 45 | + if args: |
| 46 | + if len(args) > 1: |
| 47 | + raise ValueError("If a position argument is used, only 1 is allowed to set `actual_instance`") |
| 48 | + if kwargs: |
| 49 | + raise ValueError("If a position argument is used, keyword arguments cannot be used.") |
| 50 | + super().__init__(actual_instance=args[0]) |
| 51 | + else: |
| 52 | + super().__init__(**kwargs) |
| 53 | + |
| 54 | + @field_validator('actual_instance') |
| 55 | + def actual_instance_must_validate_oneof(cls, v): |
| 56 | + instance = HitsHitsId.model_construct() |
| 57 | + error_messages = [] |
| 58 | + match = 0 |
| 59 | + # validate data type: str |
| 60 | + try: |
| 61 | + instance.oneof_schema_1_validator = v |
| 62 | + match += 1 |
| 63 | + except (ValidationError, ValueError) as e: |
| 64 | + error_messages.append(str(e)) |
| 65 | + # validate data type: int |
| 66 | + try: |
| 67 | + instance.oneof_schema_2_validator = v |
| 68 | + match += 1 |
| 69 | + except (ValidationError, ValueError) as e: |
| 70 | + error_messages.append(str(e)) |
| 71 | + if match > 1: |
| 72 | + # more than 1 match |
| 73 | + raise ValueError("Multiple matches found when setting `actual_instance` in HitsHitsId with oneOf schemas: int, str. Details: " + ", ".join(error_messages)) |
| 74 | + elif match == 0: |
| 75 | + # no match |
| 76 | + raise ValueError("No match found when setting `actual_instance` in HitsHitsId with oneOf schemas: int, str. Details: " + ", ".join(error_messages)) |
| 77 | + else: |
| 78 | + return v |
| 79 | + |
| 80 | + @classmethod |
| 81 | + def from_dict(cls, obj: Union[str, Dict[str, Any]]) -> Self: |
| 82 | + return cls.from_json(json.dumps(obj)) |
| 83 | + |
| 84 | + @classmethod |
| 85 | + def from_json(cls, json_str: str) -> Self: |
| 86 | + """Returns the object represented by the json string""" |
| 87 | + instance = cls.model_construct() |
| 88 | + error_messages = [] |
| 89 | + match = 0 |
| 90 | + |
| 91 | + # deserialize data into str |
| 92 | + try: |
| 93 | + # validation |
| 94 | + instance.oneof_schema_1_validator = json.loads(json_str) |
| 95 | + # assign value to actual_instance |
| 96 | + instance.actual_instance = instance.oneof_schema_1_validator |
| 97 | + match += 1 |
| 98 | + except (ValidationError, ValueError) as e: |
| 99 | + error_messages.append(str(e)) |
| 100 | + # deserialize data into int |
| 101 | + try: |
| 102 | + # validation |
| 103 | + instance.oneof_schema_2_validator = json.loads(json_str) |
| 104 | + # assign value to actual_instance |
| 105 | + instance.actual_instance = instance.oneof_schema_2_validator |
| 106 | + match += 1 |
| 107 | + except (ValidationError, ValueError) as e: |
| 108 | + error_messages.append(str(e)) |
| 109 | + |
| 110 | + if match > 1: |
| 111 | + # more than 1 match |
| 112 | + raise ValueError("Multiple matches found when deserializing the JSON string into HitsHitsId with oneOf schemas: int, str. Details: " + ", ".join(error_messages)) |
| 113 | + elif match == 0: |
| 114 | + # no match |
| 115 | + raise ValueError("No match found when deserializing the JSON string into HitsHitsId with oneOf schemas: int, str. Details: " + ", ".join(error_messages)) |
| 116 | + else: |
| 117 | + return instance |
| 118 | + |
| 119 | + def to_json(self) -> str: |
| 120 | + """Returns the JSON representation of the actual instance""" |
| 121 | + if self.actual_instance is None: |
| 122 | + return "null" |
| 123 | + |
| 124 | + if hasattr(self.actual_instance, "to_json") and callable(self.actual_instance.to_json): |
| 125 | + return self.actual_instance.to_json() |
| 126 | + else: |
| 127 | + return json.dumps(self.actual_instance) |
| 128 | + |
| 129 | + def to_dict(self) -> Optional[Union[Dict[str, Any], int, str]]: |
| 130 | + """Returns the dict representation of the actual instance""" |
| 131 | + if self.actual_instance is None: |
| 132 | + return None |
| 133 | + |
| 134 | + if hasattr(self.actual_instance, "to_dict") and callable(self.actual_instance.to_dict): |
| 135 | + return self.actual_instance.to_dict() |
| 136 | + else: |
| 137 | + # primitive type |
| 138 | + return self.actual_instance |
| 139 | + |
| 140 | + def to_str(self) -> str: |
| 141 | + """Returns the string representation of the actual instance""" |
| 142 | + return pprint.pformat(self.model_dump()) |
| 143 | + |
| 144 | + |
0 commit comments