Request validation for Multi-segment path parameters in Swagger 2.0

Issue #169 resolved
chandan singh created an issue

This issue is related to the below proposal and PR which has already been merged. https://bitbucket.org/atlassian/swagger-request-validator/issues/121/multi-segment-path-parameters-in-swagger

https://bitbucket.org/atlassian/swagger-request-validator/pull-requests/78/implementation-for-matching-dynamic-paths/diff

When i was trying to use the version 1.4.7 for request validation then i found that we need to do some further enhancement to achieve our purpose.

When we call the method validateRequest(@Nonnull final Request request) of the class SwaggerRequestResponseValidator then it fails to do the request validation in case of Multi-segment path parameters.

Below is my proposal to fix this problem:

Implement another overload function of validateRequest(@Nonnull final Request request, boleean hasDynamicRequestURI) where hasDynamicRequestURI flag indicate that whether we are going to do the request validation for Multi-segment path parameters.

@Nonnull
    public ValidationReport validateRequest(@Nonnull final Request request) {
                validateRequest(request, false)
}

@Nonnull
    public ValidationReport validateRequest(@Nonnull final Request request, boolean hasDynamicRequestURI) {
        requireNonNull(request, "A request is required");

        return validateOnApiOperation(
            request.getPath(),
            request.getMethod(),
            apiOperation -> requestValidator.validateRequest(request, apiOperation),
            (apiOperation, report) -> withWhitelistApplied(report, apiOperation, request, null), hasDynamicRequestURI);
    }

Then change the below logic in validateOnApiOperation method of SwaggerRequestResponseValidator class

private ValidationReport validateOnApiOperation(@Nonnull final String path,
                                                    @Nonnull final Request.Method method,
                                                    @Nonnull final Function<ApiOperation, ValidationReport> validationFunction,
                                                    @Nonnull final BiFunction<ApiOperation, ValidationReport, ValidationReport> whitelistingFunction, boolean hasDynamicRequestURI) {

        final ValidationReport.MessageContext context = ValidationReport.MessageContext.create()
                .withRequestPath(path)
                .withRequestMethod(method)
                .build();

       ApiOperationMatch apiOperationMatch        

        If(hasDynamicRequestURI){
              apiOperationMatch = apiOperationResolver.findApiOperation(path, method, ApiPath::matchesDynamicPath);
           } else {
              apiOperationMatch = apiOperationResolver.findApiOperation(path, method);
           }

Please provide your feedback on this. If you would be okay with this proposed change then i would create PR for the same.

Comments (5)

  1. James Navin

    Hi Chandan,

    The PR was closed due to lack of activity. Bitbucket doesn’t allow PRs to be re-opened, but you are more than welcome to raise a new PR.

    Looking back at the comments on that PR it seems one of the major points was around targeting against v1 vs v2. I am no longer accepting PRs against the v1 branch. Please ensure that your PR targets the current master so that it can be included in the v2 release train. If there are changes you depend on that are not present in v2 please feel free to either include them in your PR or to raise a separate PR with those changes.

    Thanks,

    James

  2. Log in to comment