From 87463757bd09191d2464b2f3778cf98411179fd0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?L=C3=A9o=20Geoffroy?= Date: Fri, 3 Feb 2023 14:23:49 +0100 Subject: [PATCH] SONAR-18388 Fix order of changelog in /list endpoint --- .../org/sonar/server/ws/ws/ListAction.java | 3 ++- .../org/sonar/server/ws/ws/list-example.json | 20 ++++++++++++++ .../sonar/server/ws/ws/ListActionTest.java | 26 +++++++++++++++++-- .../list_including_internals.json | 20 ++++++++++++++ 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 @@ -78,6 +78,26 @@ "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", 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 @@ -71,6 +71,26 @@ "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", -- 2.39.5