Skip to content

Commit 6acfeb1

Browse files
feat(specs): add fields for metadata in composition injectedItems (generated)
algolia/api-clients-automation#5241 Co-authored-by: algolia-bot <[email protected]> Co-authored-by: Gavin Wade <[email protected]>
1 parent 45f5bbc commit 6acfeb1

File tree

3 files changed

+83
-0
lines changed

3 files changed

+83
-0
lines changed

algoliasearch/composition/models/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from .highlight_result import HighlightResult
3030
from .highlight_result_option import HighlightResultOption
3131
from .hit import Hit
32+
from .hit_metadata import HitMetadata
3233
from .hit_ranking_info import HitRankingInfo
3334
from .inside_bounding_box import InsideBoundingBox
3435
from .match_level import MatchLevel
@@ -84,6 +85,7 @@
8485
"HighlightResult",
8586
"HighlightResultOption",
8687
"Hit",
88+
"HitMetadata",
8789
"HitRankingInfo",
8890
"InsideBoundingBox",
8991
"MatchLevel",

algoliasearch/composition/models/hit.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020

2121
from algoliasearch.composition.models.highlight_result import HighlightResult
22+
from algoliasearch.composition.models.hit_metadata import HitMetadata
2223
from algoliasearch.composition.models.hit_ranking_info import HitRankingInfo
2324
from algoliasearch.composition.models.snippet_result import SnippetResult
2425

@@ -28,6 +29,7 @@
2829
"snippet_result": "_snippetResult",
2930
"ranking_info": "_rankingInfo",
3031
"distinct_seq_id": "_distinctSeqID",
32+
"extra": "_extra",
3133
}
3234

3335

@@ -48,6 +50,7 @@ class Hit(BaseModel):
4850
""" Snippets that show the context around a matching search query. """
4951
ranking_info: Optional[HitRankingInfo] = None
5052
distinct_seq_id: Optional[int] = None
53+
extra: Optional[HitMetadata] = None
5154

5255
model_config = ConfigDict(
5356
strict=False,
@@ -105,5 +108,10 @@ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
105108
if obj.get("_rankingInfo") is not None
106109
else None
107110
)
111+
obj["_extra"] = (
112+
HitMetadata.from_dict(obj["_extra"])
113+
if obj.get("_extra") is not None
114+
else None
115+
)
108116

109117
return cls.model_validate(obj)
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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 sys import version_info
11+
from typing import Any, Dict, Optional
12+
13+
from pydantic import BaseModel, ConfigDict
14+
15+
if version_info >= (3, 11):
16+
from typing import Self
17+
else:
18+
from typing_extensions import Self
19+
20+
21+
_ALIASES = {
22+
"injected_item_key": "_injectedItemKey",
23+
}
24+
25+
26+
def _alias_generator(name: str) -> str:
27+
return _ALIASES.get(name, name)
28+
29+
30+
class HitMetadata(BaseModel):
31+
"""
32+
An object that contains the extra key-value pairs provided in the injectedItem definition.
33+
"""
34+
35+
injected_item_key: Optional[str] = None
36+
""" The key of the injectedItem that inserted this metadata. """
37+
38+
model_config = ConfigDict(
39+
strict=False,
40+
use_enum_values=True,
41+
populate_by_name=True,
42+
validate_assignment=True,
43+
protected_namespaces=(),
44+
alias_generator=_alias_generator,
45+
extra="allow",
46+
)
47+
48+
def to_json(self) -> str:
49+
return self.model_dump_json(by_alias=True, exclude_unset=True)
50+
51+
@classmethod
52+
def from_json(cls, json_str: str) -> Optional[Self]:
53+
"""Create an instance of HitMetadata from a JSON string"""
54+
return cls.from_dict(loads(json_str))
55+
56+
def to_dict(self) -> Dict[str, Any]:
57+
"""Return the dictionary representation of the model using alias."""
58+
return self.model_dump(
59+
by_alias=True,
60+
exclude_none=True,
61+
exclude_unset=True,
62+
)
63+
64+
@classmethod
65+
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
66+
"""Create an instance of HitMetadata from a dict"""
67+
if obj is None:
68+
return None
69+
70+
if not isinstance(obj, dict):
71+
return cls.model_validate(obj)
72+
73+
return cls.model_validate(obj)

0 commit comments

Comments
 (0)