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;
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());
"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",
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;
.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");
}
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) {
+
+ }
+ }
}
"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",