Skip to content

Commit 35bf16c

Browse files
Fluf22eric-zaharia
andauthored
fix(specs): add searchResponsePartial fallback to searchResult oneOf (#6350)
Co-authored-by: Eric Zaharia <94015633+eric-zaharia@users.noreply.github.com>
1 parent 764239a commit 35bf16c

5 files changed

Lines changed: 39 additions & 2 deletions

File tree

clients/algoliasearch-client-swift/Sources/Search/Extra/SearchClientExtension.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,8 @@ public extension SearchClient {
370370
acc.append(searchResponse)
371371
case .searchForFacetValuesResponse:
372372
break
373+
case .searchResponsePartial:
374+
break
373375
}
374376
}
375377
}
@@ -392,6 +394,8 @@ public extension SearchClient {
392394
acc.append(contentsOf: searchResponse.hits)
393395
case .searchForFacetValuesResponse:
394396
break
397+
case .searchResponsePartial:
398+
break
395399
}
396400
}
397401
}
@@ -414,6 +418,8 @@ public extension SearchClient {
414418
break
415419
case let .searchForFacetValuesResponse(searchForFacet):
416420
acc.append(searchForFacet)
421+
case .searchResponsePartial:
422+
break
417423
}
418424
}
419425
}

specs/search/common/schemas/SearchResponse.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,36 @@ searchResponse:
55
- $ref: '../../../common/schemas/SearchResponse.yml#/SearchPagination'
66
- $ref: '#/searchHits'
77

8+
searchResponsePartial:
9+
description: |
10+
Partial search response returned when the `responseFields` parameter excludes
11+
fields like `hits`. Contains all possible search response properties but
12+
none are required, so it acts as an unconditional fallback during oneOf
13+
deserialization.
14+
additionalProperties: true
15+
allOf:
16+
- $ref: '../../../common/schemas/SearchResponse.yml#/baseSearchResponse'
17+
- $ref: '../../../common/schemas/SearchResponse.yml#/SearchPagination'
18+
- type: object
19+
additionalProperties: true
20+
properties:
21+
hits:
22+
type: array
23+
description: |
24+
Search results (hits).
25+
26+
Hits are records from your index that match the search criteria, augmented with additional attributes, such as, for highlighting.
27+
items:
28+
$ref: 'Hit.yml#/hit'
29+
query:
30+
$ref: '../../../common/schemas/SearchParams.yml#/query'
31+
params:
32+
type: string
33+
description: URL-encoded string of all search parameters.
34+
example: query=a&hitsPerPage=20
35+
extensions:
36+
$ref: '#/responseExtensions'
37+
838
searchHits:
939
type: object
1040
additionalProperties: true

specs/search/common/schemas/SearchResult.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ searchResult:
22
oneOf:
33
- $ref: 'SearchResponse.yml#/searchResponse'
44
- $ref: 'SearchForFacetValuesResponse.yml#/searchForFacetValuesResponse'
5+
- $ref: 'SearchResponse.yml#/searchResponsePartial'

templates/csharp/modelOneOf.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
/// with a {{#lambdaCref}}{{{dataType}}}{{/lambdaCref}}
4646
/// </summary>
4747
/// <param name="actualInstance">An instance of {{{dataType}}}.</param>
48-
public {{classname}}(object actualInstance)
48+
public {{classname}}({{{dataType}}}<T> actualInstance)
4949
{
5050
ActualInstance = actualInstance{{^model.isNullable}}{{^isPrimitiveType}}{{^allowableValues}} ?? throw new ArgumentException("Invalid instance found. Must not be null."){{/allowableValues}}{{/isPrimitiveType}}{{#isPrimitiveType}}{{#isArray}} ?? throw new ArgumentException("Invalid instance found. Must not be null."){{/isArray}}{{#isFreeFormObject}} ?? throw new ArgumentException("Invalid instance found. Must not be null."){{/isFreeFormObject}}{{#isString}} ?? throw new ArgumentException("Invalid instance found. Must not be null."){{/isString}}{{/isPrimitiveType}}{{/model.isNullable}};
5151
}

templates/swift/modelObject.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
throw GenericError(description: "Failed to cast")
7676
}
7777
self.{{{name}}} = {{{name}}}{{/required}}{{^required}}
78-
self.{{{name}}} = dictionary["{{{name}}}"]?.value as? {{{datatype}}}
78+
self.{{{name}}} = dictionary["{{{name}}}"]?.value as? {{> generic_type}}
7979
{{/required}}
8080
{{/vars}}
8181

0 commit comments

Comments
 (0)