|
| 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 dumps |
| 10 | +from sys import version_info |
| 11 | +from typing import Any, Dict, Optional, Set, Union |
| 12 | + |
| 13 | +from pydantic import BaseModel, Field, ValidationError, model_serializer |
| 14 | + |
| 15 | +if version_info >= (3, 11): |
| 16 | + from typing import Self |
| 17 | +else: |
| 18 | + from typing_extensions import Self |
| 19 | + |
| 20 | + |
| 21 | +from algoliasearch.ingestion.models.transformation_code import TransformationCode |
| 22 | +from algoliasearch.ingestion.models.transformation_no_code import TransformationNoCode |
| 23 | + |
| 24 | + |
| 25 | +class TransformationInput(BaseModel): |
| 26 | + """ |
| 27 | + The input for the transformation, which can be either code or a no-code configuration. |
| 28 | + """ |
| 29 | + |
| 30 | + oneof_schema_1_validator: Optional[TransformationCode] = Field(default=None) |
| 31 | + |
| 32 | + oneof_schema_2_validator: Optional[TransformationNoCode] = Field(default=None) |
| 33 | + |
| 34 | + actual_instance: Union[TransformationCode, TransformationNoCode, None] = None |
| 35 | + one_of_schemas: Set[str] = {"TransformationCode", "TransformationNoCode"} |
| 36 | + |
| 37 | + def __init__(self, *args, **kwargs) -> None: |
| 38 | + if args: |
| 39 | + if len(args) > 1: |
| 40 | + raise ValueError( |
| 41 | + "If a position argument is used, only 1 is allowed to set `actual_instance`" |
| 42 | + ) |
| 43 | + if kwargs: |
| 44 | + raise ValueError( |
| 45 | + "If a position argument is used, keyword arguments cannot be used." |
| 46 | + ) |
| 47 | + super().__init__(actual_instance=args[0]) # pyright: ignore |
| 48 | + else: |
| 49 | + super().__init__(**kwargs) |
| 50 | + |
| 51 | + @model_serializer |
| 52 | + def unwrap_actual_instance( |
| 53 | + self, |
| 54 | + ) -> Union[TransformationCode, TransformationNoCode, Self, None]: |
| 55 | + """ |
| 56 | + Unwraps the `actual_instance` when calling the `to_json` method. |
| 57 | + """ |
| 58 | + return self.actual_instance if hasattr(self, "actual_instance") else self |
| 59 | + |
| 60 | + @classmethod |
| 61 | + def from_dict(cls, obj: Union[str, Dict[str, Any]]) -> Self: |
| 62 | + """Create an instance of TransformationInput from a JSON string""" |
| 63 | + return cls.from_json(dumps(obj)) |
| 64 | + |
| 65 | + @classmethod |
| 66 | + def from_json(cls, json_str: str) -> Self: |
| 67 | + """Returns the object represented by the json string""" |
| 68 | + instance = cls.model_construct() |
| 69 | + error_messages = [] |
| 70 | + |
| 71 | + try: |
| 72 | + instance.actual_instance = TransformationCode.from_json(json_str) |
| 73 | + |
| 74 | + return instance |
| 75 | + except (ValidationError, ValueError) as e: |
| 76 | + error_messages.append(str(e)) |
| 77 | + try: |
| 78 | + instance.actual_instance = TransformationNoCode.from_json(json_str) |
| 79 | + |
| 80 | + return instance |
| 81 | + except (ValidationError, ValueError) as e: |
| 82 | + error_messages.append(str(e)) |
| 83 | + |
| 84 | + raise ValueError( |
| 85 | + "No match found when deserializing the JSON string into TransformationInput with oneOf schemas: TransformationCode, TransformationNoCode. Details: " |
| 86 | + + ", ".join(error_messages) |
| 87 | + ) |
| 88 | + |
| 89 | + def to_json(self) -> str: |
| 90 | + """Returns the JSON representation of the actual instance""" |
| 91 | + if self.actual_instance is None: |
| 92 | + return "null" |
| 93 | + |
| 94 | + if hasattr(self.actual_instance, "to_json") and callable( |
| 95 | + self.actual_instance.to_json # pyright: ignore |
| 96 | + ): |
| 97 | + return self.actual_instance.to_json() # pyright: ignore |
| 98 | + else: |
| 99 | + return dumps(self.actual_instance) |
| 100 | + |
| 101 | + def to_dict( |
| 102 | + self, |
| 103 | + ) -> Optional[Union[Dict[str, Any], TransformationCode, TransformationNoCode]]: |
| 104 | + """Returns the dict representation of the actual instance""" |
| 105 | + if self.actual_instance is None: |
| 106 | + return None |
| 107 | + |
| 108 | + if hasattr(self.actual_instance, "to_dict") and callable( |
| 109 | + self.actual_instance.to_dict # pyright: ignore |
| 110 | + ): |
| 111 | + return self.actual_instance.to_dict() # pyright: ignore |
| 112 | + else: |
| 113 | + return self.actual_instance # pyright: ignore |
0 commit comments