本文整理汇总了Java中io.swagger.converter.ModelConverters类的典型用法代码示例。如果您正苦于以下问题:Java ModelConverters类的具体用法?Java ModelConverters怎么用?Java ModelConverters使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ModelConverters类属于io.swagger.converter包,在下文中一共展示了ModelConverters类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setParameterType
import io.swagger.converter.ModelConverters; //导入依赖的package包/类
public static void setParameterType(Swagger swagger, Method method, int paramIdx,
AbstractSerializableParameter<?> parameter) {
Type paramType = ParamUtils.getGenericParameterType(method, paramIdx);
ParamUtils.addDefinitions(swagger, paramType);
Property property = ModelConverters.getInstance().readAsProperty(paramType);
if (isComplexProperty(property)) {
// 简单参数不可以是复杂类型
String msg = String.format("not allow complex type for %s parameter, method=%s:%s, paramIdx=%d, type=%s",
parameter.getIn(),
method.getDeclaringClass().getName(),
method.getName(),
paramIdx,
paramType.getTypeName());
throw new Error(msg);
}
parameter.setProperty(property);
}
示例2: process
import io.swagger.converter.ModelConverters; //导入依赖的package包/类
@Override
public Property process(OperationGenerator operationGenerator) {
// Response完全表达应答类型
// 如果produces是text,那么可以假设是string,否则只能报错
List<String> produces = operationGenerator.getOperation().getProduces();
if (produces == null) {
produces = operationGenerator.getSwagger().getProduces();
}
if (produces != null) {
if (produces.contains(MediaType.TEXT_PLAIN)) {
Type responseType = String.class;
ParamUtils.addDefinitions(operationGenerator.getSwagger(), responseType);
return ModelConverters.getInstance().readAsProperty(responseType);
}
}
throw new Error("Use ApiOperation or ApiResponses to declare response type");
}
示例3: testStringProperty
import io.swagger.converter.ModelConverters; //导入依赖的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());
}
示例4: parseResponseHeaders
import io.swagger.converter.ModelConverters; //导入依赖的package包/类
private static Map<String, Property> parseResponseHeaders(ReaderContext context,
ResponseHeader[] headers) {
Map<String, Property> responseHeaders = null;
for (ResponseHeader header : headers) {
final String name = header.name();
if (StringUtils.isNotEmpty(name)) {
if (responseHeaders == null) {
responseHeaders = new HashMap<String, Property>();
}
final Class<?> cls = header.response();
if (!ReflectionUtils.isVoid(cls)) {
final Property property = ModelConverters.getInstance().readAsProperty(cls);
if (property != null) {
final Property responseProperty = ContainerWrapper.wrapContainer(
header.responseContainer(), property, ContainerWrapper.ARRAY,
ContainerWrapper.LIST, ContainerWrapper.SET);
responseProperty.setDescription(header.description());
responseHeaders.put(name, responseProperty);
appendModels(context.getSwagger(), cls);
}
}
}
}
return responseHeaders;
}
示例5: parseResponseHeaders
import io.swagger.converter.ModelConverters; //导入依赖的package包/类
private static Map<String, Property> parseResponseHeaders(Swagger swagger, ReaderContext context, ResponseHeader[] headers) {
Map<String, Property> responseHeaders = null;
for (ResponseHeader header : headers) {
final String name = header.name();
if (StringUtils.isNotEmpty(name)) {
if (responseHeaders == null) {
responseHeaders = new HashMap<String, Property>();
}
final Class<?> cls = header.response();
if (!ReflectionUtils.isVoid(cls)) {
final Property property = ModelConverters.getInstance().readAsProperty(cls);
if (property != null) {
final Property responseProperty = ContainerWrapper.wrapContainer(header.responseContainer(),
property, ContainerWrapper.ARRAY, ContainerWrapper.LIST, ContainerWrapper.SET);
responseProperty.setDescription(header.description());
responseHeaders.put(name, responseProperty);
appendModels(swagger, cls);
}
}
}
}
return responseHeaders;
}
示例6: extractProperties
import io.swagger.converter.ModelConverters; //导入依赖的package包/类
@Test
public void extractProperties() {
final Map<String, Model> models = ModelConverters.getInstance().readAll(Family.class);
assertEquals(models.size(), 3);
final Model person = models.get("Person");
final Property employer = person.getProperties().get("employer");
assertTrue(employer instanceof ArrayProperty);
final ArrayProperty employerProperty = (ArrayProperty) employer;
final Property items = employerProperty.getItems();
assertTrue(items instanceof RefProperty);
assertEquals(((RefProperty) items).getSimpleRef(), "Employer");
final Property awards = person.getProperties().get("awards");
assertTrue(awards instanceof ArrayProperty);
assertTrue(((ArrayProperty) awards).getItems() instanceof StringProperty);
}
示例7: testBookPermissions
import io.swagger.converter.ModelConverters; //导入依赖的package包/类
@Test
public void testBookPermissions() throws Exception {
ModelConverters converters = ModelConverters.getInstance();
converters.addConverter(new JsonApiModelResolver(dictionary));
Map<String, Model> models = converters.readAll(Book.class);
Resource bookModel = (Resource) models.get("book");
String entityPermissions = bookModel.getProperties().get("type").getDescription();
Assert.assertEquals(entityPermissions,
"Create Permissions : (Principal is author)\nDelete Permissions : (Deny All)\n");
ObjectProperty attributes = (ObjectProperty) bookModel.getProperties().get("attributes");
ObjectProperty relationships = (ObjectProperty) bookModel.getProperties().get("relationships");
String titlePermissions = attributes.getProperties().get("title").getDescription();
Assert.assertEquals(titlePermissions, "Read Permissions : (Principal is author OR Principal is publisher)\n");
String publisherPermissions = relationships.getProperties().get("publisher").getDescription();
Assert.assertEquals(publisherPermissions,
"Read Permissions : (Principal is author OR Principal is publisher)\n"
+ "Update Permissions : (Principal is publisher)\n");
}
示例8: testModelResolution
import io.swagger.converter.ModelConverters; //导入依赖的package包/类
@Test
public void testModelResolution() throws Exception {
ModelConverters converters = ModelConverters.getInstance();
converters.addConverter(new JsonApiModelResolver(dictionary));
Map<String, Model> models = converters.readAll(Publisher.class);
Resource publisherModel = (Resource) models.get("publisher");
ObjectProperty attributes = (ObjectProperty) publisherModel.getProperties().get("attributes");
ObjectProperty relationships = (ObjectProperty) publisherModel.getProperties().get("relationships");
Assert.assertEquals(attributes.getProperties().size(), 2);
Assert.assertEquals(relationships.getProperties().size(), 2);
Assert.assertTrue(attributes.getProperties().containsKey("billingAddress"));
Assert.assertTrue(attributes.getProperties().containsKey("billingCodes"));
Assert.assertTrue(relationships.getProperties().containsKey("books"));
Assert.assertTrue(relationships.getProperties().containsKey("exclusiveAuthors"));
}
示例9: addResponse
import io.swagger.converter.ModelConverters; //导入依赖的package包/类
private void addResponse(Operation operation, ApiResponse apiResponse) {
Map<String, Property> responseHeaders = parseResponseHeaders(apiResponse.responseHeaders());
Response response = new Response().description(apiResponse.message()).headers(responseHeaders);
if (apiResponse.code() == 0) {
operation.defaultResponse(response);
} else {
operation.response(apiResponse.code(), response);
}
if (StringUtils.isNotEmpty(apiResponse.reference())) {
response.schema(new RefProperty(apiResponse.reference()));
} else if (!isVoid(apiResponse.response())) {
Type responseType = apiResponse.response();
final Property property = ModelConverters.getInstance().readAsProperty(responseType);
if (property != null) {
response.schema(ContainerWrapper.wrapContainer(apiResponse.responseContainer(), property));
appendModels(responseType);
}
}
}
示例10: define
import io.swagger.converter.ModelConverters; //导入依赖的package包/类
/**
* Register a Java type and produces an equivalent RAML type. It returns an existing RAML type if
* the Java type was registered already.
*
* @param type Java type.
* @return RAML type.
*/
public RamlType define(Type type) {
if (types == null) {
types = new LinkedHashMap<>();
}
Type componentType = componentType(type);
String typeName = MoreTypes.getRawType(componentType).getSimpleName();
RamlType ramlType = RamlType.valueOf(typeName);
if (ramlType.isObject()) {
RamlType existing = types.get(typeName);
if (existing == null) {
ModelConverters converter = ModelConverters.getInstance();
Property property = converter.readAsProperty(componentType);
Map<PropertyBuilder.PropertyId, Object> args = new EnumMap<>(
PropertyBuilder.PropertyId.class);
for (Map.Entry<String, Model> entry : converter.readAll(componentType).entrySet()) {
define(entry.getKey(), entry.getValue());
}
ramlType = define(typeName, PropertyBuilder.toModel(PropertyBuilder.merge(property, args)));
} else {
ramlType = existing;
}
}
return type != componentType ? ramlType.toArray() : ramlType;
}
示例11: createPendingBodyParameter
import io.swagger.converter.ModelConverters; //导入依赖的package包/类
public static PendingBodyParameter createPendingBodyParameter(OperationGenerator operationGenerator,
String paramName, Type paramType) {
ParamUtils.addDefinitions(operationGenerator.getSwagger(), paramType);
Property property = ModelConverters.getInstance().readAsProperty(paramType);
PendingBodyParameter pendingBodyParameter = new PendingBodyParameter();
pendingBodyParameter.setName(paramName);
pendingBodyParameter.setProperty(property);
pendingBodyParameter.setType(paramType);
pendingBodyParameter.setOperationGenerator(operationGenerator);
return pendingBodyParameter;
}
示例12: createBodyParameter
import io.swagger.converter.ModelConverters; //导入依赖的package包/类
public static BodyParameter createBodyParameter(Swagger swagger, String paramName, Type paramType) {
addDefinitions(swagger, paramType);
Property property = ModelConverters.getInstance().readAsProperty(paramType);
Model model = PropertyBuilder.toModel(property);
BodyParameter bodyParameter = new BodyParameter();
bodyParameter.setName(paramName);
bodyParameter.setSchema(model);
return bodyParameter;
}
示例13: process
import io.swagger.converter.ModelConverters; //导入依赖的package包/类
@Override
public Property process(OperationGenerator operationGenerator) {
Type responseType = operationGenerator.getProviderMethod().getGenericReturnType();
ParamUtils.addDefinitions(operationGenerator.getSwagger(), responseType);
return ModelConverters.getInstance().readAsProperty(responseType);
}
示例14: process
import io.swagger.converter.ModelConverters; //导入依赖的package包/类
@Override
public Property process(OperationGenerator operationGenerator) {
ParameterizedType type =
(ParameterizedType) operationGenerator.getProviderMethod().getGenericReturnType();
Type responseType = type.getActualTypeArguments()[0];
ParamUtils.addDefinitions(operationGenerator.getSwagger(), responseType);
return ModelConverters.getInstance().readAsProperty(responseType);
}
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:10,代码来源:AbstractOneGenericResponseProcessor.java
示例15: validateModel
import io.swagger.converter.ModelConverters; //导入依赖的package包/类
ValidationResult validateModel(JSONObject json, Class<?> type, boolean strict)
throws ValidationException, JSONException {
ModelConverters modelConverters = ModelConverters.getInstance();
ValidationResult result = new ValidationResult();
Map<String,Model> models = modelConverters.readAll(type);
Map<String,Model> mainModels = modelConverters.read(type);
for (String modelName : mainModels.keySet()) {
Model mainModel = mainModels.get(modelName);
result.addValidationMessages(validateFields(json, mainModel, models));
if (strict)
result.addValidationMessages(validateFieldsInModel(json, mainModel, models));
}
return result;
}