当前位置: 首页>>代码示例>>Java>>正文


Java AbstractSerializableParameter类代码示例

本文整理汇总了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);
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:21,代码来源:ParamUtils.java

示例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();
}
 
开发者ID:energizedwork,项目名称:swagger-http-validator,代码行数:30,代码来源:StringParameterValidator.java

示例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);
        }
    }
}
 
开发者ID:buremba,项目名称:netty-rest,代码行数:23,代码来源:ParameterProcessor.java

示例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);
}
 
开发者ID:buremba,项目名称:swagger-slate,代码行数:21,代码来源:ParameterUtils.java

示例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 "";
    }
}
 
开发者ID:buremba,项目名称:swagger-slate,代码行数:23,代码来源:SlateDocumentGenerator.java

示例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;
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:20,代码来源:SwaggerBuilder.java

示例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;
}
 
开发者ID:Sayi,项目名称:swagger-dubbo,代码行数:14,代码来源:DubboReaderExtension.java

示例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);
}
 
开发者ID:phiz71,项目名称:vertx-swagger,代码行数:34,代码来源:AbstractSerializableParameterExtractor.java

示例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();
}
 
开发者ID:energizedwork,项目名称:swagger-http-validator,代码行数:14,代码来源:BaseDateParameterValidator.java

示例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();
}
 
开发者ID:energizedwork,项目名称:swagger-http-validator,代码行数:16,代码来源:NumberParameterValidator.java

示例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();
}
 
开发者ID:energizedwork,项目名称:swagger-http-validator,代码行数:36,代码来源:NumberParameterValidator.java

示例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();
}
 
开发者ID:energizedwork,项目名称:swagger-http-validator,代码行数:10,代码来源:BaseParameterValidator.java

示例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();
}
 
开发者ID:energizedwork,项目名称:swagger-http-validator,代码行数:10,代码来源:BaseParameterValidator.java

示例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();
}
 
开发者ID:energizedwork,项目名称:swagger-http-validator,代码行数:11,代码来源:BooleanParameterValidator.java


注:本文中的io.swagger.models.parameters.AbstractSerializableParameter类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。