aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api
diff options
context:
space:
mode:
Diffstat (limited to 'sonar-plugin-api')
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/server/ws/WebService.java33
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/server/ws/WebServiceTest.java8
2 files changed, 40 insertions, 1 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/server/ws/WebService.java b/sonar-plugin-api/src/main/java/org/sonar/api/server/ws/WebService.java
index 8442951cf99..1c913271076 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/server/ws/WebService.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/server/ws/WebService.java
@@ -296,6 +296,11 @@ public interface WebService extends Definable<WebService.Context> {
return this;
}
+ /**
+ * Internal actions are not displayed by default in the web api documentation. They are
+ * displayed only when the check-box "Show Internal API" is selected. By default
+ * an action is not internal.
+ */
public NewAction setInternal(boolean b) {
this.isInternal = b;
return this;
@@ -532,6 +537,9 @@ public interface WebService extends Definable<WebService.Context> {
return post;
}
+ /**
+ * @see NewAction#setInternal(boolean)
+ */
public boolean isInternal() {
return isInternal;
}
@@ -598,6 +606,7 @@ public interface WebService extends Definable<WebService.Context> {
private String exampleValue;
private String defaultValue;
private boolean required = false;
+ private boolean internal = false;
private Set<String> possibleValues = null;
private NewParam(String key) {
@@ -652,6 +661,18 @@ public interface WebService extends Definable<WebService.Context> {
}
/**
+ * Internal parameters are not displayed by default in the web api documentation. They are
+ * displayed only when the check-box "Show Internal API" is selected. By default
+ * a parameter is not internal.
+ *
+ * @since 6.2
+ */
+ public NewParam setInternal(boolean b) {
+ this.internal = b;
+ return this;
+ }
+
+ /**
* @since 4.4
*/
public NewParam setExampleValue(@Nullable Object s) {
@@ -752,6 +773,7 @@ public interface WebService extends Definable<WebService.Context> {
private final String exampleValue;
private final String defaultValue;
private final boolean required;
+ private final boolean internal;
private final Set<String> possibleValues;
protected Param(Action action, NewParam newParam) {
@@ -763,6 +785,7 @@ public interface WebService extends Definable<WebService.Context> {
this.exampleValue = newParam.exampleValue;
this.defaultValue = newParam.defaultValue;
this.required = newParam.required;
+ this.internal = newParam.internal;
this.possibleValues = newParam.possibleValues;
if (required && defaultValue != null) {
throw new IllegalArgumentException(format("Default value must not be set on parameter '%s?%s' as it's marked as required", action, key));
@@ -820,6 +843,16 @@ public interface WebService extends Definable<WebService.Context> {
}
/**
+ * Is the parameter internal ?
+ *
+ * @since 6.2
+ * @see NewParam#setInternal(boolean)
+ */
+ public boolean isInternal() {
+ return internal;
+ }
+
+ /**
* @since 4.4
*/
@CheckForNull
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/server/ws/WebServiceTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/server/ws/WebServiceTest.java
index 21822e870de..a199896b1f4 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/server/ws/WebServiceTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/server/ws/WebServiceTest.java
@@ -223,6 +223,8 @@ public class WebServiceTest {
.setDeprecatedSince("5.3")
.setDeprecatedKey("old-severity")
.setPossibleValues("INFO", "MAJOR", "BLOCKER");
+ newAction.createParam("internal")
+ .setInternal(true);
newAction.addPagingParams(20);
newAction.addFieldsParam(Arrays.asList("name", "severity"));
newAction.addSortParams(Arrays.asList("name", "updatedAt", "severity"), "updatedAt", false);
@@ -231,11 +233,12 @@ public class WebServiceTest {
}.define(context);
WebService.Action action = context.controller("api/rule").action("create");
- assertThat(action.params()).hasSize(7);
+ assertThat(action.params()).hasSize(8);
WebService.Param keyParam = action.param("key");
assertThat(keyParam.key()).isEqualTo("key");
assertThat(keyParam.description()).isEqualTo("Key of the new rule");
+ assertThat(keyParam.isInternal()).isFalse();
assertThat(keyParam.toString()).isEqualTo("key");
WebService.Param severityParam = action.param("severity");
@@ -247,6 +250,9 @@ public class WebServiceTest {
assertThat(severityParam.defaultValue()).isEqualTo("MAJOR");
assertThat(severityParam.possibleValues()).containsOnly("INFO", "MAJOR", "BLOCKER");
+ WebService.Param internalParam = action.param("internal");
+ assertThat(internalParam.isInternal()).isTrue();
+
// predefined fields
assertThat(action.param("p").defaultValue()).isEqualTo("1");
assertThat(action.param("p").description()).isNotEmpty();