public List<ApiDescription> read(RequestMappingContext outerContext) {
    RequestMappingInfo requestMappingInfo = outerContext.getRequestMappingInfo();
    HandlerMethod handlerMethod = outerContext.getHandlerMethod();
    PatternsRequestCondition patternsCondition = requestMappingInfo.getPatternsCondition();
    ApiSelector selector = outerContext.getDocumentationContext().getApiSelector();

    List<ApiDescription> apiDescriptionList = newArrayList();
    for (String path : matchingPaths(selector, patternsCondition)) {
      String methodName = handlerMethod.getMethod().getName();
      RequestMappingContext operationContext = outerContext.copyPatternUsing(path);

      List<Operation> operations = operationReader.read(operationContext);
      ApiDescriptionBuilder descriptionBuilder = operationContext.apiDescriptionBuilder();
      descriptionBuilder.operations(operations);
      operationContext.apiDescriptionBuilder().operations(operations);
      operationContext
          .apiDescriptionBuilder()
          .pathDecorator(
              pluginsManager.decorator(new PathContext(outerContext, from(operations).first())));
      descriptionBuilder.path(path);
      descriptionBuilder.description(methodName);
      descriptionBuilder.hidden(false);
      apiDescriptionList.add(descriptionBuilder.build());
    }
    return apiDescriptionList;
  }
  public List<ApiDescription> read(RequestMappingContext outerContext) {
    RequestMappingInfo requestMappingInfo = outerContext.getRequestMappingInfo();
    HandlerMethod handlerMethod = outerContext.getHandlerMethod();
    PatternsRequestCondition patternsCondition = requestMappingInfo.getPatternsCondition();
    ApiSelector selector = outerContext.getDocumentationContext().getApiSelector();
    PathProvider pathProvider = outerContext.getDocumentationContext().getPathProvider();

    List<ApiDescription> apiDescriptionList = newArrayList();
    for (String pattern : matchingPaths(selector, patternsCondition)) {
      String cleanedRequestMappingPath = sanitizeRequestMappingPattern(pattern);
      String path = pathProvider.getOperationPath(cleanedRequestMappingPath);
      String methodName = handlerMethod.getMethod().getName();
      RequestMappingContext operationContext =
          outerContext.copyPatternUsing(cleanedRequestMappingPath);
      PathMappingAdjuster adjuster =
          new PathMappingAdjuster(operationContext.getDocumentationContext());
      apiDescriptionList.add(
          new ApiDescriptionBuilder(outerContext.operationOrdering())
              .path(adjuster.adjustedPath(path))
              .description(methodName)
              .operations(operationReader.read(operationContext))
              .hidden(false)
              .build());
    }
    return apiDescriptionList;
  }
 /**
  * Stores the matching pattern into the request so it can be later used by the {@code
  * PathVariableLookupEvaluationContext} if necessary.
  */
 @Override
 protected RequestMappingInfo getMatchingMapping(
     RequestMappingInfo info, HttpServletRequest request) {
   RequestMappingInfo matchingMapping = super.getMatchingMapping(info, request);
   if (matchingMapping != null) {
     Set<String> patterns = matchingMapping.getPatternsCondition().getPatterns();
     if (patterns.size() != 1) {
       throw new IllegalStateException(
           "Expected 1 matching pattern for request: " + request.getServletPath());
     }
     String pattern = patterns.iterator().next();
     AccessExpressionRequestCondition cond =
         (AccessExpressionRequestCondition) info.getCustomCondition();
     request.setAttribute(PATTERN_ATTR_PREFIX + cond.getId(), pattern);
   }
   return matchingMapping;
 }
 private String[] getEndpointPatterns(String path, RequestMappingInfo mapping) {
   String patternPrefix = StringUtils.hasText(this.prefix) ? this.prefix + path : path;
   Set<String> defaultPatterns = mapping.getPatternsCondition().getPatterns();
   if (defaultPatterns.isEmpty()) {
     return new String[] {patternPrefix, patternPrefix + ".json"};
   }
   List<String> patterns = new ArrayList<String>(defaultPatterns);
   for (int i = 0; i < patterns.size(); i++) {
     patterns.set(i, patternPrefix + patterns.get(i));
   }
   return patterns.toArray(new String[patterns.size()]);
 }
 /**
  * Compares "this" info (i.e. the current instance) with another info in the context of a request.
  *
  * <p>Note: it is assumed both instances have been obtained via {@link
  * #getMatchingInfo(HttpServletRequest)} to ensure they have conditions with content relevant to
  * current request.
  */
 public int compareTo(RequestMappingInfo other, HttpServletRequest request) {
   int result = patternsCondition.compareTo(other.getPatternsCondition(), request);
   if (result != 0) {
     return result;
   }
   result = paramsCondition.compareTo(other.getParamsCondition(), request);
   if (result != 0) {
     return result;
   }
   result = headersCondition.compareTo(other.getHeadersCondition(), request);
   if (result != 0) {
     return result;
   }
   result = consumesCondition.compareTo(other.getConsumesCondition(), request);
   if (result != 0) {
     return result;
   }
   result = producesCondition.compareTo(other.getProducesCondition(), request);
   if (result != 0) {
     return result;
   }
   result = methodsCondition.compareTo(other.getMethodsCondition(), request);
   if (result != 0) {
     return result;
   }
   result = customCondition.compareTo(other.customCondition, request);
   if (result != 0) {
     return result;
   }
   return 0;
 }
  @Override
  protected RequestMappingInfo getMappingForMethod(Method method, Class<?> handlerType) {

    RequestMappingInfo defaultMapping = super.getMappingForMethod(method, handlerType);
    if (defaultMapping == null) {
      return null;
    }

    Set<String> defaultPatterns = defaultMapping.getPatternsCondition().getPatterns();
    String[] patterns = new String[defaultPatterns.size()];

    int i = 0;
    for (String pattern : defaultPatterns) {
      patterns[i] = getPath(pattern);
      paths.add(pattern);
      i++;
    }
    PatternsRequestCondition patternsInfo = new PatternsRequestCondition(patterns);

    ParamsRequestCondition paramsInfo = defaultMapping.getParamsCondition();
    if (!approvalParameter.equals(OAuth2Utils.USER_OAUTH_APPROVAL)
        && defaultPatterns.contains("/oauth/authorize")) {
      String[] params = new String[paramsInfo.getExpressions().size()];
      Set<NameValueExpression<String>> expressions = paramsInfo.getExpressions();
      i = 0;
      for (NameValueExpression<String> expression : expressions) {
        String param = expression.toString();
        if (OAuth2Utils.USER_OAUTH_APPROVAL.equals(param)) {
          params[i] = approvalParameter;
        } else {
          params[i] = param;
        }
        i++;
      }
      paramsInfo = new ParamsRequestCondition(params);
    }

    RequestMappingInfo mapping =
        new RequestMappingInfo(
            patternsInfo,
            defaultMapping.getMethodsCondition(),
            paramsInfo,
            defaultMapping.getHeadersCondition(),
            defaultMapping.getConsumesCondition(),
            defaultMapping.getProducesCondition(),
            defaultMapping.getCustomCondition());
    return mapping;
  }
 @Override
 protected void handleMatch(
     RequestMappingInfo info, String lookupPath, HttpServletRequest request) {
   super.handleMatch(info, lookupPath, request);
   AccessExpressionRequestCondition c =
       (AccessExpressionRequestCondition) info.getCustomCondition();
   if (!c.isAuthorized(request)) {
     throw new AccessDeniedException(
         "Authentication does not "
             + "match access expression '"
             + c.getExpression().getExpressionString()
             + "'");
   }
 }
 private RequestMappingInfo withNewPatterns(RequestMappingInfo mapping, String[] patternStrings) {
   PatternsRequestCondition patterns =
       new PatternsRequestCondition(
           patternStrings, null, null, useSuffixPatternMatch(), useTrailingSlashMatch(), null);
   return new RequestMappingInfo(
       patterns,
       mapping.getMethodsCondition(),
       mapping.getParamsCondition(),
       mapping.getHeadersCondition(),
       mapping.getConsumesCondition(),
       mapping.getProducesCondition(),
       mapping.getCustomCondition());
 }