use of io.swagger.models.properties.StringProperty in project camel by apache.
the class RestModelConverters method readClass.
public Map<String, Model> readClass(Class clazz) {
String name = clazz.getName();
Map<String, Model> resolved = super.read(clazz);
if (resolved != null) {
for (Model model : resolved.values()) {
// enrich with the class name of the model
model.getVendorExtensions().put("x-className", new StringProperty(name));
}
// read any extra using read-all
Map<String, Model> extra = super.readAll(clazz);
if (extra != null) {
for (Map.Entry<String, Model> entry : extra.entrySet()) {
if (!resolved.containsKey(entry.getKey())) {
resolved.put(entry.getKey(), entry.getValue());
}
}
}
}
return resolved;
}
use of io.swagger.models.properties.StringProperty in project camel by apache.
the class RestSwaggerReader method modelTypeAsProperty.
private Property modelTypeAsProperty(String typeName, Swagger swagger) {
boolean array = typeName.endsWith("[]");
if (array) {
typeName = typeName.substring(0, typeName.length() - 2);
}
String ref = modelTypeAsRef(typeName, swagger);
Property prop = ref != null ? new RefProperty(ref) : new StringProperty(typeName);
if (array) {
return new ArrayProperty(prop);
} else {
return prop;
}
}
use of io.swagger.models.properties.StringProperty in project swagger-core by swagger-api.
the class ModelResolver method resolveProperty.
public Property resolveProperty(JavaType propType, ModelConverterContext context, Annotation[] annotations, Iterator<ModelConverter> next) {
LOGGER.debug("resolveProperty {}", propType);
Property property = null;
if (propType.isContainerType()) {
JavaType keyType = propType.getKeyType();
JavaType valueType = propType.getContentType();
if (keyType != null && valueType != null) {
property = new MapProperty().additionalProperties(context.resolveProperty(valueType, new Annotation[] {}));
} else if (valueType != null) {
Property items = context.resolveProperty(valueType, new Annotation[] {});
// If property is XmlElement annotated, then use the name provided by annotation | https://github.com/swagger-api/swagger-core/issues/2047
if (annotations != null && annotations.length > 0) {
for (Annotation annotation : annotations) {
if (annotation instanceof XmlElement) {
XmlElement xmlElement = (XmlElement) annotation;
if (xmlElement != null && xmlElement.name() != null && !"".equals(xmlElement.name()) && !"##default".equals(xmlElement.name())) {
Xml xml = items.getXml() != null ? items.getXml() : new Xml();
xml.setName(xmlElement.name());
items.setXml(xml);
}
}
}
}
ArrayProperty arrayProperty = new ArrayProperty().items(items);
if (_isSetType(propType.getRawClass())) {
arrayProperty.setUniqueItems(true);
}
property = arrayProperty;
}
} else {
property = PrimitiveType.createProperty(propType);
}
if (property == null) {
if (propType.isEnumType()) {
property = new StringProperty();
_addEnumProps(propType.getRawClass(), property);
} else if (_isOptionalType(propType)) {
property = context.resolveProperty(propType.containedType(0), null);
} else {
// complex type
Model innerModel = context.resolve(propType);
if (innerModel instanceof ComposedModel) {
innerModel = ((ComposedModel) innerModel).getChild();
}
if (innerModel instanceof ModelImpl) {
ModelImpl mi = (ModelImpl) innerModel;
property = new RefProperty(StringUtils.isNotEmpty(mi.getReference()) ? mi.getReference() : mi.getName());
}
}
}
return property;
}
use of io.swagger.models.properties.StringProperty in project swagger-core by swagger-api.
the class ModelResolver method applyBeanValidatorAnnotations.
protected void applyBeanValidatorAnnotations(Property property, Annotation[] annotations) {
Map<String, Annotation> annos = new HashMap<String, Annotation>();
if (annotations != null) {
for (Annotation anno : annotations) {
annos.put(anno.annotationType().getName(), anno);
}
}
if (annos.containsKey("javax.validation.constraints.NotNull")) {
property.setRequired(true);
}
if (annos.containsKey("javax.validation.constraints.Min")) {
if (property instanceof AbstractNumericProperty) {
Min min = (Min) annos.get("javax.validation.constraints.Min");
AbstractNumericProperty ap = (AbstractNumericProperty) property;
ap.setMinimum(new BigDecimal(min.value()));
}
}
if (annos.containsKey("javax.validation.constraints.Max")) {
if (property instanceof AbstractNumericProperty) {
Max max = (Max) annos.get("javax.validation.constraints.Max");
AbstractNumericProperty ap = (AbstractNumericProperty) property;
ap.setMaximum(new BigDecimal(max.value()));
}
}
if (annos.containsKey("javax.validation.constraints.Size")) {
Size size = (Size) annos.get("javax.validation.constraints.Size");
if (property instanceof AbstractNumericProperty) {
AbstractNumericProperty ap = (AbstractNumericProperty) property;
ap.setMinimum(new BigDecimal(size.min()));
ap.setMaximum(new BigDecimal(size.max()));
} else if (property instanceof StringProperty) {
StringProperty sp = (StringProperty) property;
sp.minLength(new Integer(size.min()));
sp.maxLength(new Integer(size.max()));
} else if (property instanceof ArrayProperty) {
ArrayProperty sp = (ArrayProperty) property;
sp.setMinItems(size.min());
sp.setMaxItems(size.max());
}
}
if (annos.containsKey("javax.validation.constraints.DecimalMin")) {
DecimalMin min = (DecimalMin) annos.get("javax.validation.constraints.DecimalMin");
if (property instanceof AbstractNumericProperty) {
AbstractNumericProperty ap = (AbstractNumericProperty) property;
ap.setMinimum(new BigDecimal(min.value()));
ap.setExclusiveMinimum(!min.inclusive());
}
}
if (annos.containsKey("javax.validation.constraints.DecimalMax")) {
DecimalMax max = (DecimalMax) annos.get("javax.validation.constraints.DecimalMax");
if (property instanceof AbstractNumericProperty) {
AbstractNumericProperty ap = (AbstractNumericProperty) property;
ap.setMaximum(new BigDecimal(max.value()));
ap.setExclusiveMaximum(!max.inclusive());
}
}
if (annos.containsKey("javax.validation.constraints.Pattern")) {
Pattern pattern = (Pattern) annos.get("javax.validation.constraints.Pattern");
if (property instanceof StringProperty) {
StringProperty ap = (StringProperty) property;
ap.setPattern(pattern.regexp());
}
}
}
use of io.swagger.models.properties.StringProperty in project swagger-core by swagger-api.
the class ModelWithRangesTest method modelWithRangesTest.
@Test(description = "test model with @ApiModelProperty.allowableValues")
public void modelWithRangesTest() {
final Map<String, Property> properties = ModelConverters.getInstance().read(ModelWithRanges.class).get("ModelWithRanges").getProperties();
final IntegerProperty inclusiveRange = (IntegerProperty) properties.get("inclusiveRange");
assertEquals(inclusiveRange.getMinimum(), new BigDecimal(1));
assertEquals(inclusiveRange.getMaximum(), new BigDecimal(5));
assertNull(inclusiveRange.getExclusiveMaximum());
assertNull(inclusiveRange.getExclusiveMinimum());
final IntegerProperty exclusiveRange = (IntegerProperty) properties.get("exclusiveRange");
assertEquals(exclusiveRange.getMinimum(), new BigDecimal(1));
assertEquals(exclusiveRange.getMaximum(), new BigDecimal(5));
assertEquals(exclusiveRange.getExclusiveMinimum(), Boolean.TRUE);
assertEquals(exclusiveRange.getExclusiveMaximum(), Boolean.TRUE);
final IntegerProperty positiveInfinityRange = (IntegerProperty) properties.get("positiveInfinityRange");
assertEquals(positiveInfinityRange.getMinimum(), new BigDecimal(1.0));
assertNull(positiveInfinityRange.getMaximum());
assertNull(positiveInfinityRange.getExclusiveMaximum());
assertNull(positiveInfinityRange.getExclusiveMinimum());
final IntegerProperty negativeInfinityRange = (IntegerProperty) properties.get("negativeInfinityRange");
assertNull(negativeInfinityRange.getMinimum());
assertEquals(negativeInfinityRange.getMaximum(), new BigDecimal(5.0));
assertNull(negativeInfinityRange.getExclusiveMaximum());
assertNull(negativeInfinityRange.getExclusiveMinimum());
final StringProperty stringValues = (StringProperty) properties.get("stringValues");
assertEquals(stringValues.getEnum(), Arrays.asList("str1", "str2"));
final DoubleProperty doubleValues = (DoubleProperty) properties.get("doubleValues");
assertEquals(doubleValues.getMinimum(), new BigDecimal("1.0"));
assertEquals(doubleValues.getMaximum(), new BigDecimal("8.0"));
assertEquals(doubleValues.getExclusiveMaximum(), Boolean.TRUE);
assertNull(doubleValues.getExclusiveMinimum());
}
Aggregations