private static void validateMinimumLength(String key, WebService.Param definition, String valueOrDefault) { Integer minimumLength = definition.minimumLength(); if (minimumLength == null) { return; } int valueLength = valueOrDefault.length(); checkArgument(valueLength >= minimumLength, "'%s' length (%s) is shorter than the minimum authorized (%s)", key, valueLength, minimumLength); }
@Test public void definition() { WebService.Action action = ws.getDef(); assertThat(action.key()).isEqualTo("search_members"); assertThat(action.params()).extracting(Param::key).containsOnly("q", "selected", "p", "ps", "organization"); assertThat(action.description()).isNotEmpty(); assertThat(action.responseExampleAsString()).isNotEmpty(); assertThat(action.since()).isEqualTo("6.4"); assertThat(action.isInternal()).isTrue(); assertThat(action.isPost()).isFalse(); assertThat(action.param("organization").isInternal()).isTrue(); Param selected = action.param("selected"); assertThat(selected.possibleValues()).containsOnly("selected", "deselected"); assertThat(selected.isInternal()).isTrue(); assertThat(selected.defaultValue()).isEqualTo("selected"); assertThat(action.param("ps").maximumValue()).isEqualTo(500); assertThat(action.param("q").minimumLength()).isEqualTo(2); }
private static void writeParam(JsonWriter writer, WebService.Param param) { writer.beginObject(); writer.prop("key", param.key()); writer.prop("description", param.description()); writer.prop("since", param.since()); writer.prop("required", param.isRequired()); writer.prop("internal", param.isInternal()); writer.prop("defaultValue", param.defaultValue()); writer.prop("exampleValue", param.exampleValue()); writer.prop("deprecatedSince", param.deprecatedSince()); writer.prop("deprecatedKey", param.deprecatedKey()); writer.prop("deprecatedKeySince", param.deprecatedKeySince()); writer.prop("maxValuesAllowed", param.maxValuesAllowed()); ofNullable(param.possibleValues()).ifPresent(possibleValues -> writer.name("possibleValues").beginArray().values(possibleValues).endArray()); ofNullable(param.maximumLength()).ifPresent(maximumLength -> writer.prop("maximumLength", maximumLength)); ofNullable(param.minimumLength()).ifPresent(minimumLength -> writer.prop("minimumLength", minimumLength)); ofNullable(param.maximumValue()).ifPresent(maximumValue -> writer.prop("maximumValue", maximumValue)); writer.endObject(); }
private static void writeParam(JsonWriter writer, WebService.Param param) { writer.beginObject(); writer.prop("key", param.key()); writer.prop("description", param.description()); writer.prop("since", param.since()); writer.prop("required", param.isRequired()); writer.prop("internal", param.isInternal()); writer.prop("defaultValue", param.defaultValue()); writer.prop("exampleValue", param.exampleValue()); writer.prop("deprecatedSince", param.deprecatedSince()); writer.prop("deprecatedKey", param.deprecatedKey()); writer.prop("deprecatedKeySince", param.deprecatedKeySince()); writer.prop("maxValuesAllowed", param.maxValuesAllowed()); ofNullable(param.possibleValues()).ifPresent(possibleValues -> writer.name("possibleValues").beginArray().values(possibleValues).endArray()); ofNullable(param.maximumLength()).ifPresent(maximumLength -> writer.prop("maximumLength", maximumLength)); ofNullable(param.minimumLength()).ifPresent(minimumLength -> writer.prop("minimumLength", minimumLength)); ofNullable(param.maximumValue()).ifPresent(maximumValue -> writer.prop("maximumValue", maximumValue)); writer.endObject(); }
private static void validateMinimumLength(String key, WebService.Param definition, String valueOrDefault) { Integer minimumLength = definition.minimumLength(); if (minimumLength == null) { return; } int valueLength = valueOrDefault.length(); checkArgument(valueLength >= minimumLength, "'%s' length (%s) is shorter than the minimum authorized (%s)", key, valueLength, minimumLength); }
.matches(param -> !param.isRequired()) .matches(param -> "Foo Company".equals(param.exampleValue())) .matches(param -> param.minimumLength().equals(1)) .matches(param -> param.maximumLength().equals(255)) .matches(param -> param.description() != null);
.matches(WebService.Param::isRequired) .matches(param -> "Foo Company".equals(param.exampleValue())) .matches(param -> param.minimumLength().equals(1)) .matches(param -> param.maximumLength().equals(255)) .matches(param -> param.description() != null); .matches(param -> !param.isRequired()) .matches(param -> "foo-company".equals(param.exampleValue())) .matches(param -> param.minimumLength().equals(1)) .matches(param -> param.maximumLength().equals(255)) .matches(param -> param.description() != null);
@Test public void param_with_minimum_length() { ((WebService) context -> { NewController newController = context.createController("api/custom_measures"); NewAction create = newDefaultAction(newController, "create"); create.createParam("string_value") .setMinimumLength(3); newController.done(); }).define(context); WebService.Action action = context.controller("api/custom_measures").action("create"); assertThat(action.param("string_value").minimumLength()).isEqualTo(3); }