Skip to content

Commit 1fb46ef

Browse files
authored
Merge b2db954 into 1033d8f
2 parents 1033d8f + b2db954 commit 1fb46ef

File tree

13 files changed

+281
-164
lines changed

13 files changed

+281
-164
lines changed

generators/src/main/java/com/algolia/codegen/AlgoliaPythonGenerator.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,25 @@ public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List<Mo
145145
return operations;
146146
}
147147

148+
@Override
149+
public Map<String, ModelsMap> postProcessAllModels(Map<String, ModelsMap> objs) {
150+
Map<String, ModelsMap> models = super.postProcessAllModels(objs);
151+
OneOf.updateModelsOneOf(models, modelPackage);
152+
GenericPropagator.propagateGenericsToModels(models, true);
153+
OneOf.addOneOfMetadata(models);
154+
jsonParent(models);
155+
return models;
156+
}
157+
158+
private static void jsonParent(Map<String, ModelsMap> models) {
159+
for (ModelsMap modelContainer : models.values()) {
160+
CodegenModel model = modelContainer.getModels().get(0).getModel();
161+
if (model.parent != null && model.parent.startsWith("AbstractMap")) {
162+
model.vendorExtensions.put("x-map-parent", true);
163+
}
164+
}
165+
}
166+
148167
@Override
149168
public ModelsMap postProcessModels(ModelsMap objs) {
150169
// this is to prevent F811 from flake8 because we have some recusrive models

playground/python/app/search.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@ async def main():
1717
print("client initialized", client)
1818

1919
try:
20-
await client.browse_objects(
21-
index_name="api-clients-automation",
22-
aggregator=lambda _resp: print("baaaaaaaaaaaaaaar", _resp.to_json()),
23-
)
20+
resp = await client.search(search_method_params={
21+
"requests": [{"indexName": "api-clients-automation"}]
22+
})
23+
print(resp.to_json())
24+
print(resp.to_dict())
2425
finally:
2526
await client.close()
2627

playground/python/poetry.lock

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

playground/python/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ homepage = "https://www.algolia.com"
99
repository = "https://github.com/algolia/api-clients-automation"
1010

1111
[tool.poetry.dependencies]
12-
python = "^3.8.1"
12+
python = ">= 3.8.1"
1313
algoliasearch = { path = "../../clients/algoliasearch-client-python", develop = true }
1414
ruff = "== 0.6.4"
1515
python-dotenv = "== 1.0.1"

scripts/formatter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export async function formatter(language: string, cwd: string): Promise<void> {
5151
break;
5252
case 'python':
5353
await run(
54-
'poetry lock --no-update && poetry install --sync && pip freeze > requirements.txt && poetry run ruff check --fix && poetry run ruff format',
54+
'poetry lock --no-update && poetry install --sync && pip freeze > requirements.txt && poetry run ruff check --fix --unsafe-fixes && poetry run ruff format',
5555
{ cwd, language },
5656
);
5757
break;

specs/common/schemas/HighlightResult.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,13 @@ highlightResultOptionArray:
4747
items:
4848
$ref: '#/highlightResultOption'
4949

50+
# TODO: create a rule that sorts oneOf per number of discriminator in case they share the same primitive type
5051
highlightResult:
5152
oneOf:
52-
- $ref: '#/highlightResultMap'
5353
- $ref: '#/highlightResultOption'
5454
- $ref: '#/highlightResultOptionMap'
5555
- $ref: '#/highlightResultOptionArray'
56+
- $ref: '#/highlightResultMap'
5657

5758
highlightResultMap:
5859
type: object

specs/ingestion/common/schemas/destination.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ DestinationType:
118118
Data is recorded as user events in the Insights API.
119119
enum: [search, insights]
120120

121-
DestinationIndexName:
121+
DestinationInput:
122122
type: object
123123
additionalProperties: false
124124
properties:
@@ -151,7 +151,3 @@ AttributesToExclude:
151151
Use `*` as wildcard: `foo.[*].bar` excludes `bar` from all elements of the `foo` array.
152152
items:
153153
type: string
154-
155-
DestinationInput:
156-
oneOf:
157-
- $ref: '#/DestinationIndexName'

specs/search/common/schemas/SearchForFacetValuesResponse.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ searchForFacetValuesResponse:
66
- exhaustiveFacetsCount
77
x-discriminator-fields:
88
- facetHits
9+
- exhaustiveFacetsCount
910
properties:
1011
facetHits:
1112
type: array

templates/python/imports.mustache

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ from __future__ import annotations
33
import base64
44
import hashlib
55
import hmac
6+
import json
7+
import pprint
8+
import re
69
from sys import version_info
710
from warnings import warn
811
from random import randint
@@ -17,11 +20,13 @@ from json import (
1720
from pydantic import (
1821
BaseModel,
1922
ConfigDict,
23+
Discriminator,
2024
Field,
2125
StrictBool,
2226
StrictFloat,
2327
StrictInt,
2428
StrictStr,
29+
Tag,
2530
ValidationError,
2631
field_validator,
2732
model_serializer,
@@ -33,16 +38,18 @@ from typing import (
3338
Dict,
3439
Iterator,
3540
List,
36-
Literal,
3741
Optional,
42+
Set,
3843
Tuple,
3944
Union,
4045
)
4146

47+
from typing_extensions import Annotated
48+
4249
if version_info >= (3, 11):
43-
from typing import Self, Annotated
50+
from typing import Literal, Self
4451
else:
45-
from typing_extensions import Self, Annotated
52+
from typing_extensions import Literal, Self
4653

4754
from algoliasearch.http.helpers import create_iterable, create_iterable_sync, RetryTimeout
4855
from algoliasearch.http.serializer import bodySerializer, QueryParametersSerializer

templates/python/model.mustache

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
{{> model_enum}}
1212
{{/isEnum}}
1313
{{^isEnum}}
14-
{{#oneOf}}{{#-first}}{{> model_oneof}}{{/-first}}{{/oneOf}}{{^oneOf}}{{#anyOf}}{{#-first}}{{> model_anyof}}{{/-first}}{{/anyOf}}{{^anyOf}}{{> model_generic}}{{/anyOf}}{{/oneOf}}
14+
{{#oneOf}}{{#-first}}{{> model_oneof}}{{/-first}}{{/oneOf}}{{^oneOf}}{{> model_generic}}{{/oneOf}}
1515
{{/isEnum}}
1616
{{/model}}
17-
{{/models}}
17+
{{/models}}

templates/python/model_enum.mustache

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,13 @@
11
class {{classname}}({{vendorExtensions.x-py-enum-type}}, Enum):
2-
{{> model_description}}
2+
{{>model_description}}
33

4-
"""
5-
allowed enum values
6-
"""
74
{{#allowableValues}}
85
{{#enumVars}}
96
{{{name}}} = {{{value}}}
107
{{/enumVars}}
118

129
@classmethod
13-
def from_json(cls, json_str: str) -> Self:
14-
"""Create an instance of {{classname}} from a JSON string"""
15-
return cls(loads(json_str))
16-
17-
{{#defaultValue}}
18-
19-
#
20-
@classmethod
21-
def _missing_value_(cls, value):
22-
if value is no_arg:
23-
return cls.{{{.}}}
24-
{{/defaultValue}}
25-
{{/allowableValues}}
10+
def from_json(cls, raw_str: str) -> Self:
11+
"""Create an instance of {{classname}} from a string"""
12+
return cls(raw_str)
13+
{{/allowableValues}}

0 commit comments

Comments
 (0)