Wrong request path used in springmvc validation service

Issue #175 resolved
gschusterschitz created an issue

We're using version 1.5.1, as we have a Swagger 2.0 file to describe our REST API. In the class SwaggerRequestsValidationService (Methods buildRequest and validateResponse) the method

servletRequest.getServletPath()

is used. What is the reason for this? From our point of view this is wrong, as it returns the path configured in web.xml for the springmvc servlet, but not the real path of the REST call.

So the matching of paths within the swagger file always fails.

In my opinion the method

servletRequest.getPathInfo()

should be used.

I attached the fixed java source file. Is it possible to add this to patch 1.5.2?

Comments (6)

  1. Sven Döring

    With your suggested fix all the available integration tests - with a real web server - will fail as getPathInfo() returns null, e.g. the RestRequestValidationTest.

    So... Do you really have an issue (bug) and it is not working for you? Or is it just unpretty as Spring MVC does not conform the servlet expectations?

  2. gschusterschitz reporter

    Hi Sven!

    Thanks for the reply. I'm more or less wondering, how this could anywhere work, as getServletPath() will never return the full path in SpringMVC (v4.3). For us, it only returns the servlet (without context and path info).

    You're right, probably getPathInfo() somehow only works on our side, because we defined a swagger base path containing context and servlet, which seems to be ignored during validation. Referencing to the link you posted, in my opinion getRequestURI() should be the besser solution, when the validation matches the value with base path and path from swagger. However, I'll try to change our configuration, as it seems that in some circumstances getServletPath() should also return the path info, like in your setup.

    Thanks.

  3. Sven Döring

    The integration tests are done with SpringMVC v4.3.

    getRequestURI() can't be used either as this value is not URL decoded - /context/a+b will be returned as /context/a+b and not /context/a b.

    Can you share your configuration? Servlet container, a stripped OpenAPI (Swagger) definition, etc. I'll want to look into it to find a generic, plattform-independent solution.

  4. gschusterschitz reporter

    Our Application is deployed unter /rest, then the SpringMVC servlet is configured as:

        <servlet-mapping>
            <servlet-name>springmvc-v1</servlet-name>
            <url-pattern>/v1/*</url-pattern>
        </servlet-mapping>
    

    I guess the important parts of our Swagger are:

    {
      "swagger": "2.0",
      ...
      "basePath": "/rest/v1",
      "parameters": {
        "lang": {
          ...
        }
      }
      ...
      "paths": {
        "/{lang}/messages": {
          "get": {
             ...
          }
        }
      }
    }
    

    In our controller we use @RequestMapping(value = "/{language}/messages"), but as the interceptor for the swagger validation is executed before touching the controller, this shouldn't be important for the problem.

    So I guess, this is quite a common setup. Thanks in advance for any help, for now our patched class works just fine.

  5. Log in to comment