本文整理汇总了Java中io.swagger.models.properties.StringProperty类的典型用法代码示例。如果您正苦于以下问题:Java StringProperty类的具体用法?Java StringProperty怎么用?Java StringProperty使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
StringProperty类属于io.swagger.models.properties包,在下文中一共展示了StringProperty类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initPropertyMap
import io.swagger.models.properties.StringProperty; //导入依赖的package包/类
private static void initPropertyMap() {
PROPERTY_MAP.put(BooleanProperty.class, SimpleType.constructUnsafe(Boolean.class));
PROPERTY_MAP.put(FloatProperty.class, SimpleType.constructUnsafe(Float.class));
PROPERTY_MAP.put(DoubleProperty.class, SimpleType.constructUnsafe(Double.class));
PROPERTY_MAP.put(DecimalProperty.class, SimpleType.constructUnsafe(BigDecimal.class));
PROPERTY_MAP.put(ByteProperty.class, SimpleType.constructUnsafe(Byte.class));
PROPERTY_MAP.put(ShortProperty.class, SimpleType.constructUnsafe(Short.class));
PROPERTY_MAP.put(IntegerProperty.class, SimpleType.constructUnsafe(Integer.class));
PROPERTY_MAP.put(BaseIntegerProperty.class, SimpleType.constructUnsafe(Integer.class));
PROPERTY_MAP.put(LongProperty.class, SimpleType.constructUnsafe(Long.class));
// stringProperty包含了enum的场景,并不一定是转化为string
// 但是,如果统一走StringPropertyConverter则可以处理enum的场景
PROPERTY_MAP.put(StringProperty.class, SimpleType.constructUnsafe(String.class));
PROPERTY_MAP.put(DateProperty.class, SimpleType.constructUnsafe(LocalDate.class));
PROPERTY_MAP.put(DateTimeProperty.class, SimpleType.constructUnsafe(Date.class));
PROPERTY_MAP.put(ByteArrayProperty.class, SimpleType.constructUnsafe(byte[].class));
PROPERTY_MAP.put(FileProperty.class, SimpleType.constructUnsafe(Part.class));
}
示例2: initConverters
import io.swagger.models.properties.StringProperty; //导入依赖的package包/类
private static void initConverters() {
// inner converters
for (Class<? extends Property> propertyCls : PROPERTY_MAP.keySet()) {
addInnerConverter(propertyCls);
}
converterMap.put(RefProperty.class, new RefPropertyConverter());
converterMap.put(ArrayProperty.class, new ArrayPropertyConverter());
converterMap.put(MapProperty.class, new MapPropertyConverter());
converterMap.put(StringProperty.class, new StringPropertyConverter());
converterMap.put(ObjectProperty.class, new ObjectPropertyConverter());
converterMap.put(ModelImpl.class, new ModelImplConverter());
converterMap.put(RefModel.class, new RefModelConverter());
converterMap.put(ArrayModel.class, new ArrayModelConverter());
converterMap.put(BodyParameter.class, new BodyParameterConverter());
AbstractSerializableParameterConverter converter = new AbstractSerializableParameterConverter();
converterMap.put(QueryParameter.class, converter);
converterMap.put(PathParameter.class, converter);
converterMap.put(HeaderParameter.class, converter);
converterMap.put(FormParameter.class, converter);
converterMap.put(CookieParameter.class, converter);
}
示例3: convert
import io.swagger.models.properties.StringProperty; //导入依赖的package包/类
@Override
public JavaType convert(ClassLoader classLoader, String packageName, Swagger swagger, Object def) {
AbstractSerializableParameter<?> param = (AbstractSerializableParameter<?>) def;
switch (param.getType()) {
case ArrayProperty.TYPE:
return ArrayPropertyConverter.findJavaType(classLoader,
packageName,
swagger,
param.getItems(),
param.isUniqueItems());
case StringProperty.TYPE:
return StringPropertyConverter.findJavaType(classLoader,
packageName,
swagger,
param.getType(),
param.getFormat(),
param.getEnum());
default:
return ConverterMgr.findJavaType(param.getType(), param.getFormat());
}
}
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:23,代码来源:AbstractSerializableParameterConverter.java
示例4: resolveProperty
import io.swagger.models.properties.StringProperty; //导入依赖的package包/类
@Override
public Property resolveProperty(JavaType propType, ModelConverterContext context, Annotation[] annotations,
Iterator<ModelConverter> next) {
checkType(propType);
PropertyCreator creator = propertyCreatorMap.get(propType.getRawClass());
if (creator != null) {
return creator.createProperty();
}
Property property = super.resolveProperty(propType, context, annotations, next);
if (StringProperty.class.isInstance(property)) {
if (StringPropertyConverter.isEnum((StringProperty) property)) {
setType(propType, property.getVendorExtensions());
}
}
return property;
}
示例5: testStringProperty
import io.swagger.models.properties.StringProperty; //导入依赖的package包/类
@Test
public void testStringProperty() {
SwaggerGenerator generator = new SwaggerGeneratorForTest(context, null);
List<String> enums = Arrays.asList("testStringProperty_a", "testStringProperty_b");
StringProperty sp = new StringProperty();
sp._enum(enums);
StringPropertyConverter spc = new StringPropertyConverter();
JavaType jt =
spc.convert(generator.getClassLoader(), generator.ensureGetPackageName(), generator.getSwagger(), sp);
StringProperty spNew = (StringProperty) ModelConverters.getInstance().readAsProperty(jt);
Assert.assertEquals(enums, spNew.getEnum());
}
示例6: paramBody
import io.swagger.models.properties.StringProperty; //导入依赖的package包/类
/**
* Build BodyParameter for the Route parameter of type body.
*/
private BodyParameter paramBody(List<RequestRouter.Parameter> routeParams, Route route) {
BodyParameter bodyParam = new BodyParameter();
bodyParam.setRequired(false);
Model model = new ModelImpl();
if (routeParams != null) {
Map<String, Property> properties = new HashMap<>(routeParams.size());
routeParams.stream().forEach((p) -> {
StringProperty stringProperty = new StringProperty();
stringProperty.setName(p.name);
stringProperty
.setDescription(isBlank(p.description) ? route.description : p.description);
stringProperty.setDefault(p.value);
stringProperty.setRequired(p.required);
stringProperty.setType(StringProperty.TYPE);
properties.put(p.name, stringProperty);
});
model.setProperties(properties);
}
bodyParam.setSchema(model);
return bodyParam;
}
示例7: createSchemaFromProperty
import io.swagger.models.properties.StringProperty; //导入依赖的package包/类
private static JsonNode createSchemaFromProperty(final String specification, final Property schema) {
if (schema instanceof MapProperty) {
try {
final String schemaString = Json.mapper().writeValueAsString(schema);
return parseJsonSchema(schemaString);
} catch (final JsonProcessingException e) {
throw new IllegalStateException("Unable to serialize/read given JSON specification in response schema: " + schema, e);
}
} else if (schema instanceof StringProperty) {
return null;
}
final String reference = determineSchemaReference(schema);
final String title = Optional.ofNullable(schema.getTitle()).orElse(reference.replaceAll("^.*/", ""));
return createSchemaFromReference(specification, title, reference);
}
示例8: createShapeFromProperty
import io.swagger.models.properties.StringProperty; //导入依赖的package包/类
private static DataShape createShapeFromProperty(final String specification, final Property schema) {
if (schema instanceof MapProperty) {
try {
final String schemaString = Json.mapper().writeValueAsString(schema);
return new DataShape.Builder().kind("json-schema").specification(schemaString).build();
} catch (final JsonProcessingException e) {
throw new IllegalStateException("Unable to serialize given JSON specification in response schema: " + schema, e);
}
} else if (schema instanceof StringProperty) {
return DATA_SHAPE_NONE;
}
final String reference = determineSchemaReference(schema);
final String title = Optional.ofNullable(schema.getTitle()).orElse(reference.replaceAll("^.*/", ""));
return createShapeFromReference(specification, title, reference);
}
示例9: mapGraphValue
import io.swagger.models.properties.StringProperty; //导入依赖的package包/类
@Override
public String mapGraphValue(@NonNull StringProperty property,
@NonNull GraphEntityContext graphEntityContext, @NonNull ValueContext valueContext,
@NonNull SchemaMapperAdapter schemaMapperAdapter) {
validateVendorExtensions(property);
Map<String, Object> vendorExtensions = property.getVendorExtensions();
if (vendorExtensions.containsKey(OpenApiSpecificationExtensions.LDPATH)) {
LdPathExecutor ldPathExecutor = graphEntityContext.getLdPathExecutor();
return handleLdPathVendorExtension(property, valueContext.getValue(), ldPathExecutor);
}
if (vendorExtensions.containsKey(OpenApiSpecificationExtensions.CONSTANT_VALUE)) {
return handleConstantValueVendorExtension(property);
}
if (valueContext.getValue() != null) {
return valueContext.getValue().stringValue();
} else if (property.getRequired()) {
throw new SchemaMapperRuntimeException("No result for required property.");
}
return null;
}
示例10: validateVendorExtensions
import io.swagger.models.properties.StringProperty; //导入依赖的package包/类
/**
* Validates the vendor extensions that are declared on the StringProperty. A StringProperty
* should have exactly one of these vendor extensions:
* <ul>
* <li>{@link OpenApiSpecificationExtensions#CONSTANT_VALUE}</li>
* <li>{@link OpenApiSpecificationExtensions#LDPATH}</li>
* </ul>
*
* @throws SchemaMapperRuntimeException if none of these or multiple of these vendor extentions
* are encountered.
*/
private void validateVendorExtensions(StringProperty property) {
ImmutableSet<String> supportedVendorExtensions = ImmutableSet.of(
OpenApiSpecificationExtensions.LDPATH, OpenApiSpecificationExtensions.RELATIVE_LINK,
OpenApiSpecificationExtensions.CONSTANT_VALUE);
long nrOfSupportedVendorExtentionsPresent =
property.getVendorExtensions().keySet().stream().filter(
supportedVendorExtensions::contains).count();
if (nrOfSupportedVendorExtentionsPresent > 1) {
throw new SchemaMapperRuntimeException(String.format(
"A string object must have either no, a '%s', '%s' or '%s' property. "
+ "A string object cannot have a combination of these.",
OpenApiSpecificationExtensions.LDPATH, OpenApiSpecificationExtensions.RELATIVE_LINK,
OpenApiSpecificationExtensions.CONSTANT_VALUE));
}
}
示例11: handleConstantValueVendorExtension
import io.swagger.models.properties.StringProperty; //导入依赖的package包/类
private String handleConstantValueVendorExtension(StringProperty property) {
Object value =
property.getVendorExtensions().get(OpenApiSpecificationExtensions.CONSTANT_VALUE);
if (value != null) {
if (isSupportedLiteral(value)) {
return ((Value) value).stringValue();
}
return value.toString();
}
if (property.getRequired()) {
throw new SchemaMapperRuntimeException(String.format(
"String property has '%s' vendor extension that is null, but the property is required.",
OpenApiSpecificationExtensions.CONSTANT_VALUE));
}
return null;
}
示例12: handleLdPathVendorExtension
import io.swagger.models.properties.StringProperty; //导入依赖的package包/类
private String handleLdPathVendorExtension(StringProperty property, Value context,
LdPathExecutor ldPathExecutor) {
String ldPathQuery =
(String) property.getVendorExtensions().get(OpenApiSpecificationExtensions.LDPATH);
if (ldPathQuery == null) {
if (property.getRequired()) {
throw new SchemaMapperRuntimeException(String.format(
"String property has '%s' vendor extension that is null, but the property is required.",
OpenApiSpecificationExtensions.LDPATH));
}
return null;
}
/* at this point we're sure that ld-path is not null */
Collection<Value> queryResult = ldPathExecutor.ldPathQuery(context, ldPathQuery);
if (!property.getRequired() && queryResult.isEmpty()) {
return null;
}
LOG.debug("Context: {}", context);
return getSingleStatement(queryResult, ldPathQuery).stringValue();
}
示例13: map_MapsToMapperResult_ForRequiredPropertyWithPresentBinding
import io.swagger.models.properties.StringProperty; //导入依赖的package包/类
@Test
public void map_MapsToMapperResult_ForRequiredPropertyWithPresentBinding() {
// Assert
StringProperty nameProperty = new StringProperty().required(true);
TupleEntity entity = new TupleEntity(
ImmutableMap.of(MediaType.APPLICATION_JSON_TYPE, new ArrayProperty().items(
new ObjectProperty().required(true).properties(ImmutableMap.of("name", nameProperty)))),
result);
when(result.hasNext()).thenReturn(true, false);
when(result.next()).thenReturn(
new ListBindingSet(ImmutableList.of("name"), ImmutableList.of(DBEERPEDIA.BROUWTOREN_NAME)));
when(schemaMapper.mapTupleValue(any(StringProperty.class),
any(ValueContext.class))).thenReturn(DBEERPEDIA.BROUWTOREN_NAME.stringValue());
// Act
Object mappedEntity = tupleEntityMapper.map(entity, MediaType.APPLICATION_JSON_TYPE);
// Assert
assertThat(mappedEntity, instanceOf(ImmutableList.class));
assertThat((ImmutableList<Object>) mappedEntity, hasSize(1));
assertThat((ImmutableList<Object>) mappedEntity,
contains(ImmutableMap.of("name", DBEERPEDIA.BROUWTOREN_NAME.stringValue())));
}
示例14: map_MapsToAbsentOptionalValue_ForOptionalPropertyWithAbsentBinding
import io.swagger.models.properties.StringProperty; //导入依赖的package包/类
@Test
public void map_MapsToAbsentOptionalValue_ForOptionalPropertyWithAbsentBinding() {
// Arrange
TupleEntity entity = new TupleEntity(ImmutableMap.of(MediaType.APPLICATION_JSON_TYPE,
new ArrayProperty().items(new ObjectProperty().properties(
ImmutableMap.of("name", new StringProperty().required(false))))),
result);
when(result.hasNext()).thenReturn(true, false);
when(result.next()).thenReturn(new ListBindingSet(ImmutableList.of(), ImmutableList.of()));
// Act
Object mappedEntity = tupleEntityMapper.map(entity, MediaType.APPLICATION_JSON_TYPE);
// Assert
assertThat(mappedEntity, instanceOf(ImmutableList.class));
assertThat((ImmutableList<Object>) mappedEntity, hasSize(1));
assertThat((ImmutableList<Object>) mappedEntity,
contains(ImmutableMap.of("name", Optional.absent())));
}
示例15: map_ThrowsException_ForSingleResultWithSingleObject
import io.swagger.models.properties.StringProperty; //导入依赖的package包/类
@Test
public void map_ThrowsException_ForSingleResultWithSingleObject() {
// Arrange
StringProperty stringProperty = new StringProperty();
final TupleEntity entity = new TupleEntity(ImmutableMap.of(MediaType.APPLICATION_JSON_TYPE,
new ObjectProperty().properties(ImmutableMap.of("name", stringProperty.required(false)))),
result);
when(result.hasNext()).thenReturn(false);
// Assert
thrown.expect(EntityMapperRuntimeException.class);
thrown.expectMessage("TupleQueryResult did not yield any values.");
// Act
tupleEntityMapper.map(entity, MediaType.APPLICATION_JSON_TYPE);
}