本文整理汇总了Java中io.swagger.models.parameters.SerializableParameter类的典型用法代码示例。如果您正苦于以下问题:Java SerializableParameter类的具体用法?Java SerializableParameter怎么用?Java SerializableParameter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SerializableParameter类属于io.swagger.models.parameters包,在下文中一共展示了SerializableParameter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getValidator
import io.swagger.models.parameters.SerializableParameter; //导入依赖的package包/类
protected PrimitiveValidator<?> getValidator(Class<?> keyClass, SerializableParameter param) {
PrimitiveValidator<?> validator;
if (Number.class.isAssignableFrom(keyClass)) {
NumberValidator numVal = new NumberValidator();
numVal.setMax(param.getMaximum());
numVal.setMin(param.getMinimum());
validator = numVal;
}
else {
StringValidator stringVal = new StringValidator();
stringVal.setMinLength(param.getMinLength());
stringVal.setMaxLength(param.getMaxLength());
validator = stringVal;
}
validator.setAllowableValues(param.getEnum());
return validator;
}
示例2: validate
import io.swagger.models.parameters.SerializableParameter; //导入依赖的package包/类
@Override
public Status validate(final String value, final Parameter p) {
if (!supports(p)) {
return null;
}
final SerializableParameter parameter = (SerializableParameter)p;
if (parameter.getRequired() && (value == null || value.trim().isEmpty())) {
return new Status("ERR11001", parameter.getName());
}
if (value == null || value.trim().isEmpty()) {
return null;
}
return doValidate(value, parameter);
}
示例3: validate
import io.swagger.models.parameters.SerializableParameter; //导入依赖的package包/类
public Status validate(final String value, final Parameter parameter) {
requireNonNull(parameter);
if ((parameter instanceof SerializableParameter) &&
((SerializableParameter)parameter).getType().equalsIgnoreCase("array")) {
return arrayValidator.validate(value, parameter);
}
Optional<Status> optional = validators.stream()
.filter(v -> v.supports(parameter))
.map(v -> v.validate(value, parameter))
.filter(s -> s != null)
.findFirst();
if(optional.isPresent()) {
return optional.get();
} else {
return null;
}
}
示例4: validate
import io.swagger.models.parameters.SerializableParameter; //导入依赖的package包/类
@Override
public Status validate(final String value, final Parameter p) {
if (!supports(p)) {
return null;
}
final SerializableParameter parameter = (SerializableParameter)p;
if (parameter.getRequired() && (value == null || value.trim().isEmpty())) {
return new Status("ERR11001", p.getName());
}
if (value == null || value.trim().isEmpty()) {
return null;
}
if (!matchesEnumIfDefined(value, parameter)) {
return new Status("ERR11002", value, parameter.getName(), parameter.getEnum());
}
return doValidate(value, parameter);
}
示例5: arrayParam
import io.swagger.models.parameters.SerializableParameter; //导入依赖的package包/类
public static SerializableParameter arrayParam(final boolean required,
final String collectionFormat,
final Integer minItems,
final Integer maxItems,
final Boolean unique,
final Property items) {
final SerializableParameter result = mock(SerializableParameter.class);
when(result.getName()).thenReturn("Test Parameter");
when(result.getType()).thenReturn("array");
when(result.getCollectionFormat()).thenReturn(collectionFormat);
when(result.getRequired()).thenReturn(required);
when(result.getMinItems()).thenReturn(minItems);
when(result.getMaxItems()).thenReturn(maxItems);
when(result.isUniqueItems()).thenReturn(unique);
when(result.getItems()).thenReturn(items);
return result;
}
示例6: getArrayRegex
import io.swagger.models.parameters.SerializableParameter; //导入依赖的package包/类
private String getArrayRegex(SerializableParameter param) {
String regex;
if (param.getCollectionFormat() == null) {
regex = Pattern.quote(",");
} else {
switch (param.getCollectionFormat()) {
case "ssv":
regex = Pattern.quote(" ");
break;
case "csv":
regex = Pattern.quote(",");
break;
case "tsv":
regex = Pattern.quote("\t");
break;
case "pipes":
regex = Pattern.quote("|");
break;
default:
regex = Pattern.quote(",");
break;
}
}
return regex;
}
示例7: testArrayMulti
import io.swagger.models.parameters.SerializableParameter; //导入依赖的package包/类
@Test()
public void testArrayMulti() {
String name = "myName";
SerializableParameter parameter = new QueryParameter();
parameter.setName("myName");
parameter.setType("array");
parameter.setCollectionFormat("multi");
List<String> paramsList = new ArrayList<>();
paramsList.add("toto");
paramsList.add("tutu");
paramsList.add("titi");
MultiMap params = MultiMap.caseInsensitiveMultiMap();
params.add(name, paramsList);
Object result = abstractSerializableParameterExtractor.extract(name, parameter, params);
Assert.assertArrayEquals(paramsList.toArray(), ((List) result).toArray());
}
示例8: complement
import io.swagger.models.parameters.SerializableParameter; //导入依赖的package包/类
private SerializableParameter complement(Property property, RouteParameter source,
SerializableParameter param) {
param.setType(property.getType());
param.setFormat(property.getFormat());
// array param:
if (property instanceof ArrayProperty) {
param.setItems(((ArrayProperty) property).getItems());
}
// enum values:
List<String> enums = source.enums();
if (enums.size() > 0) {
param.setEnum(enums);
}
// default value:
if (param instanceof AbstractSerializableParameter) {
((AbstractSerializableParameter) param).setDefault(source.defaultValue());
}
return param;
}
示例9: extractParameters
import io.swagger.models.parameters.SerializableParameter; //导入依赖的package包/类
@Override
public List<Parameter> extractParameters(List<Annotation> annotations, Type type, Set<Type> typesToSkip, Iterator<SwaggerExtension> chain) {
if (this.shouldIgnoreType(type, typesToSkip)) {
return new ArrayList<Parameter>();
}
List<Parameter> parameters = new ArrayList<Parameter>();
SerializableParameter parameter = null;
for (Annotation annotation : annotations) {
parameter = getParameter(type, parameter, annotation);
}
if (parameter != null) {
parameters.add(parameter);
}
return parameters;
}
示例10: javaTypeFor
import io.swagger.models.parameters.SerializableParameter; //导入依赖的package包/类
static String javaTypeFor(final SerializableParameter parameter) {
final String type = parameter.getType();
if ("array".equals(type)) {
final Property items = parameter.getItems();
final String elementType = items.getType();
final String elementFormat = items.getFormat();
return javaTypeFor(elementType, elementFormat) + "[]";
}
final String format = parameter.getFormat();
return javaTypeFor(type, format);
}
示例11: doValidate
import io.swagger.models.parameters.SerializableParameter; //导入依赖的package包/类
@Override
protected Status doValidate(
final String value,
final SerializableParameter parameter) {
// TODO: Check pattern etc.
return null;
}
示例12: doValidate
import io.swagger.models.parameters.SerializableParameter; //导入依赖的package包/类
private Status doValidate(final Collection<String> values,
final SerializableParameter parameter) {
if (parameter.getMaxItems() != null && values.size() > parameter.getMaxItems()) {
return new Status("ERR11006", parameter.getName(), parameter.getMaxItems(), values.size());
}
if (parameter.getMinItems() != null && values.size() < parameter.getMinItems()) {
return new Status("ERR11007", parameter.getName(), parameter.getMinItems(), values.size());
}
if (Boolean.TRUE.equals(parameter.isUniqueItems()) &&
values.stream().distinct().count() != values.size()) {
return new Status("ERR11008", parameter.getName());
}
if (parameter.getEnum() != null && !parameter.getEnum().isEmpty()) {
final Set<String> enumValues = new HashSet<>(parameter.getEnum());
Optional<String> value =
values.stream()
.filter(v -> !enumValues.contains(v))
.findFirst();
if(value.isPresent()) {
return new Status("ERR11009", value.get(), parameter.getName(), parameter.getEnum());
}
}
Optional<Status> optional =
values.stream()
.map(v -> schemaValidator.validate(v, parameter.getItems()))
.filter(s -> s != null)
.findFirst();
if(optional.isPresent()) {
return optional.get();
} else {
return null;
}
}
示例13: intParam
import io.swagger.models.parameters.SerializableParameter; //导入依赖的package包/类
public static SerializableParameter intParam(final boolean required, final BigDecimal min, final BigDecimal max) {
final SerializableParameter result = mock(SerializableParameter.class);
when(result.getName()).thenReturn("Test Parameter");
when(result.getType()).thenReturn("integer");
when(result.getFormat()).thenReturn("int32");
when(result.getRequired()).thenReturn(required);
when(result.getMinimum()).thenReturn(min);
when(result.getMaximum()).thenReturn(max);
return result;
}
示例14: stringParam
import io.swagger.models.parameters.SerializableParameter; //导入依赖的package包/类
public static SerializableParameter stringParam(final boolean required) {
final SerializableParameter result = mock(SerializableParameter.class);
when(result.getName()).thenReturn("Test Parameter");
when(result.getType()).thenReturn("string");
when(result.getRequired()).thenReturn(required);
when(result.getMinimum()).thenReturn(null);
when(result.getMaximum()).thenReturn(null);
return result;
}
示例15: floatParam
import io.swagger.models.parameters.SerializableParameter; //导入依赖的package包/类
public static SerializableParameter floatParam(final boolean required, final BigDecimal min, final BigDecimal max) {
final SerializableParameter result = mock(SerializableParameter.class);
when(result.getName()).thenReturn("Test Parameter");
when(result.getType()).thenReturn("number");
when(result.getFormat()).thenReturn("float");
when(result.getRequired()).thenReturn(required);
when(result.getMinimum()).thenReturn(min);
when(result.getMaximum()).thenReturn(max);
return result;
}