Search in sources :

Example 51 with Parameter

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());
}
Also used : lombok.val(lombok.val) CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) ReadOperation(org.springframework.boot.actuate.endpoint.annotation.ReadOperation) AuditTrailExecutionPlan(org.apereo.cas.audit.AuditTrailExecutionPlan) Date(java.util.Date) Endpoint(org.springframework.boot.actuate.endpoint.annotation.Endpoint) MediaType(org.springframework.http.MediaType) lombok.val(lombok.val) Set(java.util.Set) Beans(org.apereo.cas.configuration.support.Beans) AuditActionContext(org.apereo.inspektr.audit.AuditActionContext) WriteOperation(org.springframework.boot.actuate.endpoint.annotation.WriteOperation) StringUtils(org.apache.commons.lang3.StringUtils) Collectors(java.util.stream.Collectors) ZoneId(java.time.ZoneId) BaseCasActuatorEndpoint(org.apereo.cas.web.BaseCasActuatorEndpoint) Parameter(io.swagger.v3.oas.annotations.Parameter) Operation(io.swagger.v3.oas.annotations.Operation) ObjectProvider(org.springframework.beans.factory.ObjectProvider) LocalDate(java.time.LocalDate) Nullable(org.springframework.lang.Nullable) Selector(org.springframework.boot.actuate.endpoint.annotation.Selector) Date(java.util.Date) LocalDate(java.time.LocalDate) ReadOperation(org.springframework.boot.actuate.endpoint.annotation.ReadOperation) ReadOperation(org.springframework.boot.actuate.endpoint.annotation.ReadOperation) WriteOperation(org.springframework.boot.actuate.endpoint.annotation.WriteOperation) Operation(io.swagger.v3.oas.annotations.Operation)

Example 52 with Parameter

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());
}
Also used : lombok.val(lombok.val) ImmutableAssertion(org.apereo.cas.validation.ImmutableAssertion) WriteOperation(org.springframework.boot.actuate.endpoint.annotation.WriteOperation) ReadOperation(org.springframework.boot.actuate.endpoint.annotation.ReadOperation) WriteOperation(org.springframework.boot.actuate.endpoint.annotation.WriteOperation) Operation(io.swagger.v3.oas.annotations.Operation)

Example 53 with Parameter

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);
        }
    }
}
Also used : HashMap(java.util.HashMap) ClassResourceInfo(org.apache.cxf.jaxrs.model.ClassResourceInfo) ArrayList(java.util.ArrayList) Operation(io.swagger.v3.oas.models.Operation) ApiResponse(io.swagger.v3.oas.models.responses.ApiResponse) Parameter(io.swagger.v3.oas.models.parameters.Parameter) OperationResourceInfo(org.apache.cxf.jaxrs.model.OperationResourceInfo) Tag(io.swagger.v3.oas.models.tags.Tag) HashMap(java.util.HashMap) Map(java.util.Map) HttpMethod(io.swagger.v3.oas.models.PathItem.HttpMethod) Pair(org.apache.commons.lang3.tuple.Pair)

Example 54 with Parameter

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;
}
Also used : List(java.util.List) Matcher(java.util.regex.Matcher) Map(java.util.Map) Parameter(io.swagger.v3.oas.models.parameters.Parameter) RouterFactoryException(io.vertx.ext.web.api.contract.RouterFactoryException) Optional(java.util.Optional) HashMap(java.util.HashMap) Pattern(java.util.regex.Pattern) Collectors(java.util.stream.Collectors) Matcher(java.util.regex.Matcher) RouterFactoryException(io.vertx.ext.web.api.contract.RouterFactoryException) Parameter(io.swagger.v3.oas.models.parameters.Parameter) Map(java.util.Map) HashMap(java.util.HashMap)

Example 55 with Parameter

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;
    }
}
Also used : Parameter(io.swagger.v3.oas.models.parameters.Parameter)

Aggregations

Parameter (io.swagger.v3.oas.models.parameters.Parameter)48 Test (org.testng.annotations.Test)39 Operation (io.swagger.v3.oas.models.Operation)28 Operation (io.swagger.v3.oas.annotations.Operation)27 lombok.val (lombok.val)26 OpenAPI (io.swagger.v3.oas.models.OpenAPI)20 Map (java.util.Map)17 ArrayList (java.util.ArrayList)16 ReadOperation (org.springframework.boot.actuate.endpoint.annotation.ReadOperation)15 OpenAPI3RequestValidationHandlerImpl (io.vertx.ext.web.api.contract.openapi3.impl.OpenAPI3RequestValidationHandlerImpl)14 Test (org.junit.Test)14 PathItem (io.swagger.v3.oas.models.PathItem)13 QueryParameter (io.swagger.v3.oas.models.parameters.QueryParameter)13 StringUtils (org.apache.commons.lang3.StringUtils)13 StringSchema (io.swagger.v3.oas.models.media.StringSchema)12 LinkedHashMap (java.util.LinkedHashMap)12 Parameter (io.swagger.v3.oas.annotations.Parameter)11 RequestParameters (io.vertx.ext.web.api.RequestParameters)11 HashMap (java.util.HashMap)11 Schema (io.swagger.v3.oas.models.media.Schema)10