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


Java ModelConverters类代码示例

本文整理汇总了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);
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:21,代码来源:ParamUtils.java

示例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");
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:19,代码来源:JaxrsResponseProcessor.java

示例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());
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:17,代码来源:TestProperty.java

示例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;
}
 
开发者ID:Sayi,项目名称:swagger-dubbo,代码行数:26,代码来源:DubboReaderExtension.java

示例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;
}
 
开发者ID:yangfuhai,项目名称:jboot,代码行数:24,代码来源:ControllerReaderExtension.java

示例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);
}
 
开发者ID:pegasystems,项目名称:api2swagger,代码行数:20,代码来源:ModelPropertyTest.java

示例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");
}
 
开发者ID:yahoo,项目名称:elide,代码行数:26,代码来源:JsonApiModelResolverTest.java

示例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"));
}
 
开发者ID:yahoo,项目名称:elide,代码行数:20,代码来源:JsonApiModelResolverTest.java

示例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);
        }
    }
}
 
开发者ID:wso2,项目名称:msf4j,代码行数:23,代码来源:ExtendedSwaggerReader.java

示例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;
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:34,代码来源:Raml.java

示例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;
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:14,代码来源:PojoParamUtils.java

示例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;
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:13,代码来源:ParamUtils.java

示例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);
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:8,代码来源:DefaultResponseTypeProcessor.java

示例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;
}
 
开发者ID:CenturyLinkCloud,项目名称:mdw,代码行数:16,代码来源:CompatibleValidator.java


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