aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLéo Geoffroy <leo.geoffroy@sonarsource.com>2023-02-03 14:23:49 +0100
committersonartech <sonartech@sonarsource.com>2023-02-03 14:41:22 +0000
commit87463757bd09191d2464b2f3778cf98411179fd0 (patch)
tree232144897f6c2457aac4b8189ff16f8396b3d139
parent4420e38ff6ab4c38e31740f05f2858a2ed2c6f93 (diff)
downloadsonarqube-87463757bd09191d2464b2f3778cf98411179fd0.tar.gz
sonarqube-87463757bd09191d2464b2f3778cf98411179fd0.zip
SONAR-18388 Fix order of changelog in /list endpoint
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/ws/ws/ListAction.java3
-rw-r--r--server/sonar-webserver-webapi/src/main/resources/org/sonar/server/ws/ws/list-example.json20
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/ws/ws/ListActionTest.java26
-rw-r--r--server/sonar-webserver-webapi/src/test/resources/org/sonar/server/ws/ws/ListActionTest/list_including_internals.json20
4 files changed, 66 insertions, 3 deletions
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ws/ws/ListAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ws/ws/ListAction.java
index ee6edcb78b4..bd97a993d59 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ws/ws/ListAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ws/ws/ListAction.java
@@ -26,6 +26,7 @@ import org.sonar.api.server.ws.Change;
import org.sonar.api.server.ws.Request;
import org.sonar.api.server.ws.Response;
import org.sonar.api.server.ws.WebService;
+import org.sonar.api.utils.Version;
import org.sonar.api.utils.text.JsonWriter;
import org.sonar.core.util.stream.MoreCollectors;
@@ -144,7 +145,7 @@ public class ListAction implements WebServicesWsAction {
private static void writeChangelog(JsonWriter writer, WebService.Action action) {
writer.name("changelog").beginArray();
action.changelog().stream()
- .sorted(Comparator.comparing(Change::getVersion).reversed())
+ .sorted(Comparator.comparing((Change change) -> Version.parse(change.getVersion())).reversed())
.forEach(changelog -> {
writer.beginObject();
writer.prop("description", changelog.getDescription());
diff --git a/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/ws/ws/list-example.json b/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/ws/ws/list-example.json
index a01a7493008..1163f40fb6a 100644
--- a/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/ws/ws/list-example.json
+++ b/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/ws/ws/list-example.json
@@ -79,6 +79,26 @@
"since": "4.2",
"actions": [
{
+ "key": "action",
+ "internal": false,
+ "post": false,
+ "hasResponseExample": false,
+ "changelog": [
+ {
+ "description": "Ten",
+ "version": "10.0"
+ },
+ {
+ "description": "Second",
+ "version": "2.0"
+ },
+ {
+ "description": "Initial",
+ "version": "1.0"
+ }
+ ]
+ },
+ {
"key": "list",
"since": "4.2",
"description": "List web services",
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ws/ws/ListActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ws/ws/ListActionTest.java
index f2897d0bae2..d97a50bf713 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ws/ws/ListActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ws/ws/ListActionTest.java
@@ -22,6 +22,9 @@ package org.sonar.server.ws.ws;
import java.util.Arrays;
import org.junit.Before;
import org.junit.Test;
+import org.sonar.api.server.ws.Change;
+import org.sonar.api.server.ws.Request;
+import org.sonar.api.server.ws.Response;
import org.sonar.api.server.ws.WebService;
import org.sonar.server.ws.TestRequest;
@@ -38,11 +41,10 @@ public class ListActionTest {
.setDescription("Get information on the web api supported on this instance.")
.setSince("4.2");
- for (WebServicesWsAction wsWsAction : Arrays.asList(underTest, new ResponseExampleAction())) {
+ for (WebServicesWsAction wsWsAction : Arrays.asList(underTest, new ResponseExampleAction(), new ChangeLogAction())) {
wsWsAction.define(newController);
wsWsAction.setContext(context);
}
-
newController.done();
action = context.controller("api/webservices").action("list");
}
@@ -73,4 +75,24 @@ public class ListActionTest {
return request;
}
+ class ChangeLogAction implements WebServicesWsAction {
+
+ @Override
+ public void define(WebService.NewController controller) {
+ WebService.NewAction action = controller
+ .createAction("action")
+ .setHandler(this);
+ action.setChangelog(new Change("1.0", "Initial"), new Change("2.0", "Second"), new Change("10.0", "Ten"));
+ }
+
+ @Override
+ public void handle(Request request, Response response) throws Exception {
+
+ }
+
+ @Override
+ public void setContext(WebService.Context context) {
+
+ }
+ }
}
diff --git a/server/sonar-webserver-webapi/src/test/resources/org/sonar/server/ws/ws/ListActionTest/list_including_internals.json b/server/sonar-webserver-webapi/src/test/resources/org/sonar/server/ws/ws/ListActionTest/list_including_internals.json
index d118e6e60cf..a7e56dd2d7f 100644
--- a/server/sonar-webserver-webapi/src/test/resources/org/sonar/server/ws/ws/ListActionTest/list_including_internals.json
+++ b/server/sonar-webserver-webapi/src/test/resources/org/sonar/server/ws/ws/ListActionTest/list_including_internals.json
@@ -72,6 +72,26 @@
"since": "4.2",
"actions": [
{
+ "key": "action",
+ "internal": false,
+ "post": false,
+ "hasResponseExample": false,
+ "changelog": [
+ {
+ "description": "Ten",
+ "version": "10.0"
+ },
+ {
+ "description": "Second",
+ "version": "2.0"
+ },
+ {
+ "description": "Initial",
+ "version": "1.0"
+ }
+ ]
+ },
+ {
"key": "list",
"since": "4.2",
"description": "List web services",