Skip to content

Commit da29b77

Browse files
author
Clément Le Provost
authored
Implement the responseFields query parameter (#158)
[ci skip]
1 parent 8e43fde commit da29b77

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

Source/Query.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,28 @@ open class Query : AbstractQuery {
708708
}
709709
}
710710
}
711+
712+
// MARK: Advanced
713+
714+
/// Choose which fields the response will contain. Applies to search and browse queries.
715+
///
716+
/// By default, all fields are returned. If this parameter is specified, only the fields explicitly listed will be
717+
/// returned, unless `*` is used, in which case all fields are returned. Specifying an empty list or unknown field
718+
/// names is an error.
719+
///
720+
/// This parameter is mainly intended to limit the response size. For example, for complex queries, echoing of
721+
/// request parameters in the response's params field can be undesirable.
722+
///
723+
/// Some fields cannot be filtered out:
724+
///
725+
/// - `warning` message
726+
/// - `cursor` in browse queries
727+
/// - fields triggered explicitly via `getRankingInfo`
728+
///
729+
@objc public var responseFields: [String]? {
730+
get { return Query.parseStringArray(self["responseFields"]) }
731+
set { self["responseFields"] = Query.buildJSONArray(newValue) }
732+
}
711733

712734
// MARK: - Initialization
713735

Tests/ObjectiveCBridging.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ - (void)testQuery {
118118
query.minimumAroundRadius = [NSNumber numberWithInt:666];
119119
query.insideBoundingBox = @[ [[GeoRect alloc] initWithP1:[[LatLng alloc] initWithLat:123.45 lng:67.89] p2:[[LatLng alloc] initWithLat:129.99 lng:69.99]] ];
120120
query.insidePolygon = @[ [[LatLng alloc] initWithLat:123.45 lng:67.89], [[LatLng alloc] initWithLat:129.99 lng:69.99], [[LatLng alloc] initWithLat:0.0 lng:0.0] ];
121+
query.responseFields = @[ @"foo", @"bar" ];
121122
}
122123

123124
- (void)testClient {

Tests/QueryTests.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,4 +673,14 @@ class QueryTests: XCTestCase {
673673
XCTAssertNotNil(query1.alternativesAsExact)
674674
XCTAssertEqual(0, query1.alternativesAsExact?.count)
675675
}
676+
677+
func test_responseFields() {
678+
let query1 = Query()
679+
XCTAssertNil(query1.responseFields)
680+
query1.responseFields = ["foo", "bar"]
681+
XCTAssertEqual(query1.responseFields!, ["foo", "bar"])
682+
XCTAssertEqual(query1["responseFields"], "[\"foo\",\"bar\"]")
683+
let query2 = Query.parse(query1.build())
684+
XCTAssertEqual(query2.responseFields!, ["foo", "bar"])
685+
}
676686
}

0 commit comments

Comments
 (0)