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; }
public Operation operation(ObjectNode obj, String location, ParseResult result) { if (obj == null) { return null; } Operation output = new Operation(); ArrayNode array = getArray("tags", obj, false, location, result); List<String> tags = tagStrings(array, location, result); if (tags != null) { output.tags(tags); } String value = getString("summary", obj, false, location, result); output.summary(value); value = getString("description", obj, false, location, result); output.description(value); ObjectNode externalDocs = getObject("externalDocs", obj, false, location, result); ExternalDocs docs = externalDocs(externalDocs, location, result); output.setExternalDocs(docs); value = getString("operationId", obj, false, location, result); output.operationId(value); array = getArray("consumes", obj, false, location, result); if (array != null) { if (array.size() == 0) { output.consumes(Collections.<String>emptyList()); } else { Iterator<JsonNode> it = array.iterator(); while (it.hasNext()) { JsonNode n = it.next(); String s = getString(n, location + ".consumes", result); if (s != null) { output.consumes(s); } } } } array = getArray("produces", obj, false, location, result); if (array != null) { if (array.size() == 0) { output.produces(Collections.<String>emptyList()); } else { Iterator<JsonNode> it = array.iterator(); while (it.hasNext()) { JsonNode n = it.next(); String s = getString(n, location + ".produces", result); if (s != null) { output.produces(s); } } } } ArrayNode parameters = getArray("parameters", obj, false, location, result); output.setParameters(parameters(parameters, location, result)); ObjectNode responses = getObject("responses", obj, true, location, result); output.setResponses(responses(responses, location, result)); array = getArray("schemes", obj, false, location, result); if (array != null) { Iterator<JsonNode> it = array.iterator(); while (it.hasNext()) { JsonNode n = it.next(); String s = getString(n, location + ".schemes", result); if (s != null) { Scheme scheme = Scheme.forValue(s); if (scheme != null) { output.scheme(scheme); } } } } Boolean deprecated = getBoolean("deprecated", obj, false, location, result); if (deprecated != null) { output.setDeprecated(deprecated); } array = getArray("security", obj, false, location, result); List<SecurityRequirement> security = securityRequirements(array, location, result); if (security != null) { List<Map<String, List<String>>> ss = new ArrayList<>(); for (SecurityRequirement s : security) { if (s.getRequirements() != null && s.getRequirements().size() > 0) { ss.add(s.getRequirements()); } } output.setSecurity(ss); } // extra keys Set<String> keys = getKeys(obj); for (String key : keys) { if (key.startsWith("x-")) { output.setVendorExtension(key, extension(obj.get(key))); } else if (!OPERATION_KEYS.contains(key)) { result.extra(location, key, obj.get(key)); } } return output; }