From ebd8e1dc017576530ef38f79bdbb8106455bc0a2 Mon Sep 17 00:00:00 2001 From: Takara Baumbach Date: Fri, 27 Oct 2023 09:18:59 +0200 Subject: [PATCH 1/3] fix: suppress empty legs property in routing JSON responses --- .../responses/routing/json/JSONIndividualRouteResponse.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ors-api/src/main/java/org/heigit/ors/api/responses/routing/json/JSONIndividualRouteResponse.java b/ors-api/src/main/java/org/heigit/ors/api/responses/routing/json/JSONIndividualRouteResponse.java index 0e11d7e0c2..445e95e0fc 100644 --- a/ors-api/src/main/java/org/heigit/ors/api/responses/routing/json/JSONIndividualRouteResponse.java +++ b/ors-api/src/main/java/org/heigit/ors/api/responses/routing/json/JSONIndividualRouteResponse.java @@ -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 legs; + private final Map extras; @Schema(description = "Departure date and time", From 2cf43dd4573bb454960bec620249217a995d6e52 Mon Sep 17 00:00:00 2001 From: Takara Baumbach Date: Fri, 27 Oct 2023 09:39:47 +0200 Subject: [PATCH 2/3] docs: CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 395920d8e5..68b382b61a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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)) From 187b85b0d3fb4810f5f97506e950192e5267f791 Mon Sep 17 00:00:00 2001 From: Takara Baumbach Date: Fri, 27 Oct 2023 14:01:29 +0200 Subject: [PATCH 3/3] test: add apitest to check --- .../ors/apitests/routing/ResultTest.java | 35 +++++++++++++++---- 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/ors-api/src/test/java/org/heigit/ors/apitests/routing/ResultTest.java b/ors-api/src/test/java/org/heigit/ors/apitests/routing/ResultTest.java index f3a62ef931..cf87fe7746 100644 --- a/ors-api/src/test/java/org/heigit/ors/apitests/routing/ResultTest.java +++ b/ors-api/src/test/java/org/heigit/ors/apitests/routing/ResultTest.java @@ -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); @@ -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(); @@ -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); } @@ -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)) @@ -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); @@ -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); }