Skip to content

Commit c596a0b

Browse files
feat(specs): update transformation specs for no-code (generated)
algolia/api-clients-automation#4901 Co-authored-by: algolia-bot <[email protected]> Co-authored-by: Mehmet Ali Gok <[email protected]>
1 parent ddaddb0 commit c596a0b

File tree

7 files changed

+324
-4
lines changed

7 files changed

+324
-4
lines changed

algoliasearch/ingestion/models/transformation.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,15 @@
1818
from typing_extensions import Self
1919

2020

21+
from algoliasearch.ingestion.models.transformation_input import TransformationInput
22+
from algoliasearch.ingestion.models.transformation_type import TransformationType
23+
2124
_ALIASES = {
2225
"transformation_id": "transformationID",
2326
"authentication_ids": "authenticationIDs",
2427
"code": "code",
28+
"type": "type",
29+
"input": "input",
2530
"name": "name",
2631
"description": "description",
2732
"owner": "owner",
@@ -44,7 +49,9 @@ class Transformation(BaseModel):
4449
authentication_ids: Optional[List[str]] = None
4550
""" The authentications associated with the current transformation. """
4651
code: str
47-
""" The source code of the transformation. """
52+
""" It is deprecated. Use the `input` field with proper `type` instead to specify the transformation code. """
53+
type: Optional[TransformationType] = None
54+
input: Optional[TransformationInput] = None
4855
name: str
4956
""" The uniquely identified name of your transformation. """
5057
description: Optional[str] = None
@@ -91,4 +98,11 @@ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
9198
if not isinstance(obj, dict):
9299
return cls.model_validate(obj)
93100

101+
obj["type"] = obj.get("type")
102+
obj["input"] = (
103+
TransformationInput.from_dict(obj["input"])
104+
if obj.get("input") is not None
105+
else None
106+
)
107+
94108
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+
"code": "code",
23+
}
24+
25+
26+
def _alias_generator(name: str) -> str:
27+
return _ALIASES.get(name, name)
28+
29+
30+
class TransformationCode(BaseModel):
31+
"""
32+
Input for a transformation that contains the source code of the transformation.
33+
"""
34+
35+
code: str
36+
""" The source code of the transformation. """
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 TransformationCode 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 TransformationCode 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)

algoliasearch/ingestion/models/transformation_create.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,14 @@
1818
from typing_extensions import Self
1919

2020

21+
from algoliasearch.ingestion.models.transformation_input import TransformationInput
22+
from algoliasearch.ingestion.models.transformation_type import TransformationType
23+
2124
_ALIASES = {
2225
"code": "code",
2326
"name": "name",
27+
"type": "type",
28+
"input": "input",
2429
"description": "description",
2530
"authentication_ids": "authenticationIDs",
2631
}
@@ -35,10 +40,12 @@ class TransformationCreate(BaseModel):
3540
API request body for creating a transformation.
3641
"""
3742

38-
code: str
39-
""" The source code of the transformation. """
43+
code: Optional[str] = None
44+
""" It is deprecated. Use the `input` field with proper `type` instead to specify the transformation code. """
4045
name: str
4146
""" The uniquely identified name of your transformation. """
47+
type: TransformationType
48+
input: TransformationInput
4249
description: Optional[str] = None
4350
""" A descriptive name for your transformation of what it does. """
4451
authentication_ids: Optional[List[str]] = None
@@ -79,4 +86,11 @@ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
7986
if not isinstance(obj, dict):
8087
return cls.model_validate(obj)
8188

89+
obj["type"] = obj.get("type")
90+
obj["input"] = (
91+
TransformationInput.from_dict(obj["input"])
92+
if obj.get("input") is not None
93+
else None
94+
)
95+
8296
return cls.model_validate(obj)
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
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
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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+
_ALIASES = {
22+
"steps": "steps",
23+
}
24+
25+
26+
def _alias_generator(name: str) -> str:
27+
return _ALIASES.get(name, name)
28+
29+
30+
class TransformationNoCode(BaseModel):
31+
"""
32+
Input for a no-code transformation that contains a series of steps.
33+
"""
34+
35+
steps: List[object]
36+
37+
model_config = ConfigDict(
38+
strict=False,
39+
use_enum_values=True,
40+
populate_by_name=True,
41+
validate_assignment=True,
42+
protected_namespaces=(),
43+
alias_generator=_alias_generator,
44+
extra="allow",
45+
)
46+
47+
def to_json(self) -> str:
48+
return self.model_dump_json(by_alias=True, exclude_unset=True)
49+
50+
@classmethod
51+
def from_json(cls, json_str: str) -> Optional[Self]:
52+
"""Create an instance of TransformationNoCode from a JSON string"""
53+
return cls.from_dict(loads(json_str))
54+
55+
def to_dict(self) -> Dict[str, Any]:
56+
"""Return the dictionary representation of the model using alias."""
57+
return self.model_dump(
58+
by_alias=True,
59+
exclude_none=True,
60+
exclude_unset=True,
61+
)
62+
63+
@classmethod
64+
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
65+
"""Create an instance of TransformationNoCode from a dict"""
66+
if obj is None:
67+
return None
68+
69+
if not isinstance(obj, dict):
70+
return cls.model_validate(obj)
71+
72+
return cls.model_validate(obj)

algoliasearch/ingestion/models/transformation_try.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class TransformationTry(BaseModel):
3737
"""
3838

3939
code: str
40-
""" The source code of the transformation. """
40+
""" It is deprecated. Use the `input` field with proper `type` instead to specify the transformation code. """
4141
sample_record: object
4242
""" The record to apply the given code to. """
4343
authentications: Optional[List[AuthenticationCreate]] = None
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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 TransformationType(str, Enum):
20+
"""
21+
The type of transformation, which can be either 'code' or 'noCode'.
22+
"""
23+
24+
"""
25+
allowed enum values
26+
"""
27+
CODE = "code"
28+
29+
NOCODE = "noCode"
30+
31+
@classmethod
32+
def from_json(cls, json_str: str) -> Self:
33+
"""Create an instance of TransformationType from a JSON string"""
34+
return cls(loads(json_str))

0 commit comments

Comments
 (0)