/** * Exhaustive list of possible values when it makes sense, for example * list of severities. * * @since 4.4 * @see Param#possibleValues() */ public <T> NewParam setPossibleValues(@Nullable T... values) { return setPossibleValues(values == null ? Collections.emptyList() : asList(values)); }
@Override public void define(WebService.NewController controller) { NewAction action = controller.createAction("measure") .setHandler(this) .setDescription("Generate badge for project's measure as an SVG.<br/>" + "Requires 'Browse' permission on the specified project.") .setSince("7.1") .setResponseExample(Resources.getResource(getClass(), "measure-example.svg")); support.addProjectAndBranchParams(action); action.createParam(PARAM_METRIC) .setDescription("Metric key") .setRequired(true) .setPossibleValues(METRIC_NAME_BY_KEY.keySet()); }
@Override public void define(WebService.NewController context) { WebService.NewAction action = context.createAction("installed_plugins") .setDescription("Get the list of all the plugins installed on the SonarQube instance") .setSince("2.10") .setDeprecatedSince("6.3") .setInternal(true) .setResponseExample(getClass().getResource("installed_plugins-example.json")) .setHandler(this); action.createParam("format") .setDescription("Only json response format is available") .setPossibleValues("json"); }
public void define(WebService.NewController context) { WebService.NewAction action = context.createAction(ProjectsWsParameters.ACTION_UPDATE_VISIBILITY) .setDescription("Updates visibility of a project.<br>" + "Requires 'Project administer' permission on the specified project") .setSince("6.4") .setPost(true) .setHandler(this); action.createParam(PARAM_PROJECT) .setDescription("Project key") .setExampleValue(KEY_PROJECT_EXAMPLE_001) .setRequired(true); action.createParam(PARAM_VISIBILITY) .setDescription("New visibility") .setPossibleValues(Visibility.getLabels()) .setRequired(true); }
public static void defineParams(WebService.NewAction action, Languages languages) { action.createParam(PARAM_KEY) .setDescription("Quality profile key") .setDeprecatedKey("profileKey", "6.5") .setDeprecatedSince("6.6") .setExampleValue(UUID_EXAMPLE_01); action.createParam(PARAM_QUALITY_PROFILE) .setDescription("Quality profile name") .setDeprecatedKey("profileName", "6.6") .setExampleValue("Sonar way"); action.createParam(PARAM_LANGUAGE) .setDescription("Quality profile language") .setPossibleValues(Arrays.stream(languages.all()).map(Language::getKey).collect(MoreCollectors.toSet())); } }
@Override public void define(WebService.NewController context) { WebService.NewAction action = context.createAction(ACTION) .setPost(true) .setDescription("Update the default visibility for new projects.<br/>Requires System Administrator privileges") .setChangelog( new Change("7.3", "This WS used to be located at /api/organizations/update_project_visibility")) .setInternal(true) .setSince("6.4") .setHandler(this); action.createParam(PARAM_PROJECT_VISIBILITY) .setRequired(true) .setDescription("Default visibility for projects") .setPossibleValues(Visibility.getLabels()); }
/** * Add predefined parameters related to sorting of results. */ public <V> NewParam createSortParams(Collection<V> possibleValues, @Nullable V defaultValue, boolean defaultAscending) { createParam(Param.ASCENDING) .setDescription("Ascending sort") .setBooleanPossibleValues() .setDefaultValue(defaultAscending); return createParam(Param.SORT) .setDescription("Sort field") .setDeprecatedKey("sort", "5.4") .setDefaultValue(defaultValue) .setPossibleValues(possibleValues); }
@Override public void define(WebService.NewController controller) { WebService.NewAction newAction = controller.createAction("change_log_level") .setDescription("Temporarily changes level of logs. New level is not persistent and is lost " + "when restarting server. Requires system administration permission.") .setSince("5.2") .setPost(true) .setHandler(this); newAction.createParam(PARAM_LEVEL) .setDescription("The new level. Be cautious: DEBUG, and even more TRACE, may have performance impacts.") .setPossibleValues(allowedLogLevels()) .setRequired(true); }
@Test public void param_with_empty_possible_values() { ((WebService) context -> { NewController newController = context.createController("api/rule"); NewAction create = newDefaultAction(newController, "create"); create.createParam("status") .setPossibleValues(Collections.emptyList()); newController.done(); }).define(context); WebService.Action action = context.controller("api/rule").action("create"); // no possible values -> return null but not empty assertThat(action.param("status").possibleValues()).isNull(); }
public static WebService.NewParam createQualifiersParameter(WebService.NewAction action, QualifierParameterContext context) { return action.createParam(PARAM_QUALIFIERS) .setDescription( "Comma-separated list of component qualifiers. Filter the results with the specified qualifiers. Possible values are:" + buildAllQualifiersDescription(context)) .setPossibleValues(getAllQualifiers(context.getResourceTypes())); }
public static WebService.NewParam createRootQualifiersParameter(WebService.NewAction action, QualifierParameterContext context) { return action.createParam(PARAM_QUALIFIERS) .setDescription("Comma-separated list of component qualifiers. Filter the results with the specified qualifiers. " + "Possible values are:" + buildRootQualifiersDescription(context)) .setPossibleValues(getRootQualifiers(context.getResourceTypes())); }
public WebService.NewParam createProjectPermissionParameter(WebService.NewAction action, boolean required) { return action.createParam(PARAM_PERMISSION) .setDescription(projectPermissionParamDescription) .setPossibleValues(permissionService.getAllProjectPermissions()) .setRequired(required); }
@Test public void fail_if_parameter_value_is_not_in_defined_possible_values() { Request request = new TestRequest().setPath("api/foo").setParam("format", "yml"); DumbResponse response = run(request, newWs("api/foo", a -> { a.createParam("format").setPossibleValues("json", "xml"); a.setHandler((req, resp) -> resp.stream().output().write(req.mandatoryParam("format").getBytes(UTF_8))); })); assertThat(response.stream().outputAsString()).isEqualTo("{\"errors\":[{\"msg\":\"Value of parameter 'format' (yml) must be one of: [json, xml]\"}]}"); assertThat(response.stream().status()).isEqualTo(400); }
@Test public void accept_parameter_value_within_defined_possible_values() { Request request = new TestRequest().setPath("api/foo").setParam("format", "json"); DumbResponse response = run(request, newWs("api/foo", a -> { a.createParam("format").setPossibleValues("json", "xml"); a.setHandler((req, resp) -> resp.stream().output().write(req.mandatoryParam("format").getBytes(UTF_8))); })); assertThat(response.stream().outputAsString()).isEqualTo("json"); assertThat(response.stream().status()).isEqualTo(200); }
public static WebService.NewParam createRootQualifierParameter(WebService.NewAction action, QualifierParameterContext context) { return action.createParam(PARAM_QUALIFIER) .setDescription("Project qualifier. Filter the results with the specified qualifier. Possible values are:" + buildRootQualifiersDescription(context)) .setPossibleValues(getRootQualifiers(context.getResourceTypes())); }
static NewParam createAdditionalFieldsParameter(NewAction action) { return action.createParam(PARAM_ADDITIONAL_FIELDS) .setDescription("Comma-separated list of additional fields that can be returned in the response.") .setPossibleValues(ADDITIONAL_FIELDS) .setExampleValue("periods,metrics"); }
public static WebService.NewParam createDefaultTemplateQualifierParameter(WebService.NewAction action, QualifierParameterContext context) { return action.createParam(PARAM_QUALIFIER) .setDescription("Project qualifier. Filter the results with the specified qualifier. Possible values are:" + buildDefaultTemplateQualifiersDescription(context)) .setPossibleValues(getDefaultTemplateQualifiers(context.getResourceTypes())); }
/** * Add 'selected=(selected|deselected|all)' for select-list oriented WS. */ public NewAction addSelectionModeParam() { createParam(Param.SELECTED) .setDescription("Depending on the value, show only selected items (selected=selected), deselected items (selected=deselected), " + "or all items with their selection status (selected=all).") .setDefaultValue(SelectionMode.SELECTED.value()) .setPossibleValues(SelectionMode.possibleValues()); return this; } }
public NewParam createFieldsParam(Collection<?> possibleValues) { return createParam(Param.FIELDS) .setDescription("Comma-separated list of the fields to be returned in response. All the fields are returned by default.") .setPossibleValues(possibleValues); }
/** * Shortcut for {@code setPossibleValues("true", "false", "yes", "no")} * @since 4.4 */ public NewParam setBooleanPossibleValues() { return setPossibleValues("true", "false", "yes", "no"); }