]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-18388 Fix order of changelog in /list endpoint
authorLéo Geoffroy <leo.geoffroy@sonarsource.com>
Fri, 3 Feb 2023 13:23:49 +0000 (14:23 +0100)
committersonartech <sonartech@sonarsource.com>
Fri, 3 Feb 2023 14:41:22 +0000 (14:41 +0000)
server/sonar-webserver-webapi/src/main/java/org/sonar/server/ws/ws/ListAction.java
server/sonar-webserver-webapi/src/main/resources/org/sonar/server/ws/ws/list-example.json
server/sonar-webserver-webapi/src/test/java/org/sonar/server/ws/ws/ListActionTest.java
server/sonar-webserver-webapi/src/test/resources/org/sonar/server/ws/ws/ListActionTest/list_including_internals.json

index ee6edcb78b4165688c745fba70b36ec631e013c0..bd97a993d596b14d5fc59386db7a60fa395d0aea 100644 (file)
@@ -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());
index a01a74930081de52a8768b7cd26bfbcbcdca14c9..1163f40fb6a5a34386298f785c1213f39f4170fc 100644 (file)
       "description": "Get information on the web api supported on this instance.",
       "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",
index f2897d0bae247bef828eb04513b7548bde7ef1ff..d97a50bf71376c5ebc612683ee8448ea109c9a51 100644 (file)
@@ -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) {
+
+    }
+  }
 }
index d118e6e60cfad3e838e9c5fb143e13fd6b515e84..a7e56dd2d7fe9ccafd976649920cfc3cede7fb16 100644 (file)
       "description": "Get information on the web api supported on this instance.",
       "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",