io.swagger.models.properties.AbstractNumericProperty Java Examples

The following examples show how to use io.swagger.models.properties.AbstractNumericProperty. 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: SwaggerToWordExample.java    From poi-tl with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #2
Source File: OpenApiTransformer.java    From spring-openapi with MIT License 5 votes vote down vote up
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);
	}
}
 
Example #3
Source File: XmlExampleGenerator.java    From TypeScript-Microservices with MIT License 5 votes vote down vote up
/**
* 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 "";
}
 
Example #4
Source File: PropertyAdapter.java    From swagger2markup with Apache License 2.0 5 votes vote down vote up
/**
 * 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();
}
 
Example #5
Source File: PropertyAdapter.java    From swagger2markup with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #6
Source File: PropertyAdapter.java    From swagger2markup with Apache License 2.0 5 votes vote down vote up
/**
 * 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();
}
 
Example #7
Source File: PropertyAdapter.java    From swagger2markup with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #8
Source File: OpenApiTransformer.java    From spring-openapi with MIT License 4 votes vote down vote up
protected Property createNumberSchema(AbstractNumericProperty property, Annotation[] annotations) {
	asList(annotations).forEach(annotation -> applyNumberAnnotationDetails(property, annotation));
	return property;
}