com.mangofactory.swagger.scanners.ApiListingScanner Maven / Gradle / Ivy
package com.mangofactory.swagger.scanners;
import com.google.common.base.Joiner;
import com.google.common.base.Splitter;
import com.google.common.collect.Lists;
import com.google.common.collect.Ordering;
import com.mangofactory.swagger.authorization.AuthorizationContext;
import com.mangofactory.swagger.configuration.SwaggerGlobalSettings;
import com.mangofactory.swagger.core.CommandExecutor;
import com.mangofactory.swagger.core.RequestMappingEvaluator;
import com.mangofactory.swagger.core.ResourceGroupingStrategy;
import com.mangofactory.swagger.models.ModelProvider;
import com.mangofactory.swagger.models.dto.builder.ApiListingBuilder;
import com.mangofactory.swagger.ordering.ApiDescriptionLexicographicalOrdering;
import com.mangofactory.swagger.paths.SwaggerPathProvider;
import com.mangofactory.swagger.readers.ApiDescriptionReader;
import com.mangofactory.swagger.readers.ApiModelReader;
import com.mangofactory.swagger.readers.Command;
import com.mangofactory.swagger.readers.MediaTypeReader;
import com.mangofactory.swagger.readers.operation.RequestMappingReader;
import com.mangofactory.swagger.models.dto.ApiDescription;
import com.mangofactory.swagger.models.dto.ApiListing;
import com.mangofactory.swagger.models.dto.Authorization;
import com.mangofactory.swagger.models.dto.Model;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import static com.google.common.collect.Lists.*;
import static com.google.common.collect.Maps.*;
import static com.google.common.collect.Sets.*;
public class ApiListingScanner {
private static final Logger log = LoggerFactory.getLogger(ApiListingScanner.class);
private String swaggerVersion = "1.2";
private Map> resourceGroupRequestMappings;
private SwaggerPathProvider swaggerPathProvider;
private SwaggerGlobalSettings swaggerGlobalSettings;
private AuthorizationContext authorizationContext;
private final ModelProvider modelProvider;
private Ordering apiDescriptionOrdering = new ApiDescriptionLexicographicalOrdering();
private Collection customAnnotationReaders;
private final RequestMappingEvaluator requestMappingEvaluator;
public ApiListingScanner(Map> resourceGroupRequestMappings,
SwaggerPathProvider swaggerPathProvider,
ModelProvider modelProvider,
AuthorizationContext authorizationContext,
Collection customAnnotationReaders,
RequestMappingEvaluator requestMappingEvaluator) {
this.resourceGroupRequestMappings = resourceGroupRequestMappings;
this.swaggerPathProvider = swaggerPathProvider;
this.authorizationContext = authorizationContext;
this.modelProvider = modelProvider;
this.customAnnotationReaders = customAnnotationReaders;
this.requestMappingEvaluator = requestMappingEvaluator;
}
@SuppressWarnings("unchecked")
public Map scan() {
Map apiListingMap = newHashMap();
int position = 0;
if (null == resourceGroupRequestMappings) {
log.error("resourceGroupRequestMappings should not be null.");
} else {
for (Map.Entry> entry : resourceGroupRequestMappings.entrySet()) {
ResourceGroup resourceGroup = entry.getKey();
Set produces = new LinkedHashSet(2);
Set consumes = new LinkedHashSet(2);
Set apiDescriptions = newHashSet();
List> readers = newArrayList();
readers.add(new MediaTypeReader());
readers.add(new ApiDescriptionReader(swaggerPathProvider, customAnnotationReaders, requestMappingEvaluator));
readers.add(new ApiModelReader(modelProvider));
Map models = new LinkedHashMap();
for (RequestMappingContext each : entry.getValue()) {
CommandExecutor