Skip to content

Commit c2a054f

Browse files
authored
fix(specs): allow searchParams in browse method (#911)
1 parent d007211 commit c2a054f

File tree

11 files changed

+60
-43
lines changed

11 files changed

+60
-43
lines changed

.github/.cache_version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.0.12
1+
0.0.13

specs/common/schemas/SearchParams.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -232,11 +232,6 @@ page:
232232
x-categories:
233233
- Pagination
234234

235-
cursor:
236-
type: string
237-
description: Cursor indicating the location to resume browsing from. Must match the value returned by the previous call.
238-
example: jMDY3M2MwM2QwMWUxMmQwYWI0ZTN
239-
240235
aroundRadius:
241236
description: Define the maximum radius for a geo search (in meters).
242237
oneOf:
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
browseParams:
2+
oneOf:
3+
- $ref: '../../../common/schemas/SearchParams.yml#/searchParamsString'
4+
- $ref: '#/browseParamsObject'
5+
6+
browseParamsObject:
7+
allOf:
8+
- $ref: '../../../common/schemas/SearchParams.yml#/searchParamsObject'
9+
- $ref: '#/cursor'
10+
11+
cursor:
12+
type: object
13+
additionalProperties: false
14+
properties:
15+
cursor:
16+
type: string
17+
description: Cursor indicating the location to resume browsing from. Must match the value returned by the previous call.
18+
example: jMDY3M2MwM2QwMWUxMmQwYWI0ZTN
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
browseResponse:
2+
allOf:
3+
- $ref: './SearchResponse.yml#/baseSearchResponse'
4+
- $ref: './SearchResponse.yml#/searchHits'
5+
- $ref: './BrowseParams.yml#/cursor'

specs/search/common/schemas/SearchResponse.yml

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,8 @@
1-
SearchResponse:
1+
searchResponse:
22
allOf:
33
- $ref: '#/baseSearchResponse'
44
- $ref: '#/searchHits'
55

6-
browseResponse:
7-
allOf:
8-
- $ref: '#/baseSearchResponse'
9-
- $ref: '#/searchHits'
10-
- $ref: '#/baseBrowseResponse'
11-
12-
baseBrowseResponse:
13-
type: object
14-
additionalProperties: false
15-
properties:
16-
cursor:
17-
$ref: '../../../common/schemas/SearchParams.yml#/cursor'
18-
196
searchHits:
207
type: object
218
additionalProperties: false

specs/search/paths/search/browse.yml

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,14 @@ post:
1515
content:
1616
application/json:
1717
schema:
18-
title: browseRequest
19-
type: object
20-
additionalProperties: false
21-
properties:
22-
params:
23-
$ref: '../../../common/schemas/SearchParams.yml#/paramsAsString'
24-
cursor:
25-
$ref: '../../../common/schemas/SearchParams.yml#/cursor'
18+
$ref: '../../common/schemas/BrowseParams.yml#/browseParams'
2619
responses:
2720
'200':
2821
description: OK
2922
content:
3023
application/json:
3124
schema:
32-
$ref: '../../common/schemas/SearchResponse.yml#/browseResponse'
25+
$ref: '../../common/schemas/BrowseResponse.yml#/browseResponse'
3326
'400':
3427
$ref: '../../../common/responses/BadRequest.yml'
3528
'402':

specs/search/paths/search/search.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ post:
3838
results:
3939
type: array
4040
items:
41-
$ref: '../../common/schemas/SearchResponse.yml#/SearchResponse'
41+
$ref: '../../common/schemas/SearchResponse.yml#/searchResponse'
4242
required:
4343
- results
4444
'400':

specs/search/paths/search/searchSingleIndex.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ post:
1919
content:
2020
application/json:
2121
schema:
22-
$ref: '../../common/schemas/SearchResponse.yml#/SearchResponse'
22+
$ref: '../../common/schemas/SearchResponse.yml#/searchResponse'
2323
'400':
2424
$ref: '../../../common/responses/BadRequest.yml'
2525
'402':

templates/javascript/clients/client/api/helpers.mustache

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,15 +113,15 @@ waitForApiKey(
113113
* @summary Helper method that iterates on the `browse` method.
114114
* @param browseObjects - The browseObjects object.
115115
* @param browseObjects.indexName - The index in which to perform the request.
116-
* @param browseObjects.browseRequest - The `browse` method parameters.
116+
* @param browseObjects.browseParams - The `browse` parameters.
117117
* @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.
118118
* @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`.
119119
* @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `browse` method and merged with the transporter requestOptions.
120120
*/
121121
browseObjects<T>(
122122
{
123123
indexName,
124-
browseRequest,
124+
browseParams,
125125
...browseObjectsOptions
126126
}: BrowseOptions<BrowseResponse<T>> & BrowseProps,
127127
requestOptions?: RequestOptions
@@ -131,9 +131,9 @@ browseObjects<T>(
131131
return this.browse(
132132
{
133133
indexName,
134-
browseRequest: {
134+
browseParams: {
135135
cursor: previousResponse ? previousResponse.cursor : undefined,
136-
...browseRequest,
136+
...browseParams,
137137
},
138138
},
139139
requestOptions

tests/CTS/methods/requests/search/browse.json

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[
22
{
3-
"testName": "get browse results with minimal parameters",
3+
"testName": "browse with minimal parameters",
44
"parameters": {
55
"indexName": "indexName"
66
},
@@ -10,20 +10,40 @@
1010
}
1111
},
1212
{
13-
"testName": "get browse results with all parameters",
13+
"testName": "browse with search parameters",
1414
"parameters": {
1515
"indexName": "indexName",
16-
"browseRequest": {
17-
"params": "query=foo&facetFilters=['bar']",
18-
"cursor": "cts"
16+
"browseParams": {
17+
"query": "myQuery",
18+
"facetFilters": [
19+
"tags:algolia"
20+
]
1921
}
2022
},
2123
"request": {
2224
"path": "/1/indexes/indexName/browse",
2325
"method": "POST",
2426
"body": {
25-
"params": "query=foo&facetFilters=['bar']",
26-
"cursor": "cts"
27+
"query": "myQuery",
28+
"facetFilters": [
29+
"tags:algolia"
30+
]
31+
}
32+
}
33+
},
34+
{
35+
"testName": "browse allow a cursor in parameters",
36+
"parameters": {
37+
"indexName": "indexName",
38+
"browseParams": {
39+
"cursor": "test"
40+
}
41+
},
42+
"request": {
43+
"path": "/1/indexes/indexName/browse",
44+
"method": "POST",
45+
"body": {
46+
"cursor": "test"
2747
}
2848
}
2949
}

tests/CTS/methods/requests/search/searchSingleIndex.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
}
1111
},
1212
{
13-
"method": "search",
1413
"testName": "search with searchParams",
1514
"parameters": {
1615
"indexName": "indexName",

0 commit comments

Comments
 (0)