]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-13850: Add missing response examples to WEB API endpoints.
authorDimitris Kavvathas <dimitris.kavvathas@sonarsource.com>
Fri, 10 Jun 2022 15:02:00 +0000 (17:02 +0200)
committersonartech <sonartech@sonarsource.com>
Mon, 13 Jun 2022 20:03:03 +0000 (20:03 +0000)
Add response example for 'security_reports/show' endpoint
Add response example for 'project_dump/status' endpoint
Add response example for 'alm_integrations/search_azure_repos' endpoint
Add response example for 'alm_integrations/search_bitbucketserver_repos' endpoint
Add response example for 'alm_integrations/list_azure_projects' endpoint
Add response example for 'alm_integrations/search_bitbucketcloud_repos' endpoint
Add response example for 'alm_integrations/list_bitbucketserver_projects endpoint'

18 files changed:
server/sonar-webserver-webapi/src/main/java/org/sonar/server/almintegration/ws/azure/ListAzureProjectsAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/almintegration/ws/azure/SearchAzureReposAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/almintegration/ws/bitbucketcloud/SearchBitbucketCloudReposAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/almintegration/ws/bitbucketserver/ListBitbucketServerProjectsAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/almintegration/ws/bitbucketserver/SearchBitbucketServerReposAction.java
server/sonar-webserver-webapi/src/main/resources/org/sonar/server/almintegration/ws/azure/example-list_azure_projects.json [new file with mode: 0644]
server/sonar-webserver-webapi/src/main/resources/org/sonar/server/almintegration/ws/azure/example-search_azure_repos.json [new file with mode: 0644]
server/sonar-webserver-webapi/src/main/resources/org/sonar/server/almintegration/ws/bitbucketcloud/example-search_bitbucketcloud_repos.json [new file with mode: 0644]
server/sonar-webserver-webapi/src/main/resources/org/sonar/server/almintegration/ws/bitbucketserver/example-list_bitbucketserver_projects.json [new file with mode: 0644]
server/sonar-webserver-webapi/src/main/resources/org/sonar/server/almintegration/ws/bitbucketserver/example-search_bitbucketserver_repos.json [new file with mode: 0644]
server/sonar-webserver-webapi/src/main/resources/org/sonar/server/projectdump/ws/example-status.json [new file with mode: 0644]
server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/azure/ListAzureProjectsActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/azure/SearchAzureReposActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/bitbucketcloud/SearchBitbucketCloudReposActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/bitbucketserver/ListBitbucketServerProjectsActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/bitbucketserver/SearchBitbucketServerReposActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/github/ListGithubOrganizationsActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/projectdump/ws/StatusActionTest.java

index dc0a287e492a23ab987bc7e64e1ed8bd6bb43b77..f585f1c8bdbc405d249e4d8a2cff406311ec72fe 100644 (file)
@@ -65,6 +65,7 @@ public class ListAzureProjectsAction implements AlmIntegrationsWsAction {
         "Requires the 'Create Projects' permission")
       .setPost(false)
       .setSince("8.6")
+      .setResponseExample(getClass().getResource("example-list_azure_projects.json"))
       .setHandler(this);
 
     action.createParam(PARAM_ALM_SETTING)
index c944723ef50fdeaf6dec54bb2db7b687e8da604c..389bfb630c1f0466ddce882fddfbc7f90ce7bfa8 100644 (file)
@@ -84,6 +84,7 @@ public class SearchAzureReposAction implements AlmIntegrationsWsAction {
         "Requires the 'Create Projects' permission")
       .setPost(false)
       .setSince("8.6")
+      .setResponseExample(getClass().getResource("example-search_azure_repos.json"))
       .setHandler(this);
 
     action.createParam(PARAM_ALM_SETTING)
index c0962fd2d8339f5c0f2a22a6bf21337138686a3c..190bd9f255dadfb894a281985c0138baea8bba46 100644 (file)
@@ -79,6 +79,7 @@ public class SearchBitbucketCloudReposAction implements AlmIntegrationsWsAction
         "Requires the 'Create Projects' permission")
       .setPost(false)
       .setSince("9.0")
