Java Code Examples for org.eclipse.microprofile.openapi.models.parameters.Parameter#getName()

The following examples show how to use org.eclipse.microprofile.openapi.models.parameters.Parameter#getName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MergeUtil.java    From smallrye-open-api with Apache License 2.0 6 votes vote down vote up
/**
 * Merge two lists of Parameters. Parameters are a special case because they must be unique
 * by the name in 'in' each have
 * 
 * @param values1
 * @param values2
 */
private static List<Parameter> mergeParameterLists(List<Parameter> values1, List<Parameter> values2) {
    values1 = new ArrayList<>(values1);

    for (Parameter value2 : values2) {
        Parameter match = null;
        for (Parameter value1 : values1) {
            if (value1.getName() == null || !value1.getName().equals(value2.getName())) {
                continue;
            }
            if (value1.getIn() == null || !value1.getIn().equals(value2.getIn())) {
                continue;
            }

            match = value1;
            break;
        }
        if (match == null) {
            values1.add(value2);
        } else {
            mergeObjects(match, value2);
        }
    }
    return values1;
}
 
Example 2
Source File: ParameterProcessor.java    From smallrye-open-api with Apache License 2.0 4 votes vote down vote up
/**
 * Determine if this is an ignored parameter, per the MP+OAI specification in
 * {@link org.eclipse.microprofile.openapi.annotations.parameters.Parameter @Parameter}.
 *
 * Path parameters that do not have a corresponding path segment will be ignored.
 *
 * @param parameter
 *        the parameter to determine if ignored
 * @param resourceMethod
 *        the resource method to which the parameter may apply
 * @return true if the parameter should be ignored, false otherwise
 *
 * @see org.eclipse.microprofile.openapi.annotations.parameters.Parameter#name()
 * @see org.eclipse.microprofile.openapi.annotations.parameters.Parameter#in()
 */
static boolean isIgnoredParameter(Parameter parameter, AnnotationTarget resourceMethod) {
    String paramName = parameter.getName();
    In paramIn = parameter.getIn();

    if (paramIn == null) {
        /*
         * Per @Parameter JavaDoc, ignored when empty string (i.e., unspecified).
         * This may occur when @Parameter is specified without a matching JAX-RS
         * parameter annotation.
         */
        return true;
    }

    if (ParameterImpl.isHidden(parameter)) {
        return true;
    }

    /*
     * Name is REQUIRED unless it is a reference.
     */
    if ((paramName == null || paramName.trim().isEmpty()) && parameter.getRef() == null) {
        return true;
    }

    if (paramIn == In.PATH && !parameterInPath(paramName, parameter.getStyle(), fullPathOf(resourceMethod))) {
        return true;
    }

    if (paramIn == Parameter.In.HEADER && paramName != null) {
        switch (paramName.toUpperCase()) {
            case "ACCEPT":
            case "AUTHORIZATION":
            case "CONTENT-TYPE":
                return true;
            default:
                break;
        }
    }
    return false;
}
 
Example 3
Source File: ParameterProcessor.java    From smallrye-open-api with Apache License 2.0 4 votes vote down vote up
/**
 * Determine if this is an ignored parameter, per the MP+OAI specification in
 * {@link org.eclipse.microprofile.openapi.annotations.parameters.Parameter @Parameter}.
 *
 * Path parameters that do not have a corresponding path segment will be ignored.
 *
 * @param parameter
 *        the parameter to determine if ignored
 * @param resourceMethod
 *        the resource method to which the parameter may apply
 * @return true if the parameter should be ignored, false otherwise
 *
 * @see org.eclipse.microprofile.openapi.annotations.parameters.Parameter#name()
 * @see org.eclipse.microprofile.openapi.annotations.parameters.Parameter#in()
 */
static boolean isIgnoredParameter(Parameter parameter, AnnotationTarget resourceMethod) {
    String paramName = parameter.getName();
    In paramIn = parameter.getIn();

    if (paramIn == null) {
        /*
         * Per @Parameter JavaDoc, ignored when empty string (i.e., unspecified).
         * This may occur when @Parameter is specified without a matching Spring
         * parameter annotation.
         */
        return true;
    }

    if (ParameterImpl.isHidden(parameter)) {
        return true;
    }

    /*
     * Name is REQUIRED unless it is a reference.
     */
    if ((paramName == null || paramName.trim().isEmpty()) && parameter.getRef() == null) {
        return true;
    }

    if (paramIn == In.PATH && !parameterInPath(paramName, parameter.getStyle(), fullPathOf(resourceMethod))) {
        return true;
    }

    if (paramIn == Parameter.In.HEADER && paramName != null) {
        switch (paramName.toUpperCase()) {
            case "ACCEPT":
            case "AUTHORIZATION":
            case "CONTENT-TYPE":
                return true;
            default:
                break;
        }
    }
    return false;
}