Browse Source

SONAR-18388 Fix order of changelog in /list endpoint

tags/10.0.0.68432
Léo Geoffroy 1 year ago
parent
commit
87463757bd

+ 2
- 1
server/sonar-webserver-webapi/src/main/java/org/sonar/server/ws/ws/ListAction.java View 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());

+ 20
- 0
server/sonar-webserver-webapi/src/main/resources/org/sonar/server/ws/ws/list-example.json View File

@@ -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",

+ 24
- 2
server/sonar-webserver-webapi/src/test/java/org/sonar/server/ws/ws/ListActionTest.java View 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) {

}
}
}

+ 20
- 0
server/sonar-webserver-webapi/src/test/resources/org/sonar/server/ws/ws/ListActionTest/list_including_internals.json View File

@@ -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",

Loading…
Cancel
Save