use of io.swagger.v3.oas.models.parameters.Parameter in project cas by apereo.
the class AuditLogEndpoint method getAuditLog.
/**
* Gets Audit log for passed interval.
*
* @param interval - Interval subtracted from current time
* @return the auditlog
*/
@ReadOperation
@SuppressWarnings("JavaUtilDate")
@Operation(summary = "Provide a report of the audit log using a given interval", parameters = { @Parameter(name = "interval", description = "Accepts the duration syntax, such as PT1H") })
public Set<AuditActionContext> getAuditLog(@Selector final String interval) {
if (StringUtils.isBlank(interval)) {
val sinceDate = LocalDate.now(ZoneId.systemDefault()).minusDays(casProperties.getAudit().getEngine().getNumberOfDaysInHistory());
return auditTrailManager.getObject().getAuditRecordsSince(sinceDate);
}
val duration = Beans.newDuration(interval);
val sinceTime = new Date(new Date().getTime() - duration.toMillis());
val days = duration.toDays();
val sinceDate = LocalDate.now(ZoneId.systemDefault()).minusDays(days + 1);
return auditTrailManager.getObject().getAuditRecordsSince(sinceDate).stream().filter(a -> a.getWhenActionWasPerformed().after(sinceTime)).collect(Collectors.toSet());
}
use of io.swagger.v3.oas.models.parameters.Parameter in project cas by apereo.
the class CasReleaseAttributesReportEndpoint method releaseAttributes.
/**
* Method that accepts a JSON body through a POST method to receive user credentials and only returns a
* map of attributes released for the authenticated user.
*
* @param username - the username
* @param password - the password
* @param service - the service id
* @return - the map
*/
@WriteOperation
@Operation(summary = "Get collection of released attributes for the user and application", parameters = { @Parameter(name = "username", required = true), @Parameter(name = "password", required = true), @Parameter(name = "service", required = true) })
public Map<String, Object> releaseAttributes(final String username, final String password, final String service) {
val map = releasePrincipalAttributes(username, password, service);
val assertion = (ImmutableAssertion) map.get("assertion");
return Map.of("uid", username, "attributes", assertion.getPrimaryAuthentication().getPrincipal().getAttributes());
}
use of io.swagger.v3.oas.models.parameters.Parameter in project cxf by apache.
the class OpenApiCustomizer method customize.
public void customize(final OpenAPI oas) {
if (replaceTags || javadocProvider != null) {
Map<String, ClassResourceInfo> operations = new HashMap<>();
Map<Pair<String, String>, OperationResourceInfo> methods = new HashMap<>();
cris.forEach(cri -> {
cri.getMethodDispatcher().getOperationResourceInfos().forEach(ori -> {
String normalizedPath = getNormalizedPath(cri.getURITemplate().getValue(), ori.getURITemplate().getValue());
operations.put(normalizedPath, cri);
methods.put(Pair.of(ori.getHttpMethod(), normalizedPath), ori);
});
});
List<Tag> tags = new ArrayList<>();
oas.getPaths().forEach((pathKey, pathItem) -> {
Tag tag = null;
if (replaceTags && operations.containsKey(pathKey)) {
ClassResourceInfo cri = operations.get(pathKey);
tag = new Tag();
tag.setName(cri.getURITemplate().getValue().replaceAll("/", "_"));
if (javadocProvider != null) {
tag.setDescription(javadocProvider.getClassDoc(cri));
}
if (!tags.contains(tag)) {
tags.add(tag);
}
}
for (Map.Entry<HttpMethod, Operation> subentry : pathItem.readOperationsMap().entrySet()) {
if (replaceTags && tag != null) {
subentry.getValue().setTags(Collections.singletonList(tag.getName()));
}
Pair<String, String> key = Pair.of(subentry.getKey().name(), pathKey);
if (methods.containsKey(key) && javadocProvider != null) {
OperationResourceInfo ori = methods.get(key);
if (StringUtils.isBlank(subentry.getValue().getSummary())) {
subentry.getValue().setSummary(javadocProvider.getMethodDoc(ori));
}
if (subentry.getValue().getParameters() == null) {
List<Parameter> parameters = new ArrayList<>();
addParameters(parameters);
subentry.getValue().setParameters(parameters);
} else {
for (int i = 0; i < subentry.getValue().getParameters().size(); i++) {
if (StringUtils.isBlank(subentry.getValue().getParameters().get(i).getDescription())) {
subentry.getValue().getParameters().get(i).setDescription(javadocProvider.getMethodParameterDoc(ori, i));
}
}
addParameters(subentry.getValue().getParameters());
}
if (subentry.getValue().getResponses() != null && !subentry.getValue().getResponses().isEmpty()) {
ApiResponse response = subentry.getValue().getResponses().entrySet().iterator().next().getValue();
if (StringUtils.isBlank(response.getDescription())) {
response.setDescription(javadocProvider.getMethodResponseDoc(ori));
}
}
}
}
});
if (replaceTags && oas.getTags() != null) {
oas.setTags(tags);
}
}
}
use of io.swagger.v3.oas.models.parameters.Parameter in project vertx-web by vert-x3.
the class OpenAPI3PathResolver method solve.
public Pattern solve() {
// Filter parameters to get only path parameters
parameters = parameters.stream().filter(parameter -> parameter.getIn().equals("path")).collect(Collectors.toList());
if (ILLEGAL_PATH_MATCHER.matcher(oasPath).matches())
throw new RouterFactoryException("Path template not supported", RouterFactoryException.ErrorType.INVALID_SPEC_PATH);
Matcher parametersMatcher = OAS_PATH_PARAMETERS_PATTERN.matcher(oasPath);
if (!parameters.isEmpty() && parametersMatcher.find()) {
// Need to create a specific match pattern with path parameters and some string manipulation magic
StringBuilder regex = new StringBuilder();
int lastMatchEnd = 0;
boolean endSlash = oasPath.charAt(oasPath.length() - 1) == '/';
parametersMatcher.reset();
int i = 0;
while (parametersMatcher.find()) {
// Append constant string
regex.append(Pattern.quote(oasPath.substring(lastMatchEnd, parametersMatcher.start())));
lastMatchEnd = parametersMatcher.end();
String paramName = parametersMatcher.group(1);
Optional<Parameter> parameterOptional = parameters.stream().filter(p -> p.getName().equals(paramName)).findFirst();
if (parameterOptional.isPresent()) {
// For every parameter style I have to generate a different regular expression
Parameter parameter = parameterOptional.get();
String style = (parameter.getStyle() != null) ? parameter.getStyle().toString() : "simple";
boolean explode = (parameter.getExplode() != null) ? parameter.getExplode() : false;
boolean isObject = OpenApi3Utils.isParameterObjectOrAllOfType(parameter);
boolean isArray = OpenApi3Utils.isParameterArrayType(parameter);
String groupName = "p" + i;
if (style.equals("simple")) {
regex.append("(?<" + groupName + ">[^\\/\\;\\?\\:\\@\\&\\.\\\"\\<\\>\\#\\{\\}\\|\\\\\\^\\~\\[\\]\\`]*)?");
mappedGroups.put(groupName, paramName);
} else if (style.equals("label")) {
if (isObject && explode) {
Map<String, OpenApi3Utils.ObjectField> properties = OpenApi3Utils.solveObjectParameters(parameter.getSchema());
for (Map.Entry<String, OpenApi3Utils.ObjectField> entry : properties.entrySet()) {
groupName = "p" + i;
regex.append("\\.?" + entry.getKey() + "=(?<" + groupName + ">[^\\/\\;\\?\\:\\@\\=\\.\\&\\\"\\<\\>\\#\\{\\}\\|\\\\\\^\\~\\[\\]\\`]*)");
mappedGroups.put(groupName, entry.getKey());
i++;
}
} else {
regex.append("\\.?(?<" + groupName + ">[^\\/\\;\\?\\:\\@\\=\\&\\\"\\<\\>\\#\\{\\}\\|\\\\\\^\\~\\[\\]\\`]*)?");
mappedGroups.put(groupName, paramName);
}
} else if (style.equals("matrix")) {
if (isObject && explode) {
Map<String, OpenApi3Utils.ObjectField> properties = OpenApi3Utils.solveObjectParameters(parameter.getSchema());
for (Map.Entry<String, OpenApi3Utils.ObjectField> entry : properties.entrySet()) {
groupName = "p" + i;
regex.append("\\;" + entry.getKey() + "=(?<" + groupName + ">[^\\/\\;\\?\\:\\@\\=\\.\\&\\\"\\<\\>\\#\\{\\}\\|\\\\\\^\\~\\[\\]\\`]*)");
mappedGroups.put(groupName, entry.getKey());
i++;
}
} else if (isArray && explode) {
regex.append("(?<" + groupName + ">(?>;" + paramName + "=[^\\/\\;\\?\\:\\@\\&\\\"\\<\\>\\#\\{\\}\\|\\\\\\^\\~\\[\\]\\`]*)+)");
mappedGroups.put(groupName, paramName);
} else {
regex.append(";" + paramName + "=(?<" + groupName + ">[^\\/\\;\\?\\:\\@\\=\\&\\\"\\<\\>\\#\\{\\}\\|\\\\\\^\\~\\[\\]\\`]*)?");
mappedGroups.put(groupName, paramName);
}
}
} else {
throw RouterFactoryException.createSpecInvalidException("Missing parameter description for parameter name: " + paramName);
}
i++;
}
regex.append(Pattern.quote(oasPath.substring(lastMatchEnd, (endSlash) ? oasPath.length() - 1 : oasPath.length())));
if (endSlash)
regex.append(QUERY_REGEX_WITH_SLASH);
else
regex.append(QUERY_REGEX_WITHOUT_SLASH);
resolvedPattern = Pattern.compile(regex.toString());
} else {
resolvedPattern = Pattern.compile(Pattern.quote(oasPath));
}
return resolvedPattern;
}
use of io.swagger.v3.oas.models.parameters.Parameter in project vertx-web by vert-x3.
the class OpenApi3Utils method mergeParameters.
public static List<Parameter> mergeParameters(List<Parameter> operationParameters, List<Parameter> parentParameters) {
if (parentParameters == null && operationParameters == null) {
return new ArrayList<>();
} else if (operationParameters == null) {
return new ArrayList<>(parentParameters);
} else if (parentParameters == null) {
return new ArrayList<>(operationParameters);
} else {
List<Parameter> result = new ArrayList<>(operationParameters);
List<Parameter> actualParams = new ArrayList<>(operationParameters);
for (int i = 0; i < parentParameters.size(); i++) {
for (int j = 0; j < actualParams.size(); j++) {
Parameter parentParam = parentParameters.get(i);
Parameter actualParam = actualParams.get(j);
if (!(parentParam.getIn().equalsIgnoreCase(actualParam.getIn()) && parentParam.getName().equals(actualParam.getName())))
result.add(parentParam);
}
}
return result;
}
}
Aggregations