Skip to content

Commit b2b0c16

Browse files
feat(specs): add with transformation helpers (generated)
algolia/api-clients-automation#4931 Co-authored-by: algolia-bot <accounts+algolia-api-client-bot@algolia.com> Co-authored-by: Clément Vannicatte <vannicattec@gmail.com>
1 parent 8eb9a4a commit b2b0c16

File tree

6 files changed

+279
-3
lines changed

6 files changed

+279
-3
lines changed

algoliasearch/ingestion/models/watch_response.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ class WatchResponse(BaseModel):
4444
event_id: Optional[str] = None
4545
""" Universally unique identifier (UUID) of an event. """
4646
data: Optional[List[object]] = None
47-
""" when used with discovering or validating sources, the sampled data of your source is returned. """
47+
""" This field is always null when used with the Push endpoint. When used for a source discover or source validate run, it will include the sampled data of the source. """
4848
events: Optional[List[Event]] = None
49-
""" in case of error, observability events will be added to the response, if any. """
49+
""" in case of error, observability events will be added to the response. """
5050
message: Optional[str] = None
51-
""" a message describing the outcome of a validate run. """
51+
""" a message describing the outcome of the operation that has been ran (push, discover or validate) run. """
5252
created_at: Optional[str] = None
5353
""" Date of creation in RFC 3339 format. """
5454

algoliasearch/search/models/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@
6262
from .edit import Edit
6363
from .edit_type import EditType
6464
from .error_base import ErrorBase
65+
from .event import Event
66+
from .event_status import EventStatus
67+
from .event_type import EventType
6568
from .exact_on_single_word_query import ExactOnSingleWordQuery
6669
from .exhaustive import Exhaustive
6770
from .facet_filters import FacetFilters
@@ -230,6 +233,9 @@
230233
"Edit",
231234
"EditType",
232235
"ErrorBase",
236+
"Event",
237+
"EventStatus",
238+
"EventType",
233239
"ExactOnSingleWordQuery",
234240
"Exhaustive",
235241
"FacetFilters",

