raml-tester icon indicating copy to clipboard operation
raml-tester copied to clipboard

use it to validate real requests?

Open nidi3 opened this issue 9 years ago • 3 comments

nidi3 avatar Aug 05 '15 21:08 nidi3

Is this to say that it cannot validate real request? Because I tried and I cannot make it work (with JAX-RS). I just cannot figure out how to do it. What is assumingBaseUri for?

ddidier avatar Nov 27 '15 11:11 ddidier

With "real" I mean requests during the productive runtime of an application, not in tests. This issue is about special support/documentation for this, there's no reason it shouldn't work right now.

There are probably more JAX-RS specific possibilities, but the simplest thing that should work would be a ServletFilter along these lines:

public class RamlFilter implements Filter {
    private RamlDefinition api;

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        api = RamlLoaders.fromClasspath(getClass()).load("api.raml");
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
                         throws IOException, ServletException {
        final RamlReport report = api.testAgainst(request, response, chain);
        //do something with the report
    }

}

nidi3 avatar Nov 27 '15 12:11 nidi3

Or you could use https://github.com/nidi3/raml-tester-proxy. It's a proxy that sits between the client and the server and logs all requests that are not conforming to the RAML.

nidi3 avatar Nov 27 '15 12:11 nidi3