Skip to content

Commit

Permalink
fix(specs): allow searchParams in browse method (#911)
Browse files Browse the repository at this point in the history
  • Loading branch information
shortcuts authored Aug 9, 2022
1 parent d007211 commit c2a054f
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 43 deletions.
2 changes: 1 addition & 1 deletion .github/.cache_version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.12
0.0.13
5 changes: 0 additions & 5 deletions specs/common/schemas/SearchParams.yml
Original file line number Diff line number Diff line change
Expand Up @@ -232,11 +232,6 @@ page:
x-categories:
- Pagination

cursor:
type: string
description: Cursor indicating the location to resume browsing from. Must match the value returned by the previous call.
example: jMDY3M2MwM2QwMWUxMmQwYWI0ZTN

aroundRadius:
description: Define the maximum radius for a geo search (in meters).
oneOf:
Expand Down
18 changes: 18 additions & 0 deletions specs/search/common/schemas/BrowseParams.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
browseParams:
oneOf:
- $ref: '../../../common/schemas/SearchParams.yml#/searchParamsString'
- $ref: '#/browseParamsObject'

browseParamsObject:
allOf:
- $ref: '../../../common/schemas/SearchParams.yml#/searchParamsObject'
- $ref: '#/cursor'

cursor:
type: object
additionalProperties: false
properties:
cursor:
type: string
description: Cursor indicating the location to resume browsing from. Must match the value returned by the previous call.
example: jMDY3M2MwM2QwMWUxMmQwYWI0ZTN
5 changes: 5 additions & 0 deletions specs/search/common/schemas/BrowseResponse.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
browseResponse:
allOf:
- $ref: './SearchResponse.yml#/baseSearchResponse'
- $ref: './SearchResponse.yml#/searchHits'
- $ref: './BrowseParams.yml#/cursor'
15 changes: 1 addition & 14 deletions specs/search/common/schemas/SearchResponse.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,8 @@
SearchResponse:
searchResponse:
allOf:
- $ref: '#/baseSearchResponse'
- $ref: '#/searchHits'

browseResponse:
allOf:
- $ref: '#/baseSearchResponse'
- $ref: '#/searchHits'
- $ref: '#/baseBrowseResponse'

baseBrowseResponse:
type: object
additionalProperties: false
properties:
cursor:
$ref: '../../../common/schemas/SearchParams.yml#/cursor'

searchHits:
type: object
additionalProperties: false
Expand Down
11 changes: 2 additions & 9 deletions specs/search/paths/search/browse.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,14 @@ post:
content:
application/json:
schema:
title: browseRequest
type: object
additionalProperties: false
properties:
params:
$ref: '../../../common/schemas/SearchParams.yml#/paramsAsString'
cursor:
$ref: '../../../common/schemas/SearchParams.yml#/cursor'
$ref: '../../common/schemas/BrowseParams.yml#/browseParams'
responses:
'200':
description: OK
content:
application/json:
schema:
$ref: '../../common/schemas/SearchResponse.yml#/browseResponse'
$ref: '../../common/schemas/BrowseResponse.yml#/browseResponse'
'400':
$ref: '../../../common/responses/BadRequest.yml'
'402':
Expand Down
2 changes: 1 addition & 1 deletion specs/search/paths/search/search.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ post:
results:
type: array
items:
$ref: '../../common/schemas/SearchResponse.yml#/SearchResponse'
$ref: '../../common/schemas/SearchResponse.yml#/searchResponse'
required:
- results
'400':
Expand Down
2 changes: 1 addition & 1 deletion specs/search/paths/search/searchSingleIndex.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ post:
content:
application/json:
schema:
$ref: '../../common/schemas/SearchResponse.yml#/SearchResponse'
$ref: '../../common/schemas/SearchResponse.yml#/searchResponse'
'400':
$ref: '../../../common/responses/BadRequest.yml'
'402':
Expand Down
8 changes: 4 additions & 4 deletions templates/javascript/clients/client/api/helpers.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,15 @@ waitForApiKey(
* @summary Helper method that iterates on the `browse` method.
* @param browseObjects - The browseObjects object.
* @param browseObjects.indexName - The index in which to perform the request.
* @param browseObjects.browseRequest - The `browse` method parameters.
* @param browseObjects.browseParams - The `browse` parameters.
* @param browseObjects.validate - The validator function. It receive the resolved return of the API call. By default, stops when there is no `cursor` in the response.
* @param browseObjects.aggregator - The function that runs right after the API call has been resolved, allows you to do anything with the response before `validate`.
* @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `browse` method and merged with the transporter requestOptions.
*/
browseObjects<T>(
{
indexName,
browseRequest,
browseParams,
...browseObjectsOptions
}: BrowseOptions<BrowseResponse<T>> & BrowseProps,
requestOptions?: RequestOptions
Expand All @@ -131,9 +131,9 @@ browseObjects<T>(
return this.browse(
{
indexName,
browseRequest: {
browseParams: {
cursor: previousResponse ? previousResponse.cursor : undefined,
...browseRequest,
...browseParams,
},
},
requestOptions
Expand Down
34 changes: 27 additions & 7 deletions tests/CTS/methods/requests/search/browse.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[
{
"testName": "get browse results with minimal parameters",
"testName": "browse with minimal parameters",
"parameters": {
"indexName": "indexName"
},
Expand All @@ -10,20 +10,40 @@
}
},
{
"testName": "get browse results with all parameters",
"testName": "browse with search parameters",
"parameters": {
"indexName": "indexName",
"browseRequest": {
"params": "query=foo&facetFilters=['bar']",
"cursor": "cts"
"browseParams": {
"query": "myQuery",
"facetFilters": [
"tags:algolia"
]
}
},
"request": {
"path": "/1/indexes/indexName/browse",
"method": "POST",
"body": {
"params": "query=foo&facetFilters=['bar']",
"cursor": "cts"
"query": "myQuery",
"facetFilters": [
"tags:algolia"
]
}
}
},
{
"testName": "browse allow a cursor in parameters",
"parameters": {
"indexName": "indexName",
"browseParams": {
"cursor": "test"
}
},
"request": {
"path": "/1/indexes/indexName/browse",
"method": "POST",
"body": {
"cursor": "test"
}
}
}
Expand Down
1 change: 0 additions & 1 deletion tests/CTS/methods/requests/search/searchSingleIndex.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
}
},
{
"method": "search",
"testName": "search with searchParams",
"parameters": {
"indexName": "indexName",
Expand Down

0 comments on commit c2a054f

Please sign in to comment.