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


Java StringProperty.getEnum方法代码示例

本文整理汇总了Java中io.swagger.models.properties.StringProperty.getEnum方法的典型用法代码示例。如果您正苦于以下问题:Java StringProperty.getEnum方法的具体用法?Java StringProperty.getEnum怎么用?Java StringProperty.getEnum使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.swagger.models.properties.StringProperty的用法示例。


在下文中一共展示了StringProperty.getEnum方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: doConvert

import io.swagger.models.properties.StringProperty; //导入方法依赖的package包/类
@Override
public JavaType doConvert(ClassLoader classLoader, String packageName, Swagger swagger, Object property) {
  StringProperty stringProperty = (StringProperty) property;

  List<String> enums = stringProperty.getEnum();
  return findJavaType(classLoader,
      packageName,
      swagger,
      stringProperty.getType(),
      stringProperty.getFormat(),
      enums);
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:13,代码来源:StringPropertyConverter.java

示例2: validate

import io.swagger.models.properties.StringProperty; //导入方法依赖的package包/类
@Override
public ValidationResult validate(JSONObject json, String key, Property modelProperty,
        Iterator<Validator> next) {
    ValidationResult result = new ValidationResult();
    if (modelProperty instanceof StringProperty) {
        try {
            StringProperty stringProperty = (StringProperty) modelProperty;
            // Check for allowable values
            if (stringProperty.getEnum() != null && stringProperty.getEnum().size() > 0) {
                List<?> values = stringProperty.getEnum();
                Set<String> allowable = new LinkedHashSet<String>();
                for (Object obj : values) {
                    allowable.add(obj.toString());
                }
                if (!allowable.contains(json.getString(key))) {
                    result = new ValidationResult().addValidationMessage(new ValidationMessage()
                            .message(("`" + key + "` value `" + json.getString(key)
                                    + "` is not in the allowable values `" + allowable + "`")));
                }
            }
            if ((stringProperty.getMinLength() !=null && stringProperty.getMinLength() > 0) || (stringProperty.getMaxLength()!=null && stringProperty.getMaxLength() > 0 )) {
                result.addValidationMessage(validateMinMaxLength(key, json.getString(key), stringProperty.getMinLength(), stringProperty.getMaxLength()));
            }
            // TBD Support date and date-time
        }
        catch (JSONException e) {
            result = new ValidationResult().addValidationMessage(
                    new ValidationMessage().message("Unable to parse property " + key
                            + " from json " + json.toString() + ":" + e.getMessage()));
        }
    }
    if (next.hasNext()) {
        result.addValidationMessages(next.next().validate(json, key, modelProperty, next));
    }
    return result;
}
 
开发者ID:CenturyLinkCloud,项目名称:mdw,代码行数:37,代码来源:StringValidator.java

示例3: validateProperty

import io.swagger.models.properties.StringProperty; //导入方法依赖的package包/类
private void validateProperty(Property actualProperty, Property expectedProperty, String message) {
    // TODO Validate Property schema
    if (expectedProperty != null && isAssertionEnabled(SwaggerAssertionType.PROPERTIES)) {
        if (expectedProperty instanceof RefProperty) {
            if (isAssertionEnabled(SwaggerAssertionType.REF_PROPERTIES)) {
                RefProperty refProperty = (RefProperty) expectedProperty;
                softAssertions.assertThat(actualProperty).as(message).isExactlyInstanceOf(RefProperty.class);
                // TODO Validate RefProperty
            }
        } else if (expectedProperty instanceof ArrayProperty) {
            if (isAssertionEnabled(SwaggerAssertionType.ARRAY_PROPERTIES)) {
                ArrayProperty arrayProperty = (ArrayProperty) expectedProperty;
                softAssertions.assertThat(actualProperty).as(message).isExactlyInstanceOf(ArrayProperty.class);
                // TODO Validate ArrayProperty
            }
        } else if (expectedProperty instanceof StringProperty) {
            if (isAssertionEnabled(SwaggerAssertionType.STRING_PROPERTIES)) {
                StringProperty expectedStringProperty = (StringProperty) expectedProperty;
                softAssertions.assertThat(actualProperty).as(message).isExactlyInstanceOf(StringProperty.class);
                // TODO Validate StringProperty
                if(actualProperty instanceof StringProperty){
                    StringProperty actualStringProperty = (StringProperty) expectedProperty;
                    List<String> expectedEnums = expectedStringProperty.getEnum();
                    if (CollectionUtils.isNotEmpty(expectedEnums)) {
                        softAssertions.assertThat(actualStringProperty.getEnum()).hasSameElementsAs(expectedEnums);
                    }else{
                        softAssertions.assertThat(actualStringProperty.getEnum()).isNullOrEmpty();
                    }
                }
            }
        } else {
            // TODO Validate all other properties
            softAssertions.assertThat(actualProperty).isExactlyInstanceOf(expectedProperty.getClass());
        }
    }

}
 
开发者ID:RobWin,项目名称:assertj-swagger,代码行数:38,代码来源:ConsumerDrivenValidator.java

示例4: getType

import io.swagger.models.properties.StringProperty; //导入方法依赖的package包/类
public static String getType(Property property, Set<String> requiredRefinitions){
    Validate.notNull(property, "property must not be null!");
    String type;
    if(property instanceof RefProperty){
        RefProperty refProperty = (RefProperty)property;
        if(requiredRefinitions != null)
            requiredRefinitions.add(refProperty.getSimpleRef());
        return "["+refProperty.getSimpleRef()+"](#"+refProperty.getSimpleRef().toLowerCase(Locale.ENGLISH)+")";
    }else if(property instanceof ArrayProperty){
        ArrayProperty arrayProperty = (ArrayProperty)property;
        Property items = arrayProperty.getItems();
        type = getType(items, requiredRefinitions) + " " + arrayProperty.getType();
    }else if(property instanceof StringProperty){
        StringProperty stringProperty = (StringProperty)property;
        List<String> enums = stringProperty.getEnum();
        if(enums !=null && !enums.isEmpty()){
            type = "enum" + " (" + StringUtils.join(enums, ", ") + ")";
        }else{
            type = property.getType();
        }
    }
    else{
        if(StringUtils.isNotBlank(property.getFormat())){
            type = StringUtils.defaultString(property.getType()) + " (" + property.getFormat() + ")";
        }else{
            type = property.getType();
        }
    }
    return StringUtils.defaultString(type);
}
 
开发者ID:buremba,项目名称:swagger-slate,代码行数:31,代码来源:PropertyUtils.java

示例5: fillProperty

import io.swagger.models.properties.StringProperty; //导入方法依赖的package包/类
public static Object fillProperty(Swagger swagger, RandomGenerator gen, Property property) {
	switch (property.getType()) {
	case "string":
		if (property instanceof StringProperty) {
			StringProperty stringProp = (StringProperty) property;
			if (stringProp.getEnum() != null && !stringProp.getEnum().isEmpty()) {
				return gen.getValue(stringProp.getEnum());
			} else {
				return FormatGenerator.getString(gen, stringProp.getFormat(),
						(stringProp.getMinLength() != null ? stringProp.getMinLength() : 1),
						(stringProp.getMaxLength() != null ? stringProp.getMaxLength() : 25));
			}
		} else if (property instanceof DateTimeProperty) {
			DateTimeProperty dateTimeProp = (DateTimeProperty) property;
			if (dateTimeProp.getEnum() != null && !dateTimeProp.getEnum().isEmpty()) {
				return gen.getValue(dateTimeProp.getEnum());
			} else {
				return FormatGenerator.getString(gen, dateTimeProp.getFormat(), 0, 0);
			}
		} else if (property instanceof DateProperty) {
			DateProperty dateProp = (DateProperty) property;
			if (dateProp.getEnum() != null && !dateProp.getEnum().isEmpty()) {
				return gen.getValue(dateProp.getEnum());
			} else {
				return FormatGenerator.getString(gen, dateProp.getFormat(), 0, 0);
			}
		} else {
			throw new RuntimeException(
					"This String format is not supported : " + property.getClass().getSimpleName());
		}
	case "integer":
		BaseIntegerProperty intProp = (BaseIntegerProperty) property;
		return FormatGenerator.getInteger(gen, intProp.getFormat(),
				(intProp.getMinimum() != null ? intProp.getMinimum().intValue() : Integer.MIN_VALUE),
				(intProp.getMaximum() != null ? intProp.getMaximum().intValue() : Integer.MAX_VALUE));
	case "number":
		DecimalProperty numberProp = (DecimalProperty) property;
		return FormatGenerator.getNumber(gen, numberProp.getFormat(),
				(numberProp.getMinimum() != null ? numberProp.getMinimum() : Double.MIN_VALUE),
				(numberProp.getMaximum() != null ? numberProp.getMaximum() : Double.MAX_VALUE));
	case "boolean":
		return FormatGenerator.getBoolean(gen);
	case "ref":
		return getRef(swagger, gen, (RefProperty) property);
	case "array":
		return getArray(swagger, gen, (ArrayProperty) property);
	default:
		throw new RuntimeException("This type is not supported.");
	}
}
 
开发者ID:lpelleau,项目名称:SwagTester,代码行数:51,代码来源:BodyGenerator.java


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