Skip to content

Commit

Permalink
fix: suppress empty legs property in routing JSON responses (#1584)
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelsJP authored Oct 27, 2023
2 parents 35a6d2e + 187b85b commit dcfe1c0
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ RELEASING:
- YML configuration ([#1506](https://github.com/GIScience/openrouteservice/pull/1506))

### Changed
- suppress empty legs property in routing JSON responses ([#1584](https://github.com/GIScience/openrouteservice/pull/1584))
- url_check.sh to support custom sleep and reporting intervals ([#1468](https://github.com/GIScience/openrouteservice/pull/1468))
- autogenerated API specification from Swagger 2.0 to OpenAPI 3.0 ([#1487](https://github.com/GIScience/openrouteservice/pull/1487))
- class/variable naming from Swagger to OpenAPI ([#1504](https://github.com/GIScience/openrouteservice/pull/1504))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ public class JSONIndividualRouteResponse extends JSONBasedIndividualRouteRespons

@Schema(description = "List containing the legs the route consists of.")
@JsonProperty("legs")
@JsonInclude()
@JsonInclude(JsonInclude.Include.NON_EMPTY)
private final List<JSONLeg> legs;

private final Map<String, JSONExtra> extras;

@Schema(description = "Departure date and time",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public ResultTest() {
coordFootBridge1.put(49.415036);
coordsFootBridge.put(coordFootBridge1);
JSONArray coordFootBridge2 = new JSONArray();
coordFootBridge2.put( 8.692765);
coordFootBridge2.put(8.692765);
coordFootBridge2.put(49.410540);
coordsFootBridge.put(coordFootBridge2);

Expand Down Expand Up @@ -815,6 +815,29 @@ void testSegmentDistances() {
.statusCode(200);
}

@Test
void testNoLegsIfNotPT() {
JSONObject body = new JSONObject();
body.put("coordinates", getParameter("coordinatesLong"));
body.put("preference", getParameter("preference"));
body.put("instructions", true);
body.put("elevation", true);

given()
.config(JSON_CONFIG_DOUBLE_NUMBERS)
.headers(CommonHeaders.jsonContent)
.pathParam("profile", getParameter("carProfile"))
.body(body.toString())
.when()
.post(getEndPointPath() + "/{profile}")
.then().log().ifValidationFails()
.assertThat()
.body("any { it.key == 'routes' }", is(true))
.body("routes[0].containsKey('segments')", is(true))
.body("routes[0].containsKey('legs')", is(false))
.statusCode(200);
}

@Test
void testWaypoints() {
JSONObject body = new JSONObject();
Expand Down Expand Up @@ -854,7 +877,7 @@ void testBbox() {
.then()
.assertThat()
.body("any { it.key == 'routes' }", is(true))
.body("routes[0].bbox", hasItems(closeTo(8.678615,0.1), closeTo(49.388405,0.5), closeTo(106.83,1), closeTo(8.719662,0.1), closeTo(49.424603,0.5), closeTo(411.73,4)))
.body("routes[0].bbox", hasItems(closeTo(8.678615, 0.1), closeTo(49.388405, 0.5), closeTo(106.83, 1), closeTo(8.719662, 0.1), closeTo(49.424603, 0.5), closeTo(411.73, 4)))
.statusCode(200);
}

Expand All @@ -877,7 +900,7 @@ void testManeuver() {
.then().log().ifValidationFails()
.assertThat()
.body("any { it.key == 'routes' }", is(true))
.body("routes[0].bbox", hasItems(closeTo(8.678615,0.1), closeTo(49.388405f,0.5), closeTo(106.83f, 1), closeTo(8.719662f, 0.1), closeTo(49.424603f,0.5), closeTo(411.73f, 4)))
.body("routes[0].bbox", hasItems(closeTo(8.678615, 0.1), closeTo(49.388405f, 0.5), closeTo(106.83f, 1), closeTo(8.719662f, 0.1), closeTo(49.424603f, 0.5), closeTo(411.73f, 4)))
.body("routes[0].segments[0].steps[0].maneuver.bearing_before", is(0))
.body("routes[0].segments[0].steps[0].maneuver.bearing_after", is(175))
.body("routes[0].segments[0].steps[0].maneuver.containsKey('location')", is(true))
Expand Down Expand Up @@ -3697,7 +3720,7 @@ void expectMaxpeedHgvForward() {
.then()
.assertThat()
.body("any { it.key == 'routes' }", is(true))
.body("routes[0].summary.distance", is(closeTo(497.5f,4)))
.body("routes[0].summary.distance", is(closeTo(497.5f, 4)))
.body("routes[0].summary.duration", is(closeTo(61.9f, 0.6)))
.statusCode(200);

Expand All @@ -3711,8 +3734,8 @@ void expectMaxpeedHgvForward() {
.then()
.assertThat()
.body("any { it.key == 'routes' }", is(true))
.body("routes[0].summary.distance", is(closeTo(497.5f,4)))
.body("routes[0].summary.duration", is(closeTo(81.1f,0.8)))
.body("routes[0].summary.distance", is(closeTo(497.5f, 4)))
.body("routes[0].summary.duration", is(closeTo(81.1f, 0.8)))
.statusCode(200);
}

Expand Down

0 comments on commit dcfe1c0

Please sign in to comment.