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(spec): better filters type #413

Merged
merged 18 commits into from
Apr 26, 2022
Merged
Show file tree
Hide file tree
Changes from 4 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
2 changes: 1 addition & 1 deletion .github/.cache_version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8.0.5.2
76264f26-7ad7-4fae-9bda-5e96b9cd04eb
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public Map<String, Object> postProcessAllModels(Map<String, Object> objs) {
.get(0)
.get("model");
if (!model.oneOf.isEmpty()) {
List<HashMap<String, String>> listOneOf = new ArrayList();
List<HashMap<String, String>> oneOfList = new ArrayList();

for (String iterateModel : model.oneOf) {
HashMap<String, String> oneOfModel = new HashMap();
Expand All @@ -163,11 +163,11 @@ public Map<String, Object> postProcessAllModels(Map<String, Object> objs) {
iterateModel.replace("<", "").replace(">", "")
);

listOneOf.add(oneOfModel);
oneOfList.add(oneOfModel);
}

model.vendorExtensions.put("x-is-one-of-interface", true);
model.vendorExtensions.put("x-is-one-of-list", listOneOf);
model.vendorExtensions.put("x-is-one-of-list", oneOfList);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import io.swagger.util.Json;
import java.util.*;
import java.util.Map.Entry;
import org.openapitools.codegen.CodegenComposedSchemas;
import org.openapitools.codegen.CodegenModel;
import org.openapitools.codegen.CodegenOperation;
import org.openapitools.codegen.CodegenParameter;
Expand Down Expand Up @@ -205,7 +206,24 @@ private void handleModel(
int suffix
) throws CTSException {
if (!spec.getHasVars()) {
throw new CTSException("Spec has no vars.");
// In this case we might have a complex `allOf`, we will first check
// if it exists
CodegenComposedSchemas composedSchemas = spec.getComposedSchemas();

if (composedSchemas != null) {
List<CodegenProperty> allOf = composedSchemas.getAllOf();

if (allOf != null && !allOf.isEmpty()) {
traverseParams(paramName, param, allOf.get(0), parent, suffix);

return;
}
}
// We only throw if there is no `composedSchemas`, because `oneOf` can also
// be handled below
else {
throw new CTSException("Spec has no vars.");
}
}

if (spec.getItems() != null) {
Expand All @@ -224,12 +242,22 @@ private void handleModel(
);

HashMap<String, String> oneOfModel = new HashMap<>();
String typeName = getTypeName(match).replace("<", "").replace(">", "");

oneOfModel.put("classname", Utils.capitalize(baseType));
oneOfModel.put(
"name",
getTypeName(match).replace("<", "").replace(">", "")
);

if (typeName.equals("List")) {
Json.prettyPrint(match);
shortcuts marked this conversation as resolved.
Show resolved Hide resolved
CodegenProperty items = match.getItems();

if (items == null) {
throw new CTSException("Unhandled case for empty oneOf List items.");
}

typeName += getTypeName(items);
}

oneOfModel.put("name", typeName);
testOutput.put("oneOfModel", oneOfModel);

return;
Expand Down Expand Up @@ -466,7 +494,18 @@ private IJsonSchemaValidationProperties findMatchingOneOf(
return bestOneOf;
}
if (param instanceof List) {
// no idea for list
// NICE ---> no idea for list <--- NICE
Copy link
Collaborator

Choose a reason for hiding this comment

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

sorry for this, I'll right better error exception next time

Copy link
Member Author

Choose a reason for hiding this comment

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

Nah actually I like this way of thinking!!

CodegenComposedSchemas composedSchemas = model.getComposedSchemas();

if (composedSchemas != null) {
List<CodegenProperty> oneOf = composedSchemas.getOneOf();

// Somehow this is not yet enough
if (oneOf != null && !oneOf.isEmpty()) {
return oneOf.get(0);
}
Comment on lines +502 to +505
Copy link
Member Author

Choose a reason for hiding this comment

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

This takes the first item of the list, it's not correct but allow the CI to work for now

}

return null;
}

Expand Down
71 changes: 50 additions & 21 deletions specs/common/schemas/SearchParams.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,31 +30,14 @@ baseSearchParams:
type: string
description: Filter the query with numeric, facet and/or tag filters.
default: ''
# There could be a pattern for this one (complicated one)
facetFilters:
type: array
items:
type: string
description: Filter hits by facet value.
default: []
$ref: '#/facetFilters'
optionalFilters:
type: array
items:
type: string
description: Create filters for ranking purposes, where records that match the filter are ranked higher, or lower in the case of a negative optional filter.
default: []
$ref: '#/optionalFilters'
numericFilters:
type: array
items:
type: string
description: Filter on numeric attributes.
default: []
$ref: '#/numericFilters'
tagFilters:
type: array
items:
type: string
description: Filter hits by tags.
default: []
$ref: '#/tagFilters'
sumOrFiltersScores:
type: boolean
description: Determines how to calculate the total score for filtering.
Expand Down Expand Up @@ -164,6 +147,8 @@ baseSearchParams:
type: boolean
description: Whether this search should use AI Re-Ranking.
default: true
reRankingApplyFilter:
$ref: '#/reRankingApplyFilter'

searchParamsString:
type: object
Expand Down Expand Up @@ -202,3 +187,47 @@ aroundRadius:
aroundRadiusAll:
type: string
enum: [all]

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

searchFiltersNestedArrayString:
type: array
items:
type: array
items:
type: string

facetFilters:
description: Filter hits by facet value.
oneOf:
- $ref: '#/searchFiltersArrayString'
- $ref: '#/searchFiltersNestedArrayString'

reRankingApplyFilter:
description: When Dynamic Re-Ranking is enabled, only records that match these filters will be impacted by Dynamic Re-Ranking.
oneOf:
- $ref: '#/searchFiltersArrayString'
- $ref: '#/searchFiltersNestedArrayString'

tagFilters:
description: Filter hits by tags.
oneOf:
- $ref: '#/searchFiltersArrayString'
- $ref: '#/searchFiltersNestedArrayString'

numericFilters:
description: Filter on numeric attributes.
oneOf:
- $ref: '#/searchFiltersArrayString'
- $ref: '#/searchFiltersNestedArrayString'

optionalFilters:
description: Create filters for ranking purposes, where records that match the filter are ranked higher, or lower in the case of a negative optional filter.
oneOf:
- $ref: '#/searchFiltersArrayString'
- $ref: '#/searchFiltersNestedArrayString'
61 changes: 44 additions & 17 deletions specs/search/common/schemas/Hit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,22 +64,9 @@ rankingInfo:
type: integer
description: Precision used when computing the geo distance, in meters.
matchedGeoLocation:
type: object
additionalProperties:
type: object
additionalProperties: false
properties:
lat:
type: number
format: double
description: Latitude of the matched location.
lng:
type: number
format: double
description: Longitude of the matched location.
distance:
type: integer
description: Distance between the matched location and the search location (in meters).
$ref: '#/matchedGeoLocation'
personalization:
$ref: '#/personalization'
nbExactWords:
type: integer
description: Number of exactly matched words.
Expand All @@ -95,9 +82,21 @@ rankingInfo:
userScore:
type: integer
description: Custom ranking for the object, expressed as a single integer value.
word:
words:
type: integer
description: Number of matched words, including prefixes and typos.
promotedByReRanking:
type: boolean
description: Wether the record are promoted by the re-ranking strategy.
required:
- promoted
- nbTypos
- firstMatchedWord
- geoDistance
- nbExactWords
- words
- filters
- userScore

highlightedValue:
type: string
Expand All @@ -108,3 +107,31 @@ matchLevel:
type: string
description: Indicates how well the attribute matched the search query.
enum: [none, partial, full]

matchedGeoLocation:
type: object
properties:
lat:
type: number
format: double
description: Latitude of the matched location.
lng:
type: number
format: double
description: Longitude of the matched location.
distance:
type: integer
description: Distance between the matched location and the search location (in meters).

personalization:
type: object
properties:
filtersScore:
type: integer
description: The score of the filters.
rankingScore:
type: integer
description: The score of the ranking.
score:
type: integer
description: The score of the event.
24 changes: 24 additions & 0 deletions tests/CTS/methods/requests/search/search.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[
{
"method": "search",
"testName": "search with minimal parameters",
"parameters": {
"indexName": "indexName",
"searchParams": {
Expand All @@ -14,5 +15,28 @@
"query": "myQuery"
}
}
},
{
"method": "search",
"testName": "search with facetFilters",
"parameters": {
"indexName": "indexName",
"searchParams": {
"query": "myQuery",
"facetFilters": [
"tags:algolia"
]
}
},
"request": {
"path": "/1/indexes/indexName/query",
"method": "POST",
"data": {
"query": "myQuery",
"facetFilters": [
"tags:algolia"
]
}
}
}
]
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{{#oneOfModel}}{{{classname}}}.of{{{name}}}({{{key}}}{{suffix}}){{/oneOfModel}}{{^oneOfModel}}{{{key}}}{{suffix}}{{/oneOfModel}}
shortcuts marked this conversation as resolved.
Show resolved Hide resolved
{{#oneOfModel}}{{{classname}}}.of{{{name}}}({{{key}}}{{suffix}}){{/oneOfModel}}{{^oneOfModel}}{{{key}}}{{suffix}}{{/oneOfModel}}
Loading