Skip to content

Commit 9a29c26

Browse files
fix(python): remove warnings for HighlightResult and SnippetResult (#5284) (generated) [skip ci]
Co-authored-by: Clément Vannicatte <[email protected]>
1 parent db05110 commit 9a29c26

File tree

5 files changed

+42
-1
lines changed

5 files changed

+42
-1
lines changed

clients/algoliasearch-client-python/algoliasearch/search/models/hit.py

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from sys import version_info
1111
from typing import Any, Dict, Optional
1212

13-
from pydantic import BaseModel, ConfigDict
13+
from pydantic import BaseModel, ConfigDict, field_serializer
1414

1515
if version_info >= (3, 11):
1616
from typing import Self
@@ -59,6 +59,43 @@ class Hit(BaseModel):
5959
extra="allow",
6060
)
6161

62+
@staticmethod
63+
def __dump_item(item):
64+
return (
65+
item.model_dump(
66+
by_alias=True,
67+
exclude_none=True,
68+
exclude_unset=True,
69+
warnings="none",
70+
)
71+
if isinstance(item, BaseModel)
72+
else item
73+
)
74+
75+
@field_serializer("highlight_result")
76+
def serialize_highlight_result(self, v: HighlightResult | None):
77+
if v is None:
78+
return None
79+
80+
if isinstance(v, dict):
81+
return {k: self.__dump_item(val) for k, val in v.items()}
82+
elif isinstance(v, list):
83+
return [self.__dump_item(val) for val in v]
84+
else:
85+
return self.__dump_item(v)
86+
87+
@field_serializer("snippet_result")
88+
def serialize_snippet_result(self, v: SnippetResult | None):
89+
if v is None:
90+
return None
91+
92+
if isinstance(v, dict):
93+
return {k: self.__dump_item(val) for k, val in v.items()}
94+
elif isinstance(v, list):
95+
return [self.__dump_item(val) for val in v]
96+
else:
97+
return self.__dump_item(v)
98+
6299
def to_json(self) -> str:
63100
return self.model_dump_json(by_alias=True, exclude_unset=True)
64101

docs/bundled/search.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6958,6 +6958,7 @@
69586958
"type": "object",
69596959
"description": "Search result.\n\nA hit is a record from your index, augmented with special attributes for highlighting, snippeting, and ranking.\n",
69606960
"x-is-generic": true,
6961+
"x-is-hit-object": true,
69616962
"additionalProperties": true,
69626963
"required": [
69636964
"objectID"

docs/bundled/search.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21218,6 +21218,7 @@ components:
2121821218
A hit is a record from your index, augmented with special attributes for
2121921219
highlighting, snippeting, and ranking.
2122021220
x-is-generic: true
21221+
x-is-hit-object: true
2122121222
additionalProperties: true
2122221223
required:
2122321224
- objectID

specs/bundled/algoliasearch.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2755,6 +2755,7 @@ components:
27552755
A hit is a record from your index, augmented with special attributes for
27562756
highlighting, snippeting, and ranking.
27572757
x-is-generic: true
2758+
x-is-hit-object: true
27582759
additionalProperties: true
27592760
required:
27602761
- objectID

specs/bundled/search.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6448,6 +6448,7 @@ components:
64486448
A hit is a record from your index, augmented with special attributes for
64496449
highlighting, snippeting, and ranking.
64506450
x-is-generic: true
6451+
x-is-hit-object: true
64516452
additionalProperties: true
64526453
required:
64536454
- objectID

0 commit comments

Comments
 (0)