io.swagger.models.properties.PropertyBuilder Java Examples

The following examples show how to use io.swagger.models.properties.PropertyBuilder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RpcReaderExtension.java    From sofa-rpc with Apache License 2.0 6 votes vote down vote up
private Parameter readParam(Swagger swagger, Type type, Class<?> cls, ApiParam param) {
    PrimitiveType fromType = PrimitiveType.fromType(type);
    final Parameter para = null == fromType ? new BodyParameter() : new QueryParameter();
    Parameter parameter = ParameterProcessor.applyAnnotations(swagger, para, 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() || cls.isPrimitive());
    } else {
        //hack: Get the from data model paramter from BodyParameter
        BodyParameter bp = (BodyParameter) parameter;
        bp.setIn("body");
        Property property = ModelConverters.getInstance().readAsProperty(type);
        final Map<PropertyBuilder.PropertyId, Object> args = new EnumMap<PropertyBuilder.PropertyId, Object>(
            PropertyBuilder.PropertyId.class);
        bp.setSchema(PropertyBuilder.toModel(PropertyBuilder.merge(property, args)));
    }
    return parameter;
}
 
Example #2
Source File: ParameterProcessor.java    From netty-rest with Apache License 2.0 6 votes vote down vote up
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);
        }
    }
}