本文整理汇总了Java中io.swagger.models.parameters.AbstractSerializableParameter类的典型用法代码示例。如果您正苦于以下问题:Java AbstractSerializableParameter类的具体用法?Java AbstractSerializableParameter怎么用?Java AbstractSerializableParameter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AbstractSerializableParameter类属于io.swagger.models.parameters包,在下文中一共展示了AbstractSerializableParameter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setParameterType
import io.swagger.models.parameters.AbstractSerializableParameter; //导入依赖的package包/类
public static void setParameterType(Swagger swagger, Method method, int paramIdx,
AbstractSerializableParameter<?> parameter) {
Type paramType = ParamUtils.getGenericParameterType(method, paramIdx);
ParamUtils.addDefinitions(swagger, paramType);
Property property = ModelConverters.getInstance().readAsProperty(paramType);
if (isComplexProperty(property)) {
// 简单参数不可以是复杂类型
String msg = String.format("not allow complex type for %s parameter, method=%s:%s, paramIdx=%d, type=%s",
parameter.getIn(),
method.getDeclaringClass().getName(),
method.getName(),
paramIdx,
paramType.getTypeName());
throw new Error(msg);
}
parameter.setProperty(property);
}
示例2: convert
import io.swagger.models.parameters.AbstractSerializableParameter; //导入依赖的package包/类
@Override
public JavaType convert(ClassLoader classLoader, String packageName, Swagger swagger, Object def) {
AbstractSerializableParameter<?> param = (AbstractSerializableParameter<?>) def;
switch (param.getType()) {
case ArrayProperty.TYPE:
return ArrayPropertyConverter.findJavaType(classLoader,
packageName,
swagger,
param.getItems(),
param.isUniqueItems());
case StringProperty.TYPE:
return StringPropertyConverter.findJavaType(classLoader,
packageName,
swagger,
param.getType(),
param.getFormat(),
param.getEnum());
default:
return ConverterMgr.findJavaType(param.getType(), param.getFormat());
}
}
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:23,代码来源:AbstractSerializableParameterConverter.java
示例3: validate
import io.swagger.models.parameters.AbstractSerializableParameter; //导入依赖的package包/类
@Override
public <T extends AbstractSerializableParameter<T>> List<ValidationError> validate(AbstractSerializableParameter<T> parameterDef, String value) {
ImmutableList.Builder<ValidationError> errorsBuilder = ImmutableList.builder();
ParameterSource parameterSource = ParameterSource.valueOf(parameterDef.getIn());
String key = parameterDef.getName();
if (parameterDef.getPattern() != null && !value.matches(parameterDef.getPattern())) {
errorsBuilder.add(new ValidationError(parameterSource,
key,
Messages.validationMessage("err.common.pattern.noMatch", parameterDef.getPattern(), value))
);
}
if (parameterDef.getMinLength() != null && value.length() < parameterDef.getMinLength()) {
errorsBuilder.add(new ValidationError(parameterSource,
key,
Messages.validationMessage("err.common.minLength.tooShort", value, value.length(), parameterDef.getMinLength()))
);
}
if (parameterDef.getMaxLength() != null && value.length() > parameterDef.getMaxLength()) {
errorsBuilder.add(new ValidationError(parameterSource,
key,
Messages.validationMessage("err.common.maxLength.tooLong", value, value.length(), parameterDef.getMaxLength()))
);
}
return errorsBuilder.build();
}
示例4: processAllowedValues
import io.swagger.models.parameters.AbstractSerializableParameter; //导入依赖的package包/类
private static void processAllowedValues(AllowableValues allowableValues, AbstractSerializableParameter<?> p) {
if (allowableValues == null) {
return;
}
Map<PropertyBuilder.PropertyId, Object> args = allowableValues.asPropertyArguments();
if (args.containsKey(PropertyBuilder.PropertyId.ENUM)) {
p.setEnum((List<String>) args.get(PropertyBuilder.PropertyId.ENUM));
} else {
if (args.containsKey(PropertyBuilder.PropertyId.MINIMUM)) {
p.setMinimum((BigDecimal) args.get(PropertyBuilder.PropertyId.MINIMUM));
}
if (args.containsKey(PropertyBuilder.PropertyId.MAXIMUM)) {
p.setMaximum((BigDecimal) args.get(PropertyBuilder.PropertyId.MAXIMUM));
}
if (args.containsKey(PropertyBuilder.PropertyId.EXCLUSIVE_MINIMUM)) {
p.setExclusiveMinimum((Boolean) args.get(PropertyBuilder.PropertyId.EXCLUSIVE_MINIMUM) ? true : null);
}
if (args.containsKey(PropertyBuilder.PropertyId.EXCLUSIVE_MAXIMUM)) {
p.setExclusiveMaximum((Boolean) args.get(PropertyBuilder.PropertyId.EXCLUSIVE_MAXIMUM) ? true : null);
}
}
}
示例5: getDefaultValue
import io.swagger.models.parameters.AbstractSerializableParameter; //导入依赖的package包/类
public static String getDefaultValue(Parameter parameter){
Validate.notNull(parameter, "property must not be null!");
String defaultValue = "";
if(parameter instanceof AbstractSerializableParameter){
AbstractSerializableParameter serializableParameter = (AbstractSerializableParameter)parameter;
defaultValue = serializableParameter.getDefaultValue();
if(defaultValue == null || defaultValue.isEmpty()) {
switch (serializableParameter.getType()) {
case "string":
return "\"str\"";
case "integer":
return "0";
default:
return "";
}
}
}
return StringUtils.defaultString(defaultValue);
}
示例6: getValue
import io.swagger.models.parameters.AbstractSerializableParameter; //导入依赖的package包/类
private String getValue(AbstractSerializableParameter value)
{
switch (value.getType()) {
case "date":
return "\"2015-01-20\"";
case "string":
return "\"str\"";
case "integer":
case "long":
return "0";
case "double":
return "0.0";
case "boolean":
return "false";
case "map":
return "{\"prop\": value}";
case "array":
return "[\n\t" + getValue(value.getItems()) + "\n]";
default:
return "";
}
}
示例7: complement
import io.swagger.models.parameters.AbstractSerializableParameter; //导入依赖的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;
}
示例8: readParam
import io.swagger.models.parameters.AbstractSerializableParameter; //导入依赖的package包/类
private Parameter readParam(Swagger swagger, Type type,Class<?> cls, ApiParam param) {
PrimitiveType fromType = PrimitiveType.fromType(type);
final Parameter para = null == fromType ? new FormParameter() : new QueryParameter();
Parameter parameter = ParameterProcessor.applyAnnotations(swagger, para,
type == null ? String.class : type, null == param ? new ArrayList<Annotation>()
: Collections.<Annotation> singletonList(param));
if (parameter instanceof AbstractSerializableParameter) {
final AbstractSerializableParameter<?> p = (AbstractSerializableParameter<?>) parameter;
if (p.getType() == null) p.setType(null == fromType ? "string" : fromType.getCommonName());
p.setRequired(p.getRequired() == true ? true : cls.isPrimitive());
}
return parameter;
}
示例9: extract
import io.swagger.models.parameters.AbstractSerializableParameter; //导入依赖的package包/类
public Object extract(String name, Parameter parameter, MultiMap params) {
AbstractSerializableParameter abstractSerializableParameter = (AbstractSerializableParameter) parameter;
if (!params.contains(name)) {
if (abstractSerializableParameter.getRequired()) {
throw new IllegalArgumentException("Missing required parameter: " + name);
} else if (abstractSerializableParameter.getDefaultValue()!=null){
return abstractSerializableParameter.getDefaultValue();
} else {
return null;
}
}
if ((abstractSerializableParameter.getAllowEmptyValue() == null
|| !abstractSerializableParameter.getAllowEmptyValue())
&& StringUtils.isEmpty(params.get(name))) {
throw new IllegalArgumentException(
"Empty value is not authorized for parameter: " + name);
}
if ("array".equals(abstractSerializableParameter.getType())) {
if ("multi".equals(abstractSerializableParameter.getCollectionFormat())) {
return params.getAll(name);
} else {
List<String> resultParams = this.splitArrayParam(abstractSerializableParameter,
params.get(name));
if (resultParams != null) {
return resultParams;
}
}
}
return params.get(name);
}
示例10: validateParam
import io.swagger.models.parameters.AbstractSerializableParameter; //导入依赖的package包/类
@Override
public <T extends AbstractSerializableParameter<T>> List<ValidationError> validateParam(AbstractSerializableParameter<?> parameterDef, String value) {
DateTimeFormatter dateFormatter = getFormatter();
try {
dateFormatter.parse(value);
} catch (DateTimeParseException e) {
return singletonList(
ValidationError.forParameter(parameterDef, Messages.validationMessage("err.format.invalidDate", value, getFormatString()))
);
}
return emptyList();
}
示例11: validate
import io.swagger.models.parameters.AbstractSerializableParameter; //导入依赖的package包/类
@Override
public <T extends AbstractSerializableParameter<T>> List<ValidationError> validate(AbstractSerializableParameter<T> parameterDef, String value) {
ImmutableList.Builder<ValidationError> errorsBuilder = ImmutableList.builder();
try {
N convertedValue = convert(value);
errorsBuilder.addAll(validateRange(parameterDef, convertedValue.doubleValue()));
} catch (NumberFormatException ce) {
errorsBuilder.add(
ValidationError.forParameter(parameterDef, "input string \"" + value + "\" is not a valid " + parameterDef.getFormat())
);
}
return errorsBuilder.build();
}
示例12: validateRange
import io.swagger.models.parameters.AbstractSerializableParameter; //导入依赖的package包/类
private <T extends AbstractSerializableParameter<T>> List<ValidationError> validateRange(AbstractSerializableParameter<T> parameterDef, double value) {
ImmutableList.Builder<ValidationError> errorsBuilder = ImmutableList.builder();
Double maximum = parameterDef.getMaximum();
boolean exclusiveMaximum = firstNonNull(parameterDef.isExclusiveMaximum(), false);
Double minimum = parameterDef.getMinimum();
boolean exclusiveMinimum = firstNonNull(parameterDef.isExclusiveMinimum(), false);
if (maximum != null) {
if (!exclusiveMaximum && value > maximum) {
errorsBuilder.add(ValidationError.forParameter(parameterDef,
validationMessage("err.common.maximum.notExclusive", maximum, value))
);
} else if (exclusiveMaximum && value >= maximum) {
errorsBuilder.add(ValidationError.forParameter(parameterDef,
validationMessage("err.common.maximum.tooLarge", maximum, value))
);
}
}
if (minimum != null) {
if (!exclusiveMinimum && value < minimum) {
errorsBuilder.add(ValidationError.forParameter(parameterDef,
validationMessage("err.common.minimum.notExclusive", minimum, value))
);
} else if (exclusiveMinimum && value <= minimum) {
errorsBuilder.add(ValidationError.forParameter(parameterDef,
validationMessage("err.common.minimum.tooSmall", minimum, value))
);
}
}
return errorsBuilder.build();
}
示例13: validateParam
import io.swagger.models.parameters.AbstractSerializableParameter; //导入依赖的package包/类
@Override
public <T extends AbstractSerializableParameter<T>> List<ValidationError> validateParam(AbstractSerializableParameter<?> parameterDef, String value) {
ImmutableList.Builder<ValidationError> errorsBuilder = ImmutableList.builder();
errorsBuilder.addAll(validateGenericRules(parameterDef, value));
errorsBuilder.addAll(validate(parameterDef, value));
return errorsBuilder.build();
}
示例14: validateGenericRules
import io.swagger.models.parameters.AbstractSerializableParameter; //导入依赖的package包/类
private <T extends AbstractSerializableParameter<T>> List<ValidationError> validateGenericRules(AbstractSerializableParameter<T> parameterDef, String value) {
if (parameterDef.getEnum() != null && !parameterDef.getEnum().contains(value)) {
return Collections.singletonList(
ValidationError.forParameter(parameterDef, Messages.validationMessage("err.common.enum.notInEnum", value, parameterDef.getEnum()))
);
}
return emptyList();
}
示例15: validate
import io.swagger.models.parameters.AbstractSerializableParameter; //导入依赖的package包/类
@Override
public <T extends AbstractSerializableParameter<T>> List<ValidationError> validate(AbstractSerializableParameter<T> parameterDef, String value) {
if (!value.equals("true") && !value.equals("false")) {
return Collections.singletonList(
ValidationError.forParameter(parameterDef, String.format("string \"%s\" is not a valid boolean", value))
);
}
return emptyList();
}