algoliasearch/search/models/event.py

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
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, Union
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+
from algoliasearch.search.models.event_status import EventStatus
22+
from algoliasearch.search.models.event_type import EventType
23+
24+
_ALIASES = {
25+
"event_id": "eventID",
26+
"run_id": "runID",
27+
"status": "status",
28+
"type": "type",
29+
"batch_size": "batchSize",
30+
"data": "data",
31+
"published_at": "publishedAt",
32+
}
33+
34+
35+
def _alias_generator(name: str) -> str:
36+
return _ALIASES.get(name, name)
37+
38+
39+
class Event(BaseModel):
40+
"""
41+
An event describe a step of the task execution flow..
42+
"""
43+
44+
event_id: str
45+
""" Universally unique identifier (UUID) of an event. """
46+
run_id: str
47+
""" Universally unique identifier (UUID) of a task run. """
48+
status: Union[EventStatus, None]
49+
type: EventType
50+
batch_size: int
51+
""" The extracted record batch size. """
52+
data: Optional[Dict[str, object]] = None
53+
published_at: str
54+
""" Date of publish RFC 3339 format. """
55+
56+
model_config = ConfigDict(
57+
strict=False,
58+
use_enum_values=True,
59+
populate_by_name=True,
60+
validate_assignment=True,
61+
protected_namespaces=(),
62+
alias_generator=_alias_generator,
63+
extra="allow",
64+
)
65+
66+
def to_json(self) -> str:
67+
return self.model_dump_json(by_alias=True, exclude_unset=True)
68+
69+
@classmethod
70+
def from_json(cls, json_str: str) -> Optional[Self]:
71+
"""Create an instance of Event from a JSON string"""
72+
return cls.from_dict(loads(json_str))
73+
74+
def to_dict(self) -> Dict[str, Any]:
75+
"""Return the dictionary representation of the model using alias."""
76+
return self.model_dump(
77+
by_alias=True,
78+
exclude_none=True,
79+
exclude_unset=True,
80+
)
81+
82+
@classmethod
83+
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
84+
"""Create an instance of Event from a dict"""
85+
if obj is None:
86+
return None
87+
88+
if not isinstance(obj, dict):
89+
return cls.model_validate(obj)
90+
91+
obj["status"] = obj.get("status")
92+
obj["type"] = obj.get("type")
93+
94+
return cls.model_validate(obj)
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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 enum import Enum
10+
from json import loads
11+
from sys import version_info
12+
13+
if version_info >= (3, 11):
14+
from typing import Self
15+
else:
16+
from typing_extensions import Self
17+
18+
19+
class EventStatus(str, Enum):
20+
"""
21+
EventStatus
22+
"""
23+
24+
"""
25+
allowed enum values
26+
"""
27+
CREATED = "created"
28+
29+
STARTED = "started"
30+
31+
RETRIED = "retried"
32+
33+
FAILED = "failed"
34+
35+
SUCCEEDED = "succeeded"
36+
37+
CRITICAL = "critical"
38+
39+
@classmethod
40+
def from_json(cls, json_str: str) -> Self:
41+
"""Create an instance of EventStatus from a JSON string"""
42+
return cls(loads(json_str))
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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 enum import Enum
10+
from json import loads
11+
from sys import version_info
12+
13+
if version_info >= (3, 11):
14+
from typing import Self
15+
else:
16+
from typing_extensions import Self
17+
18+
19+
class EventType(str, Enum):
20+
"""
21+
EventType
22+
"""
23+
24+
"""
25+
allowed enum values
26+
"""
27+
FETCH = "fetch"
28+
29+
RECORD = "record"
30+
31+
LOG = "log"
32+
33+
TRANSFORM = "transform"
34+
35+
@classmethod
36+
def from_json(cls, json_str: str) -> Self:
37+
"""Create an instance of EventType from a JSON string"""
38+
return cls(loads(json_str))
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
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, List, 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+
from algoliasearch.search.models.event import Event
22+
23+
_ALIASES = {
24+
"run_id": "runID",
25+
"event_id": "eventID",
26+
"data": "data",
27+
"events": "events",
28+
"message": "message",
29+
"created_at": "createdAt",
30+
}
31+
32+
33+
def _alias_generator(name: str) -> str:
34+
return _ALIASES.get(name, name)
35+
36+
37+
class WatchResponse(BaseModel):
38+
"""
39+
WatchResponse
40+
"""
41+
42+
run_id: str
43+
""" Universally unique identifier (UUID) of a task run. """
44+
event_id: Optional[str] = None
45+
""" Universally unique identifier (UUID) of an event. """
46+
data: Optional[List[object]] = None
47+
""" This field is always null when used with the Push endpoint. When used for a source discover or source validate run, it will include the sampled data of the source. """
48+
events: Optional[List[Event]] = None
49+
""" in case of error, observability events will be added to the response. """
50+
message: Optional[str] = None
51+
""" a message describing the outcome of the operation that has been ran (push, discover or validate) run. """
52+
created_at: Optional[str] = None
53+
""" Date of creation in RFC 3339 format. """
54+
55+
model_config = ConfigDict(
56+
strict=False,
57+
use_enum_values=True,
58+
populate_by_name=True,
59+
validate_assignment=True,
60+
protected_namespaces=(),
61+
alias_generator=_alias_generator,
62+
extra="allow",
63+
)
64+
65+
def to_json(self) -> str:
66+
return self.model_dump_json(by_alias=True, exclude_unset=True)
67+
68+
@classmethod
69+
def from_json(cls, json_str: str) -> Optional[Self]:
70+
"""Create an instance of WatchResponse from a JSON string"""
71+
return cls.from_dict(loads(json_str))
72+
73+
def to_dict(self) -> Dict[str, Any]:
74+
"""Return the dictionary representation of the model using alias."""
75+
return self.model_dump(
76+
by_alias=True,
77+
exclude_none=True,
78+
exclude_unset=True,
79+
)
80+
81+
@classmethod
82+
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
83+
"""Create an instance of WatchResponse from a dict"""
84+
if obj is None:
85+
return None
86+
87+
if not isinstance(obj, dict):
88+
return cls.model_validate(obj)
89+
90+
obj["events"] = (
91+
[Event.from_dict(_item) for _item in obj["events"]]
92+
if obj.get("events") is not None
93+
else None
94+
)
95+
96+
return cls.model_validate(obj)

0 commit comments

Comments
 (0)