+      .setResponseExample(getClass().getResource("example-search_bitbucketcloud_repos.json"))
       .setHandler(this);
 
     action.createParam(PARAM_ALM_SETTING)
index f16e9da9e4a1030467947ce50c7c40626db93db7..adcd5339fb60c5fd1a665622146e264c1e4b569d 100644 (file)
@@ -63,6 +63,7 @@ public class ListBitbucketServerProjectsAction implements AlmIntegrationsWsActio
         "Requires the 'Create Projects' permission")
       .setPost(false)
       .setSince("8.2")
+      .setResponseExample(getClass().getResource("example-list_bitbucketserver_projects.json"))
       .setHandler(this);
 
     action.createParam(PARAM_ALM_SETTING)
index 0bfd91e2f09286ec29b359be393ab21715972a89..fd610071cec6676439f636f3f1892a4c207f736c 100644 (file)
@@ -81,6 +81,7 @@ public class SearchBitbucketServerReposAction implements AlmIntegrationsWsAction
         "Requires the 'Create Projects' permission")
       .setPost(false)
       .setSince("8.2")
+      .setResponseExample(getClass().getResource("example-search_bitbucketserver_repos.json"))
       .setHandler(this);
 
     action.createParam(PARAM_ALM_SETTING)
diff --git a/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/almintegration/ws/azure/example-list_azure_projects.json b/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/almintegration/ws/azure/example-list_azure_projects.json
new file mode 100644 (file)
index 0000000..99e646e
--- /dev/null
@@ -0,0 +1,12 @@
+{
+  "projects": [
+    {
+      "name": "project1",
+      "description": "description1"
+    },
+    {
+      "name": "project2",
+      "description": "description2"
+    }
+  ]
+}
diff --git a/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/almintegration/ws/azure/example-search_azure_repos.json b/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/almintegration/ws/azure/example-search_azure_repos.json
new file mode 100644 (file)
index 0000000..dea6d3b
--- /dev/null
@@ -0,0 +1,12 @@
+{
+  "repositories": [
+    {
+      "name": "repoName1",
+      "projectName": "project1"
+    },
+    {
+      "name": "repoName2",
+      "projectName": "project2"
+    }
+  ]
+}
\ No newline at end of file
diff --git a/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/almintegration/ws/bitbucketcloud/example-search_bitbucketcloud_repos.json b/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/almintegration/ws/bitbucketcloud/example-search_bitbucketcloud_repos.json
new file mode 100644 (file)
index 0000000..a643d23
--- /dev/null
@@ -0,0 +1,24 @@
+{
+  "paging": {
+    "pageIndex": 1,
+    "pageSize": 100
+  },
+  "isLastPage": false,
+  "repositories": [
+    {
+      "slug": "repo-slug-1",
+      "uuid": "REPO-UUID-ONE",
+      "name": "repoName1",
+      "projectKey": "projectKey1",
+      "workspace": "60Mna3eiSKjB2JqXucUVXoQMQbl2q0mTxJ2fyR0xfRuAcibVepy7yEfptuuFM3kd3f9v7eKtoT3JPd01"
+    },
+    {
+      "slug": "repo-slug-2",
+      "uuid": "REPO-UUID-TWO",
+      "name": "repoName2",
+      "sqProjectKey": "KEY_01814E2745E7D394BD",
+      "projectKey": "projectKey2",
+      "workspace": "60Mna3eiSKjB2JqXucUVXoQMQbl2q0mTxJ2fyR0xfRuAcibVepy7yEfptuuFM3kd3f9v7eKtoT3JPd01"
+    }
+  ]
+}
\ No newline at end of file
diff --git a/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/almintegration/ws/bitbucketserver/example-list_bitbucketserver_projects.json b/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/almintegration/ws/bitbucketserver/example-list_bitbucketserver_projects.json
new file mode 100644 (file)
index 0000000..52d4ba7
--- /dev/null
@@ -0,0 +1,12 @@
+{
+  "projects": [
+    {
+      "key": "key",
+      "name": "name"
+    },
+    {
+      "key": "key2",
+      "name": "name2"
+    }
+  ]
+}
diff --git a/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/almintegration/ws/bitbucketserver/example-search_bitbucketserver_repos.json b/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/almintegration/ws/bitbucketserver/example-search_bitbucketserver_repos.json
new file mode 100644 (file)
index 0000000..57feeed
--- /dev/null
@@ -0,0 +1,20 @@
+{
+  "isLastPage": false,
+  "repositories": [
+    {
+      "slug": "repo-slug-1",
+      "uuid": "REPO-UUID-ONE",
+      "name": "repoName1",
+      "projectKey": "projectKey1",
+      "workspace": "60Mna3eiSKjB2JqXucUVXoQMQbl2q0mTxJ2fyR0xfRuAcibVepy7yEfptuuFM3kd3f9v7eKtoT3JPd01"
+    },
+    {
+      "slug": "repo-slug-2",
+      "uuid": "REPO-UUID-TWO",
+      "name": "repoName2",
+      "sqProjectKey": "KEY_01814E2745E7D394BD",
+      "projectKey": "projectKey2",
+      "workspace": "60Mna3eiSKjB2JqXucUVXoQMQbl2q0mTxJ2fyR0xfRuAcibVepy7yEfptuuFM3kd3f9v7eKtoT3JPd01"
+    }
+  ]
+}
\ No newline at end of file
diff --git a/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/projectdump/ws/example-status.json b/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/projectdump/ws/example-status.json
new file mode 100644 (file)
index 0000000..6f116fd
--- /dev/null
@@ -0,0 +1,6 @@
+{
+  "canBeExported": true,
+  "canBeImported": false,
+  "exportedDump": "/data/governance/export/my_project.zip",
+  "dumpToImport": "/data/governance/import/my_project.zip"
+}
index c9d2a57fbfa6e129c5c68881d23e974dab6ae81f..6da70e2988888faab06cf3b8d3ce4ab56fa18fb6 100644 (file)
@@ -159,6 +159,7 @@ public class ListAzureProjectsActionTest {
 
     assertThat(def.since()).isEqualTo("8.6");
     assertThat(def.isPost()).isFalse();
+    assertThat(def.responseExampleFormat()).isEqualTo("json");
     assertThat(def.params())
       .extracting(WebService.Param::key, WebService.Param::isRequired)
       .containsExactlyInAnyOrder(tuple("almSetting", true));
index ed5f0d84f5514dcef658adef9af0b1ee859cc6cb..7385919dfaa502c0a50e36dc7ec390299227ca0b 100644 (file)
@@ -77,6 +77,7 @@ public class SearchAzureReposActionTest {
 
     assertThat(def.since()).isEqualTo("8.6");
     assertThat(def.isPost()).isFalse();
+    assertThat(def.responseExampleFormat()).isEqualTo("json");
     assertThat(def.params())
       .extracting(WebService.Param::key, WebService.Param::isRequired)
       .containsExactlyInAnyOrder(
index 24ee3f1f116e3bd2d9c7465e48b36e319b76a9ae..40063d4020db5d22ac41235cf27facb6ef7f29bf 100644 (file)
@@ -184,6 +184,7 @@ public class SearchBitbucketCloudReposActionTest {
 
     assertThat(def.since()).isEqualTo("9.0");
     assertThat(def.isPost()).isFalse();
+    assertThat(def.responseExampleFormat()).isEqualTo("json");
     assertThat(def.params())
       .extracting(WebService.Param::key, WebService.Param::isRequired)
       .containsExactlyInAnyOrder(
@@ -209,8 +210,7 @@ public class SearchBitbucketCloudReposActionTest {
 
   private Repository getBBCRepo2() {
     Project project2 = new Project("PROJECT-UUID-TWO", "projectKey2", "projectName2");
-    Repository repo2 = new Repository("REPO-UUID-TWO", "repo-slug-2", "repoName2", project2, null);
-    return repo2;
+    return new Repository("REPO-UUID-TWO", "repo-slug-2", "repoName2", project2, null);
   }
 
 }
index b5a88fbf067d5184d19ff4c7b99536b0d7a5c59c..2b2f3b43b45cc6205b00bc1b006c4f6b6c2d65ea 100644 (file)
@@ -151,6 +151,7 @@ public class ListBitbucketServerProjectsActionTest {
 
     assertThat(def.since()).isEqualTo("8.2");
     assertThat(def.isPost()).isFalse();
+    assertThat(def.responseExampleFormat()).isEqualTo("json");
     assertThat(def.params())
       .extracting(WebService.Param::key, WebService.Param::isRequired)
       .containsExactlyInAnyOrder(tuple("almSetting", true));
index 00fb2634aa460785299f4f21def139b777409b03..3717cfd716729ddbb248cd4c7ecc0bbd3ed0a36d 100644 (file)
@@ -240,6 +240,7 @@ public class SearchBitbucketServerReposActionTest {
 
     assertThat(def.since()).isEqualTo("8.2");
     assertThat(def.isPost()).isFalse();
+    assertThat(def.responseExampleFormat()).isEqualTo("json");
     assertThat(def.params())
       .extracting(WebService.Param::key, WebService.Param::isRequired)
       .containsExactlyInAnyOrder(
index 8119cb08eb0f5fd0273013894003494e6d0ea21a..9639ff1da61579f11db7aef74de624474edcb4ab 100644 (file)
@@ -30,6 +30,7 @@ import org.sonar.alm.client.github.GithubApplicationClientImpl;
 import org.sonar.alm.client.github.security.UserAccessToken;
 import org.sonar.api.config.internal.Encryption;
 import org.sonar.api.config.internal.Settings;
+import org.sonar.api.server.ws.WebService;
 import org.sonar.api.utils.System2;
 import org.sonar.db.DbTester;
 import org.sonar.db.alm.pat.AlmPatDto;
@@ -258,6 +259,19 @@ public class ListGithubOrganizationsActionTest {
       .isEqualTo(pat.getPersonalAccessToken());
   }
 
+  @Test
+  public void definition() {
+    WebService.Action def = ws.getDef();
+
+    assertThat(def.since()).isEqualTo("8.4");
+    assertThat(def.isPost()).isFalse();
+    assertThat(def.isInternal()).isTrue();
+    assertThat(def.responseExampleFormat()).isEqualTo("json");
+    assertThat(def.params())
+      .extracting(WebService.Param::key, WebService.Param::isRequired)
+      .containsExactlyInAnyOrder(tuple("p", false), tuple("ps", false), tuple("almSetting", true), tuple("token", false));
+  }
+
   private void setupGhOrganizations(AlmSettingDto almSetting, String pat) {
     when(appClient.listOrganizations(eq(almSetting.getUrl()), argThat(token -> token.getValue().equals(pat)), eq(1), eq(100)))
       .thenReturn(new GithubApplicationClient.Organizations()
index 77398253609a27d7850e4d3f3badd80aad776146..f9f866ef065b921b6055d2921825c66c25f49893 100644 (file)
@@ -30,6 +30,7 @@ import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.sonar.api.config.Configuration;
+import org.sonar.api.server.ws.WebService;
 import org.sonar.api.utils.System2;
 import org.sonar.api.web.UserRole;
 import org.sonar.core.util.Slug;
@@ -49,6 +50,7 @@ import org.sonar.server.ws.WsActionTester;
 import static java.util.Comparator.reverseOrder;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.assertj.core.api.Assertions.tuple;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 import static org.sonar.api.resources.Qualifiers.PROJECT;
@@ -96,6 +98,23 @@ public class StatusActionTest {
     cleanUpFilesystem();
   }
 
+  @Test
+  public void definition() {
+    WebService.Action definition = underTest.getDef();
+
+    assertThat(definition.key()).isEqualTo("status");
+    assertThat(definition.isPost()).isFalse();
+    assertThat(definition.description()).isNotEmpty();
+    assertThat(definition.since()).isEqualTo("1.0");
+    assertThat(definition.isInternal()).isTrue();
+    assertThat(definition.responseExampleFormat()).isEqualTo("json");
+    assertThat(definition.params())
+      .extracting(WebService.Param::key, WebService.Param::isRequired)
+      .containsExactlyInAnyOrder(
+        tuple("id", false),
+        tuple("key", false));
+  }
+
   @Test
   public void fails_with_BRE_if_no_param_is_provided() {
     assertThatThrownBy(() -> underTest.newRequest().execute())