private static String getAccept(Operation operation) {
    String accepts = null;
    String defaultContentType = "application/json";
    if (operation.getProduces() != null && !operation.getProduces().isEmpty()) {
      StringBuilder sb = new StringBuilder();
      for (String produces : operation.getProduces()) {
        if (defaultContentType.equalsIgnoreCase(produces)) {
          accepts = defaultContentType;
          break;
        } else {
          if (sb.length() > 0) {
            sb.append(",");
          }
          sb.append(produces);
        }
      }
      if (accepts == null) {
        accepts = sb.toString();
      }
    } else {
      accepts = defaultContentType;
    }

    return accepts;
  }
Exemplo n.º 2
0
  public Operation filterOperation(
      SwaggerSpecFilter filter,
      Operation op,
      ApiDescription api,
      Map<String, List<String>> params,
      Map<String, String> cookies,
      Map<String, List<String>> headers) {
    Operation clonedOperation =
        new Operation()
            .summary(op.getSummary())
            .description(op.getDescription())
            .operationId(op.getOperationId())
            .schemes(op.getSchemes())
            .consumes(op.getConsumes())
            .produces(op.getProduces())
            .tags(op.getTags())
            .externalDocs(op.getExternalDocs())
            .vendorExtensions(op.getVendorExtensions())
            .deprecated(op.isDeprecated());

    List<Parameter> clonedParams = new ArrayList<Parameter>();
    if (op.getParameters() != null) {
      for (Parameter param : op.getParameters()) {
        if (filter.isParamAllowed(param, op, api, params, cookies, headers)) {
          clonedParams.add(param);
        }
      }
    }
    clonedOperation.setParameters(clonedParams);
    clonedOperation.setSecurity(op.getSecurity());
    clonedOperation.setResponses(op.getResponses());

    return clonedOperation;
  }