Skip to content

Commit 1250c2b

Browse files
authored
fix(specs): simplify filter types (#3042)
1 parent 63fea4b commit 1250c2b

File tree

8 files changed

+196
-35
lines changed

8 files changed

+196
-35
lines changed

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import org.openapitools.codegen.CodegenConstants;
1111
import org.openapitools.codegen.languages.PythonClientCodegen;
1212
import org.openapitools.codegen.model.ModelMap;
13+
import org.openapitools.codegen.model.ModelsMap;
1314
import org.openapitools.codegen.model.OperationsMap;
1415

1516
public class AlgoliaPythonGenerator extends PythonClientCodegen {
@@ -129,4 +130,16 @@ public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List<Mo
129130

130131
return operations;
131132
}
133+
134+
@Override
135+
public ModelsMap postProcessModels(ModelsMap objs) {
136+
// this is to prevent F811 from flake8 because we have some recusrive models
137+
String modelName = objs.getModels().get(0).getModel().getClassname();
138+
for (Map<String, String> imp : objs.getImports()) {
139+
if (imp.get("import").endsWith("import " + modelName)) {
140+
imp.remove("import");
141+
}
142+
}
143+
return objs;
144+
}
132145
}

generators/src/main/java/com/algolia/codegen/cts/tests/ParametersWithDataType.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ private void handleModel(
306306

307307
testOutput.putAll(traverseParams(paramName, param, match, parent, suffix, isParentFreeFormObject));
308308

309-
HashMap<String, Object> oneOfModel = new HashMap<>();
309+
Map<String, Object> oneOfModel = new HashMap<>();
310310
IJsonSchemaValidationProperties current = match;
311311
String typeName = getTypeName(current);
312312
boolean isList = false;

specs/common/schemas/IndexSettings.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,9 @@ indexSettingsAsSearchParams:
745745
x-categories:
746746
- Filtering
747747
reRankingApplyFilter:
748-
$ref: '#/reRankingApplyFilter'
748+
oneOf:
749+
- $ref: '#/reRankingApplyFilter'
750+
- type: 'null'
749751

750752
maxFacetHits:
751753
type: integer
@@ -759,11 +761,12 @@ reRankingApplyFilter:
759761
description: |
760762
Restrict [Dynamic Re-Ranking](https://www.algolia.com/doc/guides/algolia-ai/re-ranking/) to records that match these filters.
761763
oneOf:
762-
- $ref: './SearchParams.yml#/listOfSearchFilters'
764+
- type: array
765+
items:
766+
$ref: '#/reRankingApplyFilter'
763767
- type: string
764768
x-categories:
765769
- Filtering
766-
- type: 'null'
767770

768771
hitsPerPage:
769772
type: integer

specs/common/schemas/SearchParams.yml

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -378,25 +378,6 @@ insidePolygon:
378378
x-categories:
379379
- Geo-Search
380380

381-
# There is duplicated logic here because we want to keep a correct description
382-
# and using `$ref` override everything.
383-
searchFiltersArrayString:
384-
title: search filter array
385-
type: array
386-
items:
387-
type: string
388-
389-
mixedSearchFilters:
390-
oneOf:
391-
- $ref: '#/searchFiltersArrayString'
392-
- type: string
393-
394-
listOfSearchFilters:
395-
type: array
396-
title: search filters
397-
items:
398-
$ref: '#/mixedSearchFilters'
399-
400381
filters:
401382
type: string
402383
description: |
@@ -441,7 +422,9 @@ facetFilters:
441422
`facet:\-value`.
442423
example: [['category:Book', 'category:-Movie'], 'author:John Doe']
443424
oneOf:
444-
- $ref: '#/listOfSearchFilters'
425+
- type: array
426+
items:
427+
$ref: '#/facetFilters'
445428
- type: string
446429
x-categories:
447430
- Filtering
@@ -457,7 +440,9 @@ tagFilters:
457440
The same combination and escaping rules apply as for `facetFilters`.
458441
example: [['Book', 'Movie'], 'SciFi']
459442
oneOf:
460-
- $ref: '#/listOfSearchFilters'
443+
- type: array
444+
items:
445+
$ref: '#/tagFilters'
461446
- type: string
462447
x-categories:
463448
- Filtering
@@ -473,7 +458,9 @@ numericFilters:
473458
The same combination rules apply as for `facetFilters`.
474459
example: [['inStock = 1', 'deliveryDate < 1441755506'], 'price < 1000']
475460
oneOf:
476-
- $ref: '#/listOfSearchFilters'
461+
- type: array
462+
items:
463+
$ref: '#/numericFilters'
477464
- type: string
478465
x-categories:
479466
- Filtering
@@ -492,7 +479,9 @@ optionalFilters:
492479
493480
example: ['category:Book', 'author:John Doe']
494481
oneOf:
495-
- $ref: '#/listOfSearchFilters'
482+
- type: array
483+
items:
484+
$ref: '#/optionalFilters'
496485
- type: string
497486
x-categories:
498487
- Filtering

templates/go/tests/requests/requests.mustache

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"os"
88
"testing"
99
"time"
10+
"strings"
1011

1112
"github.com/kinbiko/jsonassert"
1213
"github.com/stretchr/testify/require"
@@ -129,7 +130,7 @@ func Test{{#lambda.titlecase}}{{clientPrefix}}{{/lambda.titlecase}}_{{#lambda.ti
129130
require.NoError(t, err)
130131

131132
jaE2E := jsonassert.New(t)
132-
jaE2E.Assertf(expectedBodyRaw, string(unionBodyRaw))
133+
jaE2E.Assertf(expectedBodyRaw, strings.ReplaceAll(string(unionBodyRaw), "%", "%%"))
133134
{{/body}}
134135
{{/response}}
135136
})

templates/python/tests/requests/requests.mustache

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ class Test{{#lambda.pascalcase}}{{{client}}}{{/lambda.pascalcase}}{{#isE2E}}E2E{
6262
assert raw_resp.status_code == {{statusCode}}
6363
{{/statusCode}}
6464

65+
6566
{{#body}}
6667
resp = await {{#lambda.pascalcase}}{{{client}}}{{/lambda.pascalcase}}(self._e2e_app_id, self._e2e_api_key{{#hasRegionalHost}}, "{{{defaultRegion}}}"{{/hasRegionalHost}}).{{#lambda.snakecase}}{{method}}{{/lambda.snakecase}}({{#parametersWithDataType}}{{> tests/requests/generateParams}}{{/parametersWithDataType}}{{#hasRequestOptions}} request_options={ {{#requestOptions.headers.parameters}}"headers":loads("""{{{.}}}"""),{{/requestOptions.headers.parameters}}{{#requestOptions.queryParameters.parameters}}"query_parameters":loads("""{{{.}}}"""),{{/requestOptions.queryParameters.parameters}} }{{/hasRequestOptions}})
6768
_expected_body = loads("""{{{.}}}""")
@@ -74,4 +75,4 @@ class Test{{#lambda.pascalcase}}{{{client}}}{{/lambda.pascalcase}}{{#isE2E}}E2E{
7475

7576
{{#isSearchClient}}
7677
{{> tests/requests/helpers}}
77-
{{/isSearchClient}}
78+
{{/isSearchClient}}

templates/ruby/base_object.mustache

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,8 @@
2323
end
2424
{{#getAdditionalPropertiesIsAnyType}}
2525

26-
# merge additional_properties into transformed_hash
27-
@additional_properties.each_pair do |k, v|
28-
transformed_hash[k.to_sym] = v
29-
end unless @additional_properties.nil?
26+
# add extra attribute to transformed_hash
27+
transformed_hash.merge!(attributes.reject { |k, _| attribute_map.key?(k.to_sym) })
3028
{{/getAdditionalPropertiesIsAnyType}}
3129
new(transformed_hash)
3230
end

tests/CTS/requests/search/search.json

Lines changed: 158 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@
8787
"highlighted": "neovim",
8888
"value": "neovim"
8989
},
90+
{
91+
"count": 1,
92+
"highlighted": "visual studio",
93+
"value": "visual studio"
94+
},
9095
{
9196
"count": 1,
9297
"highlighted": "vscode",
@@ -261,7 +266,10 @@
261266
"facetFilters": [
262267
"mySearch:filters",
263268
[
264-
"mySearch:filters"
269+
"mySearch:filters",
270+
[
271+
"mySearch:filters"
272+
]
265273
]
266274
],
267275
"reRankingApplyFilter": [
@@ -309,7 +317,10 @@
309317
"facetFilters": [
310318
"mySearch:filters",
311319
[
312-
"mySearch:filters"
320+
"mySearch:filters",
321+
[
322+
"mySearch:filters"
323+
]
313324
]
314325
],
315326
"reRankingApplyFilter": [
@@ -341,6 +352,151 @@
341352
}
342353
}
343354
},
355+
{
356+
"testName": "search filters end to end",
357+
"parameters": {
358+
"requests": [
359+
{
360+
"indexName": "cts_e2e_search_facet",
361+
"filters": "editor:'visual studio' OR editor:neovim"
362+
},
363+
{
364+
"indexName": "cts_e2e_search_facet",
365+
"facetFilters": [
366+
"editor:'visual studio'",
367+
"editor:neovim"
368+
]
369+
},
370+
{
371+
"indexName": "cts_e2e_search_facet",
372+
"facetFilters": [
373+
"editor:'visual studio'",
374+
[
375+
"editor:neovim"
376+
]
377+
]
378+
},
379+
{
380+
"indexName": "cts_e2e_search_facet",
381+
"facetFilters": [
382+
"editor:'visual studio'",
383+
[
384+
"editor:neovim",
385+
[
386+
"editor:goland"
387+
]
388+
]
389+
]
390+
}
391+
]
392+
},
393+
"request": {
394+
"path": "/1/indexes/*/queries",
395+
"method": "POST",
396+
"body": {
397+
"requests": [
398+
{
399+
"indexName": "cts_e2e_search_facet",
400+
"filters": "editor:'visual studio' OR editor:neovim"
401+
},
402+
{
403+
"indexName": "cts_e2e_search_facet",
404+
"facetFilters": [
405+
"editor:'visual studio'",
406+
"editor:neovim"
407+
]
408+
},
409+
{
410+
"indexName": "cts_e2e_search_facet",
411+
"facetFilters": [
412+
"editor:'visual studio'",
413+
[
414+
"editor:neovim"
415+
]
416+
]
417+
},
418+
{
419+
"indexName": "cts_e2e_search_facet",
420+
"facetFilters": [
421+
"editor:'visual studio'",
422+
[
423+
"editor:neovim",
424+
[
425+
"editor:goland"
426+
]
427+
]
428+
]
429+
}
430+
]
431+
}
432+
},
433+
"response": {
434+
"statusCode": 200,
435+
"body": {
436+
"results": [
437+
{
438+
"hitsPerPage": 20,
439+
"index": "cts_e2e_search_facet",
440+
"nbHits": 2,
441+
"nbPages": 1,
442+
"page": 0,
443+
"hits": [
444+
{
445+
"editor": "visual studio",
446+
"_highlightResult": {
447+
"editor": {
448+
"value": "visual studio",
449+
"matchLevel": "none"
450+
}
451+
}
452+
},
453+
{
454+
"editor": "neovim",
455+
"_highlightResult": {
456+
"editor": {
457+
"value": "neovim",
458+
"matchLevel": "none"
459+
}
460+
}
461+
}
462+
],
463+
"query": "",
464+
"params": "filters=editor%3A%27visual+studio%27+OR+editor%3Aneovim"
465+
},
466+
{
467+
"hitsPerPage": 20,
468+
"index": "cts_e2e_search_facet",
469+
"nbHits": 0,
470+
"nbPages": 0,
471+
"page": 0,
472+
"hits": [],
473+
"query": "",
474+
"params": "facetFilters=%5B%22editor%3A%27visual+studio%27%22%2C%22editor%3Aneovim%22%5D"
475+
},
476+
{
477+
"hitsPerPage": 20,
478+
"index": "cts_e2e_search_facet",
479+
"nbHits": 0,
480+
"nbPages": 0,
481+
"page": 0,
482+
"hits": [],
483+
"query": "",
484+
"params": "facetFilters=%5B%22editor%3A%27visual+studio%27%22%2C%5B%22editor%3Aneovim%22%5D%5D"
485+
},
486+
{
487+
"hitsPerPage": 20,
488+
"index": "cts_e2e_search_facet",
489+
"nbHits": 0,
490+
"nbPages": 0,
491+
"page": 0,
492+
"hits": [],
493+
"query": "",
494+
"params": "facetFilters=%5B%22editor%3A%27visual+studio%27%22%2C%5B%22editor%3Aneovim%22%2C%5B%22editor%3Agoland%22%5D%5D%5D"
495+
}
496+
]
497+
}
498+
}
499+
},
344500
{
345501
"testName": "search with all search parameters",
346502
"parameters": {

0 commit comments

Comments
 (0)