From 955277e81bbf7aae38ad587a5b478edfb4f05f8a Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Sun, 16 Oct 2016 19:18:38 +0200 Subject: SONAR-8291 add NewParam#setInternal(boolean) to API --- .../java/org/sonar/api/server/ws/WebService.java | 33 ++++++++++++++++++++++ .../org/sonar/api/server/ws/WebServiceTest.java | 8 +++++- 2 files changed, 40 insertions(+), 1 deletion(-) (limited to 'sonar-plugin-api') 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 { 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 { return post; } + /** + * @see NewAction#setInternal(boolean) + */ public boolean isInternal() { return isInternal; } @@ -598,6 +606,7 @@ public interface WebService extends Definable { private String exampleValue; private String defaultValue; private boolean required = false; + private boolean internal = false; private Set possibleValues = null; private NewParam(String key) { @@ -651,6 +660,18 @@ public interface WebService extends Definable { return this; } + /** + * 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 */ @@ -752,6 +773,7 @@ public interface WebService extends Definable { private final String exampleValue; private final String defaultValue; private final boolean required; + private final boolean internal; private final Set possibleValues; protected Param(Action action, NewParam newParam) { @@ -763,6 +785,7 @@ public interface WebService extends Definable { 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)); @@ -819,6 +842,16 @@ public interface WebService extends Definable { return required; } + /** + * Is the parameter internal ? + * + * @since 6.2 + * @see NewParam#setInternal(boolean) + */ + public boolean isInternal() { + return internal; + } + /** * @since 4.4 */ 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(); -- cgit v1.2.3