com.mangofactory.swagger.readers.ApiOperationReader Maven / Gradle / Ivy
package com.mangofactory.swagger.readers;
import com.google.common.collect.Lists;
import com.mangofactory.swagger.authorization.AuthorizationContext;
import com.mangofactory.swagger.configuration.SwaggerGlobalSettings;
import com.mangofactory.swagger.core.CommandExecutor;
import com.mangofactory.swagger.models.dto.Authorization;
import com.mangofactory.swagger.models.dto.Operation;
import com.mangofactory.swagger.models.dto.builder.OperationBuilder;
import com.mangofactory.swagger.models.dto.Parameter;
import com.mangofactory.swagger.models.dto.ResponseMessage;
import com.mangofactory.swagger.ordering.OperationPositionalOrdering;
import com.mangofactory.swagger.readers.operation.DefaultResponseMessageReader;
import com.mangofactory.swagger.readers.operation.OperationAuthReader;
import com.mangofactory.swagger.readers.operation.OperationDeprecatedReader;
import com.mangofactory.swagger.readers.operation.OperationHiddenReader;
import com.mangofactory.swagger.readers.operation.OperationHttpMethodReader;
import com.mangofactory.swagger.readers.operation.OperationImplicitParameterReader;
import com.mangofactory.swagger.readers.operation.OperationImplicitParametersReader;
import com.mangofactory.swagger.readers.operation.OperationNicknameReader;
import com.mangofactory.swagger.readers.operation.OperationNotesReader;
import com.mangofactory.swagger.readers.operation.OperationPositionReader;
import com.mangofactory.swagger.readers.operation.OperationResponseClassReader;
import com.mangofactory.swagger.readers.operation.OperationSummaryReader;
import com.mangofactory.swagger.readers.operation.RequestMappingReader;
import com.mangofactory.swagger.readers.operation.parameter.OperationParameterReader;
import com.mangofactory.swagger.scanners.RequestMappingContext;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.mvc.condition.RequestMethodsRequestCondition;
import org.springframework.web.servlet.mvc.method.RequestMappingInfo;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
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.Sets.*;
public class ApiOperationReader implements Command {
private static final Set allRequestMethods = new LinkedHashSet(Arrays.asList
(RequestMethod
.values()));
public static final OperationPositionalOrdering OPERATION_POSITIONAL_ORDERING = new OperationPositionalOrdering();
private Collection customAnnotationReaders;
public ApiOperationReader(Collection customAnnotationReaders) {
this.customAnnotationReaders = customAnnotationReaders == null
? Lists.newArrayList()
: customAnnotationReaders;
}
@SuppressWarnings("unchecked")
@Override
public void execute(RequestMappingContext outerContext) {
RequestMappingInfo requestMappingInfo = outerContext.getRequestMappingInfo();
HandlerMethod handlerMethod = outerContext.getHandlerMethod();
SwaggerGlobalSettings swaggerGlobalSettings = (SwaggerGlobalSettings) outerContext.get("swaggerGlobalSettings");
AuthorizationContext authorizationContext = (AuthorizationContext) outerContext.get("authorizationContext");
String requestMappingPattern = (String) outerContext.get("requestMappingPattern");
RequestMethodsRequestCondition requestMethodsRequestCondition = requestMappingInfo.getMethodsCondition();
Set responseMessages = newHashSet();
List operations = newArrayList();
Set requestMethods = requestMethodsRequestCondition.getMethods();
Set supportedMethods = requestMethods == null || requestMethods.isEmpty()
? allRequestMethods
: requestMethods;
List commandList = newArrayList();
commandList.add(new OperationHiddenReader());
commandList.add(new OperationAuthReader());
commandList.add(new OperationHttpMethodReader());
commandList.add(new OperationSummaryReader());
commandList.add(new OperationNotesReader());
commandList.add(new OperationResponseClassReader());
commandList.add(new OperationNicknameReader());
commandList.add(new OperationPositionReader());
commandList.add(new OperationParameterReader());
commandList.add(new OperationImplicitParametersReader());
commandList.add(new OperationImplicitParameterReader());
commandList.add(new OperationParameterRequestConditionReader());
commandList.add(new MediaTypeReader());
commandList.add(new DefaultResponseMessageReader());
commandList.add(new OperationDeprecatedReader());
commandList.addAll(customAnnotationReaders);
//Setup response message list
Integer currentCount = 0;
Boolean isHidden;
for (RequestMethod httpRequestMethod : supportedMethods) {
CommandExecutor