Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(specs): simplify filter types #3042

Merged
merged 9 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.openapitools.codegen.CodegenConstants;
import org.openapitools.codegen.languages.PythonClientCodegen;
import org.openapitools.codegen.model.ModelMap;
import org.openapitools.codegen.model.ModelsMap;
import org.openapitools.codegen.model.OperationsMap;

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

return operations;
}

@Override
public ModelsMap postProcessModels(ModelsMap objs) {
// this is to prevent F811 from flake8 because we have some recusrive models
String modelName = objs.getModels().get(0).getModel().getClassname();
for (Map<String, String> imp : objs.getImports()) {
if (imp.get("import").endsWith("import " + modelName)) {
imp.remove("import");
}
}
return objs;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ private void handleModel(

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

HashMap<String, Object> oneOfModel = new HashMap<>();
Map<String, Object> oneOfModel = new HashMap<>();
IJsonSchemaValidationProperties current = match;
String typeName = getTypeName(current);
boolean isList = false;
Expand Down
9 changes: 6 additions & 3 deletions specs/common/schemas/IndexSettings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,9 @@ indexSettingsAsSearchParams:
x-categories:
- Filtering
reRankingApplyFilter:
$ref: '#/reRankingApplyFilter'
oneOf:
- $ref: '#/reRankingApplyFilter'
- type: 'null'

maxFacetHits:
type: integer
Expand All @@ -759,11 +761,12 @@ reRankingApplyFilter:
description: |
Restrict [Dynamic Re-Ranking](https://www.algolia.com/doc/guides/algolia-ai/re-ranking/) to records that match these filters.
oneOf:
- $ref: './SearchParams.yml#/listOfSearchFilters'
- type: array
items:
$ref: '#/reRankingApplyFilter'
- type: string
x-categories:
- Filtering
- type: 'null'

hitsPerPage:
type: integer
Expand Down
35 changes: 12 additions & 23 deletions specs/common/schemas/SearchParams.yml
Original file line number Diff line number Diff line change
Expand Up @@ -378,25 +378,6 @@ insidePolygon:
x-categories:
- Geo-Search

# There is duplicated logic here because we want to keep a correct description
# and using `$ref` override everything.
searchFiltersArrayString:
title: search filter array
type: array
items:
type: string

mixedSearchFilters:
oneOf:
- $ref: '#/searchFiltersArrayString'
- type: string

listOfSearchFilters:
type: array
title: search filters
items:
$ref: '#/mixedSearchFilters'

filters:
type: string
description: |
Expand Down Expand Up @@ -441,7 +422,9 @@ facetFilters:
`facet:\-value`.
example: [['category:Book', 'category:-Movie'], 'author:John Doe']
oneOf:
- $ref: '#/listOfSearchFilters'
- type: array
items:
$ref: '#/facetFilters'
- type: string
x-categories:
- Filtering
Expand All @@ -457,7 +440,9 @@ tagFilters:
The same combination and escaping rules apply as for `facetFilters`.
example: [['Book', 'Movie'], 'SciFi']
oneOf:
- $ref: '#/listOfSearchFilters'
- type: array
items:
$ref: '#/tagFilters'
- type: string
x-categories:
- Filtering
Expand All @@ -473,7 +458,9 @@ numericFilters:
The same combination rules apply as for `facetFilters`.
example: [['inStock = 1', 'deliveryDate < 1441755506'], 'price < 1000']
oneOf:
- $ref: '#/listOfSearchFilters'
- type: array
items:
$ref: '#/numericFilters'
- type: string
x-categories:
- Filtering
Expand All @@ -492,7 +479,9 @@ optionalFilters:

example: ['category:Book', 'author:John Doe']
oneOf:
- $ref: '#/listOfSearchFilters'
- type: array
items:
$ref: '#/optionalFilters'
- type: string
x-categories:
- Filtering
3 changes: 2 additions & 1 deletion templates/go/tests/requests/requests.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os"
"testing"
"time"
"strings"

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

jaE2E := jsonassert.New(t)
jaE2E.Assertf(expectedBodyRaw, string(unionBodyRaw))
jaE2E.Assertf(expectedBodyRaw, strings.ReplaceAll(string(unionBodyRaw), "%", "%%"))
{{/body}}
{{/response}}
})
Expand Down
3 changes: 2 additions & 1 deletion templates/python/tests/requests/requests.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class Test{{#lambda.pascalcase}}{{{client}}}{{/lambda.pascalcase}}{{#isE2E}}E2E{
assert raw_resp.status_code == {{statusCode}}
{{/statusCode}}


{{#body}}
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}})
_expected_body = loads("""{{{.}}}""")
Expand All @@ -74,4 +75,4 @@ class Test{{#lambda.pascalcase}}{{{client}}}{{/lambda.pascalcase}}{{#isE2E}}E2E{

{{#isSearchClient}}
{{> tests/requests/helpers}}
{{/isSearchClient}}
{{/isSearchClient}}
6 changes: 2 additions & 4 deletions templates/ruby/base_object.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@
end
{{#getAdditionalPropertiesIsAnyType}}

# merge additional_properties into transformed_hash
@additional_properties.each_pair do |k, v|
transformed_hash[k.to_sym] = v
end unless @additional_properties.nil?
# add extra attribute to transformed_hash
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

huge fix

transformed_hash.merge!(attributes.reject { |k, _| attribute_map.key?(k.to_sym) })
{{/getAdditionalPropertiesIsAnyType}}
new(transformed_hash)
end
Expand Down
160 changes: 158 additions & 2 deletions tests/CTS/requests/search/search.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@
"highlighted": "neovim",
"value": "neovim"
},
{
"count": 1,
"highlighted": "visual studio",
"value": "visual studio"
},
{
"count": 1,
"highlighted": "vscode",
Expand Down Expand Up @@ -261,7 +266,10 @@
"facetFilters": [
"mySearch:filters",
[
"mySearch:filters"
"mySearch:filters",
[
"mySearch:filters"
]
]
],
"reRankingApplyFilter": [
Expand Down Expand Up @@ -309,7 +317,10 @@
"facetFilters": [
"mySearch:filters",
[
"mySearch:filters"
"mySearch:filters",
[
"mySearch:filters"
]
]
],
"reRankingApplyFilter": [
Expand Down Expand Up @@ -341,6 +352,151 @@
}
}
},
{
"testName": "search filters end to end",
"parameters": {
"requests": [
{
"indexName": "cts_e2e_search_facet",
"filters": "editor:'visual studio' OR editor:neovim"
},
{
"indexName": "cts_e2e_search_facet",
"facetFilters": [
"editor:'visual studio'",
"editor:neovim"
]
},
{
"indexName": "cts_e2e_search_facet",
"facetFilters": [
"editor:'visual studio'",
[
"editor:neovim"
]
]
},
{
"indexName": "cts_e2e_search_facet",
"facetFilters": [
"editor:'visual studio'",
[
"editor:neovim",
[
"editor:goland"
]
]
]
}
]
},
"request": {
"path": "/1/indexes/*/queries",
"method": "POST",
"body": {
"requests": [
{
"indexName": "cts_e2e_search_facet",
"filters": "editor:'visual studio' OR editor:neovim"
},
{
"indexName": "cts_e2e_search_facet",
"facetFilters": [
"editor:'visual studio'",
"editor:neovim"
]
},
{
"indexName": "cts_e2e_search_facet",
"facetFilters": [
"editor:'visual studio'",
[
"editor:neovim"
]
]
},
{
"indexName": "cts_e2e_search_facet",
"facetFilters": [
"editor:'visual studio'",
[
"editor:neovim",
[
"editor:goland"
]
]
]
}
]
}
},
"response": {
"statusCode": 200,
"body": {
"results": [
{
"hitsPerPage": 20,
"index": "cts_e2e_search_facet",
"nbHits": 2,
"nbPages": 1,
"page": 0,
"hits": [
{
"editor": "visual studio",
"_highlightResult": {
"editor": {
"value": "visual studio",
"matchLevel": "none"
}
}
},
{
"editor": "neovim",
"_highlightResult": {
"editor": {
"value": "neovim",
"matchLevel": "none"
}
}
}
],
"query": "",
"params": "filters=editor%3A%27visual+studio%27+OR+editor%3Aneovim"
},
{
"hitsPerPage": 20,
"index": "cts_e2e_search_facet",
"nbHits": 0,
"nbPages": 0,
"page": 0,
"hits": [],
"query": "",
"params": "facetFilters=%5B%22editor%3A%27visual+studio%27%22%2C%22editor%3Aneovim%22%5D"
},
{
"hitsPerPage": 20,
"index": "cts_e2e_search_facet",
"nbHits": 0,
"nbPages": 0,
"page": 0,
"hits": [],
"query": "",
"params": "facetFilters=%5B%22editor%3A%27visual+studio%27%22%2C%5B%22editor%3Aneovim%22%5D%5D"
},
{
"hitsPerPage": 20,
"index": "cts_e2e_search_facet",
"nbHits": 0,
"nbPages": 0,
"page": 0,
"hits": [],
"query": "",
"params": "facetFilters=%5B%22editor%3A%27visual+studio%27%22%2C%5B%22editor%3Aneovim%22%2C%5B%22editor%3Agoland%22%5D%5D%5D"
}
]
}
}
},
{
"testName": "search with all search parameters",
"parameters": {
Expand Down
Loading