springfox.documentation.builders.ApiListingBuilder Java Examples

The following examples show how to use springfox.documentation.builders.ApiListingBuilder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ServiceCombDocumentationSwaggerMapper.java    From spring-cloud-huawei with Apache License 2.0 5 votes vote down vote up
private Multimap<String, ApiListing> filteringApiListings(Map.Entry<String, ApiListing> entry) {
  Multimap map = HashMultimap.create();
  ApiListing apiListing = entry.getValue();
  ApiListingBuilder apiListingBuilder = new ApiListingBuilder(Ordering.from(Orderings.apiPathCompatator()));
  apiListingBuilder.apiVersion(apiListing.getApiVersion())
      .basePath(apiListing.getBasePath())
      .resourcePath(apiListing.getResourcePath())
      .produces(validateContentType(apiListing.getProduces()
          , MediaType.APPLICATION_JSON)) // 02-02 only keep one produces
      .consumes(validateContentType(apiListing.getConsumes()
          , MediaType.APPLICATION_JSON))// 02-03 only keep one consumers
      .host(apiListing.getHost())
      .protocols(apiListing.getProtocols())
      .securityReferences(apiListing.getSecurityReferences())
      .models(apiListing.getModels())
      .description(apiListing.getDescription())
      .position(apiListing.getPosition())
      .tags(apiListing.getTags());

  List<ApiDescription> apiDescriptions = apiListing.getApis();
  List<ApiDescription> newApiDescriptions = new ArrayList<>(apiDescriptions.size());
  apiDescriptions.forEach(apiDescription -> newApiDescriptions.add(
      new ApiDescriptionBuilder(Ordering.from(Orderings.positionComparator()))
          .path(validatePath(apiDescription.getPath()))
          .description(apiDescription.getDescription())
          // 02-01 only keep the first operation and convert operation.
          .operations(Arrays.asList(validateOperation(apiDescription.getOperations().get(0))))
          .hidden(apiDescription.isHidden()).build())
  );

  apiListingBuilder.apis(newApiDescriptions);
  map.put(entry.getKey(), apiListingBuilder.build());
  return map;
}
 
Example #2
Source File: DefaultControllerPlugin.java    From BlogManagePlatform with Apache License 2.0 5 votes vote down vote up
private void resolveController(ApiListingContext context, Class<?> controller) {
	if (findAnnotation(controller, Api.class) != null) {
		return;
	}
	ControllerInfo info = resolveNameAttribute(controller);
	if (info == null) {
		log.warn(StrUtil.concat(controller.getName(), "的信息未配置"));
	}
	ApiListingBuilder builder = context.apiListingBuilder();
	ReflectUtil.set(ApiListingBuilder.class, "tagNames", builder, Set.of(info.name));
	builder.consumes(Set.of(info.consumes));
	builder.produces(Set.of(info.produces));
}
 
Example #3
Source File: ApiListingJsonScanner.java    From Resource with GNU General Public License v3.0 4 votes vote down vote up
public Multimap<String, ApiListing> scan(ApiListingScanningContext context)
{
    final Multimap<String, ApiListing> apiListingMap = LinkedListMultimap.create();
    int position = 0;
    Map<ResourceGroup, List<RequestMappingContext>> requestMappingsByResourceGroup
        = context.getRequestMappingsByResourceGroup();
    Collection<ApiDescription> additionalListings = pluginsManager.additionalListings(context);
    Set<ResourceGroup> allResourceGroups = from(collectResourceGroups(additionalListings))
        .append(requestMappingsByResourceGroup.keySet())
        .toSet();

    List<SecurityReference> securityReferences = newArrayList();
    for (final ResourceGroup resourceGroup : sortedByName(allResourceGroups))
    {

        DocumentationContext documentationContext = context.getDocumentationContext();
        Set<String> produces = new LinkedHashSet<String>(documentationContext.getProduces());
        Set<String> consumes = new LinkedHashSet<String>(documentationContext.getConsumes());
        String host = documentationContext.getHost();
        Set<String> protocols = new LinkedHashSet<String>(documentationContext.getProtocols());
        Set<ApiDescription> apiDescriptions = newHashSet();

        Map<String, Model> models = new LinkedHashMap<String, Model>();
        List<RequestMappingContext> requestMappings = nullToEmptyList(
            requestMappingsByResourceGroup.get(resourceGroup));

        for (RequestMappingContext each : sortedByMethods(requestMappings))
        {//url
            Map<String, Model> knownModels = new HashMap<>();
            models.putAll(apiModelReader.read(each.withKnownModels(models)));

            apiDescriptions.addAll(apiDescriptionReader.read(each));
        }
        //
        models.putAll(ModelCache.getInstance().getKnownModels());

        List<ApiDescription> additional = from(additionalListings)
            .filter(and(
                belongsTo(resourceGroup.getGroupName()),
                onlySelectedApis(documentationContext)))
            .toList();
        apiDescriptions.addAll(additional);

        List<ApiDescription> sortedApis = from(apiDescriptions)
            .toSortedList(documentationContext.getApiDescriptionOrdering());
        Optional<String> o = longestCommonPath(sortedApis);
        String resourcePath = new ResourcePathProvider(resourceGroup)
            .resourcePath()
            .or(o)
            .orNull();

        PathProvider pathProvider = documentationContext.getPathProvider();
        String basePath = pathProvider.getApplicationBasePath();
        PathAdjuster adjuster = new PathMappingAdjuster(documentationContext);
        ApiListingBuilder apiListingBuilder = new ApiListingBuilder(context.apiDescriptionOrdering())
            .apiVersion(documentationContext.getApiInfo().getVersion())
            .basePath(adjuster.adjustedPath(basePath))
            .resourcePath(resourcePath)
            .produces(produces)
            .consumes(consumes)
            .host(host)
            .protocols(protocols)
            .securityReferences(securityReferences)
            .apis(sortedApis)
            .models(models)
            .position(position++)
            .availableTags(documentationContext.getTags());

        ApiListingContext apiListingContext = new ApiListingContext(
            context.getDocumentationType(),
            resourceGroup,
            apiListingBuilder);
        apiListingMap.put(resourceGroup.getGroupName(), pluginsManager.apiListing(apiListingContext));
    }
    return apiListingMap;
}