Java源码示例:io.swagger.models.properties.AbstractNumericProperty

示例1
private Object valueOfProperty(Map<String, Model> definitions, Property prop, Set<String> keyCache) {
    Object value;
    if (prop instanceof RefProperty) {
        String ref = ((RefProperty) prop).get$ref().substring("#/definitions/".length());
        if (keyCache.contains(ref)) value = ((RefProperty) prop).get$ref();
        else value = valueOfModel(definitions, definitions.get(ref), keyCache);
    } else if (prop instanceof ArrayProperty) {
        List<Object> list = new ArrayList<>();
        Property insideItems = ((ArrayProperty) prop).getItems();
        list.add(valueOfProperty(definitions, insideItems, keyCache));
        value = list;
    } else if (prop instanceof AbstractNumericProperty) {
        value = 0;
    } else if (prop instanceof BooleanProperty) {
        value = false;
    } else {
        value = prop.getType();
    }
    return value;
}
 
示例2
protected void applyNumberAnnotationDetails(AbstractNumericProperty schema, Annotation annotation) {
	if (annotation instanceof DecimalMin) {
		schema.setMinimum(new BigDecimal(((DecimalMin) annotation).value()));
	} else if (annotation instanceof DecimalMax) {
		schema.setMaximum(new BigDecimal(((DecimalMax) annotation).value()));
	} else if (annotation instanceof Min) {
		schema.setMinimum(BigDecimal.valueOf(((Min) annotation).value()));
	} else if (annotation instanceof Max) {
		schema.setMaximum(BigDecimal.valueOf(((Max) annotation).value()));
	} else if (annotation instanceof Deprecated) {
		schema.setVendorExtension("x-deprecated", true);
	}
}
 
示例3
/**
* Get the example string value for the given Property.
*
* If an example value was not provided in the specification, a default will be generated.
*
* @param property Property to get example string for
*
* @return Example String
*/
protected String getExample(Property property) {
    if (property.getExample() != null) {
        return property.getExample().toString();
    } else if (property instanceof DateTimeProperty) {
        return "2000-01-23T04:56:07.000Z";
    } else if (property instanceof DateProperty) {
        return "2000-01-23";
    } else if (property instanceof BooleanProperty) {
        return "true";
    } else if (property instanceof LongProperty) {
        return "123456789";
    } else if (property instanceof DoubleProperty) { // derived from DecimalProperty so make sure this is first
        return "3.149";
    }  else if (property instanceof DecimalProperty) {
        return "1.3579";
    } else if (property instanceof PasswordProperty) {
        return "********";
    } else if (property instanceof UUIDProperty) {
        return "046b6c7f-0b8a-43b9-b35d-6489e6daee91";
    // do these last in case the specific types above are derived from these classes
    } else if (property instanceof StringProperty) {
        return "aeiou";
    } else if (property instanceof BaseIntegerProperty) {
        return "123";
    } else if (property instanceof AbstractNumericProperty) {
        return "1.23";
    }
    LOGGER.warn("default example value not implemented for " + property);
    return "";
}
 
示例4
/**
 * Retrieves the minimum value of a property
 *
 * @return the minimum value of the property
 */
public Optional<BigDecimal> getMin() {
    if (property instanceof BaseIntegerProperty) {
        BaseIntegerProperty integerProperty = (BaseIntegerProperty) property;
        return Optional.ofNullable(integerProperty.getMinimum() != null ? integerProperty.getMinimum() : null);
    } else if (property instanceof AbstractNumericProperty) {
        AbstractNumericProperty numericProperty = (AbstractNumericProperty) property;
        return Optional.ofNullable(numericProperty.getMinimum());
    }
    return Optional.empty();
}
 
示例5
/**
 * Retrieves the exclusiveMinimum value of a property
 *
 * @return the exclusiveMinimum value of the property
 */
public boolean getExclusiveMin() {
    if (property instanceof AbstractNumericProperty) {
        AbstractNumericProperty numericProperty = (AbstractNumericProperty) property;
        return BooleanUtils.isTrue(numericProperty.getExclusiveMinimum());
    }
    return false;
}
 
示例6
/**
 * Retrieves the minimum value of a property
 *
 * @return the minimum value of the property
 */
public Optional<BigDecimal> getMax() {
    if (property instanceof BaseIntegerProperty) {
        BaseIntegerProperty integerProperty = (BaseIntegerProperty) property;
        return Optional.ofNullable(integerProperty.getMaximum() != null ? integerProperty.getMaximum() : null);
    } else if (property instanceof AbstractNumericProperty) {
        AbstractNumericProperty numericProperty = (AbstractNumericProperty) property;
        return Optional.ofNullable(numericProperty.getMaximum());
    }
    return Optional.empty();
}
 
示例7
/**
 * Retrieves the exclusiveMaximum value of a property
 *
 * @return the exclusiveMaximum value of the property
 */
public boolean getExclusiveMax() {
    if (property instanceof AbstractNumericProperty) {
        AbstractNumericProperty numericProperty = (AbstractNumericProperty) property;
        return BooleanUtils.isTrue((numericProperty.getExclusiveMaximum()));
    }
    return false;
}
 
示例8
protected Property createNumberSchema(AbstractNumericProperty property, Annotation[] annotations) {
	asList(annotations).forEach(annotation -> applyNumberAnnotationDetails(property, annotation));
	return property;
}