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


Java ModelConverters.addConverter方法代码示例

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


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

示例1: 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

示例2: 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

示例3: SwaggerFilter

import io.swagger.converter.ModelConverters; //导入方法依赖的package包/类
public SwaggerFilter() {
    ModelConverters modelConverters = ModelConverters.getInstance();
    modelConverters.addConverter(new ParamModelConverter(Tags.class, () -> {
        return new StringFormatProperty("tag-list");
    }));
    modelConverters.addConverter(new ParamModelConverter(Duration.class, () -> {
        return new StringFormatProperty("duration");
    }));
}
 
开发者ID:hawkular,项目名称:hawkular-metrics,代码行数:10,代码来源:SwaggerFilter.java

示例4: build

import io.swagger.converter.ModelConverters; //导入方法依赖的package包/类
/**
 * @return the constructed 'Swagger' object
 */
public Swagger build() {

    /* Used to convert Elide POJOs into Swagger Model objects */
    ModelConverters converters = ModelConverters.getInstance();
    converters.addConverter(new JsonApiModelResolver(dictionary));

    if (allClasses.isEmpty()) {
        allClasses = dictionary.getBindings();
    } else {
        allClasses = Sets.intersection(dictionary.getBindings(), allClasses);
        if (allClasses.isEmpty()) {
            throw new IllegalArgumentException("None of the provided classes are exported by Elide");
        }
    }

    /* Create a Model for each Elide entity */
    Map<String, Model> models = new HashMap<>();
    for (Class<?> clazz : allClasses) {
        models.putAll(converters.readAll(clazz));
    }
    swagger.setDefinitions(models);

    rootClasses =  allClasses.stream()
            .filter(dictionary::isRoot)
            .collect(Collectors.toSet());

    /* Find all the paths starting from the root entities. */
    Set<PathMetaData> pathData =  rootClasses.stream()
            .map(this::find)
            .flatMap(Collection::stream)
            .collect(Collectors.toSet());

    /* Prune the discovered paths to remove redundant elements */
    Set<PathMetaData> toRemove = new HashSet<>();
    for (PathMetaData path : pathData) {
        for (PathMetaData compare : pathData) {

            /*
             * We don't prune paths that are redundant with root collections to allow both BOTH
             * root collection urls as well as relationship urls.
             */
            if (path.equals(compare) || compare.lineage.isEmpty()) {
                continue;
            }
            if (compare.shorterThan(path)) {
                toRemove.add(path);
                break;
            }
        }
    }
    pathData = Sets.difference(pathData, toRemove);

    /* Each path constructs 3 URLs (collection, instance, and relationship) */
    for (PathMetaData pathDatum : pathData) {
        swagger.path(pathDatum.getCollectionUrl(), pathDatum.getCollectionPath());

        swagger.path(pathDatum.getInstanceUrl(), pathDatum.getInstancePath());

        /* We only construct relationship URLs if the entity is not a root collection */
        if (! pathDatum.lineage.isEmpty()) {
            swagger.path(pathDatum.getRelationshipUrl(), pathDatum.getRelationshipPath());
        }
    }

    /* We create Swagger 'tags' for each entity so Swagger UI organizes the paths by entities */
    List<Tag> tags = allClasses.stream()
            .map((clazz) -> dictionary.getJsonAliasFor(clazz))
            .map((alias) -> new Tag().name(alias))
            .collect(Collectors.toList());

    swagger.tags(tags);

    return swagger;
}
 
开发者ID:yahoo,项目名称:elide,代码行数:78,代码来源:SwaggerBuilder.java


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