Skip to content

Commit ce2690a

Browse files
algolia-botrenovate[bot]shortcutsmillotp
committed
chore(deps): dependencies 2025-04-28 (generated)
algolia/api-clients-automation#4785 Co-authored-by: algolia-bot <accounts+algolia-api-client-bot@algolia.com> Co-authored-by: Algolia Bot <30854082+algolia-bot@users.noreply.github.com> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: shortcuts <vannicattec@gmail.com> Co-authored-by: Pierre Millot <pierre.millot@algolia.com>
1 parent 4faf5c6 commit ce2690a

File tree

4 files changed

+81
-181
lines changed

4 files changed

+81
-181
lines changed

algoliasearch/ingestion/models/destination_index_name.py

Lines changed: 0 additions & 82 deletions
This file was deleted.

algoliasearch/ingestion/models/destination_input.py

Lines changed: 50 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -6,95 +6,77 @@
66

77
from __future__ import annotations
88

9-
from json import dumps
9+
from json import loads
1010
from sys import version_info
11-
from typing import Any, Dict, Optional, Set, Union
11+
from typing import Any, Dict, List, Optional
1212

13-
from pydantic import BaseModel, Field, ValidationError, model_serializer
13+
from pydantic import BaseModel, ConfigDict
1414

1515
if version_info >= (3, 11):
1616
from typing import Self
1717
else:
1818
from typing_extensions import Self
1919

2020

21-
from algoliasearch.ingestion.models.destination_index_name import DestinationIndexName
21+
from algoliasearch.ingestion.models.record_type import RecordType
22+
23+
_ALIASES = {
24+
"index_name": "indexName",
25+
"record_type": "recordType",
26+
"attributes_to_exclude": "attributesToExclude",
27+
}
28+
29+
30+
def _alias_generator(name: str) -> str:
31+
return _ALIASES.get(name, name)
2232

2333

2434
class DestinationInput(BaseModel):
2535
"""
2636
DestinationInput
2737
"""
2838

29-
oneof_schema_1_validator: Optional[DestinationIndexName] = Field(default=None)
30-
31-
actual_instance: Union[DestinationIndexName, None] = None
32-
one_of_schemas: Set[str] = {"DestinationIndexName"}
33-
34-
def __init__(self, *args, **kwargs) -> None:
35-
if args:
36-
if len(args) > 1:
37-
raise ValueError(
38-
"If a position argument is used, only 1 is allowed to set `actual_instance`"
39-
)
40-
if kwargs:
41-
raise ValueError(
42-
"If a position argument is used, keyword arguments cannot be used."
43-
)
44-
super().__init__(actual_instance=args[0]) # pyright: ignore
45-
else:
46-
super().__init__(**kwargs)
47-
48-
@model_serializer
49-
def unwrap_actual_instance(self) -> Union[DestinationIndexName, Self, None]:
50-
"""
51-
Unwraps the `actual_instance` when calling the `to_json` method.
52-
"""
53-
return self.actual_instance if hasattr(self, "actual_instance") else self
39+
index_name: str
40+
""" Algolia index name (case-sensitive). """
41+
record_type: Optional[RecordType] = None
42+
attributes_to_exclude: Optional[List[str]] = None
43+
""" Attributes from your source to exclude from Algolia records. Not all your data attributes will be useful for searching. Keeping your Algolia records small increases indexing and search performance. - Exclude nested attributes with `.` notation. For example, `foo.bar` indexes the `foo` attribute and all its children **except** the `bar` attribute. - Exclude attributes from arrays with `[i]`, where `i` is the index of the array element. For example, `foo.[0].bar` only excludes the `bar` attribute from the first element of the `foo` array, but indexes the complete `foo` attribute for all other elements. Use `*` as wildcard: `foo.[*].bar` excludes `bar` from all elements of the `foo` array. """
44+
45+
model_config = ConfigDict(
46+
strict=False,
47+
use_enum_values=True,
48+
populate_by_name=True,
49+
validate_assignment=True,
50+
protected_namespaces=(),
51+
alias_generator=_alias_generator,
52+
extra="allow",
53+
)
54+
55+
def to_json(self) -> str:
56+
return self.model_dump_json(by_alias=True, exclude_unset=True)
5457

5558
@classmethod
56-
def from_dict(cls, obj: Union[str, Dict[str, Any]]) -> Self:
59+
def from_json(cls, json_str: str) -> Optional[Self]:
5760
"""Create an instance of DestinationInput from a JSON string"""
58-
return cls.from_json(dumps(obj))
61+
return cls.from_dict(loads(json_str))
62+
63+
def to_dict(self) -> Dict[str, Any]:
64+
"""Return the dictionary representation of the model using alias."""
65+
return self.model_dump(
66+
by_alias=True,
67+
exclude_none=True,
68+
exclude_unset=True,
69+
)
5970

6071
@classmethod
61-
def from_json(cls, json_str: str) -> Self:
62-
"""Returns the object represented by the json string"""
63-
instance = cls.model_construct()
64-
error_messages = []
65-
66-
try:
67-
instance.actual_instance = DestinationIndexName.from_json(json_str)
68-
69-
return instance
70-
except (ValidationError, ValueError) as e:
71-
error_messages.append(str(e))
72+
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
73+
"""Create an instance of DestinationInput from a dict"""
74+
if obj is None:
75+
return None
7276

73-
raise ValueError(
74-
"No match found when deserializing the JSON string into DestinationInput with oneOf schemas: DestinationIndexName. Details: "
75-
+ ", ".join(error_messages)
76-
)
77+
if not isinstance(obj, dict):
78+
return cls.model_validate(obj)
7779

78-
def to_json(self) -> str:
79-
"""Returns the JSON representation of the actual instance"""
80-
if self.actual_instance is None:
81-
return "null"
82-
83-
if hasattr(self.actual_instance, "to_json") and callable(
84-
self.actual_instance.to_json # pyright: ignore
85-
):
86-
return self.actual_instance.to_json() # pyright: ignore
87-
else:
88-
return dumps(self.actual_instance)
89-
90-
def to_dict(self) -> Optional[Union[Dict[str, Any], DestinationIndexName]]:
91-
"""Returns the dict representation of the actual instance"""
92-
if self.actual_instance is None:
93-
return None
80+
obj["recordType"] = obj.get("recordType")
9481

95-
if hasattr(self.actual_instance, "to_dict") and callable(
96-
self.actual_instance.to_dict # pyright: ignore
97-
):
98-
return self.actual_instance.to_dict() # pyright: ignore
99-
else:
100-
return self.actual_instance # pyright: ignore
82+
return cls.model_validate(obj)

poetry.lock

Lines changed: 30 additions & 30 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ async-timeout = ">= 4.0.3"
2323
pydantic = ">= 2"
2424

2525
[tool.poetry.group.dev.dependencies]
26-
ruff = "== 0.9.6"
26+
ruff = "== 0.11.7"
2727
pyright = "== 1.1.391"
2828

2929
[tool.ruff]

0 commit comments

Comments
 (0)