Errors thrown despite the spec being loaded

Issue #243 resolved
Former user created an issue

I think this is a benign bug but a nuisance nonetheless. Per getting started doc, I copy/pasted this and changed the constructor arg to use my openapi.yml (in src/main/resources). So my constructor looks like this:

    public OpenApiValidationConfig(@Value("classpath:openapi.yml") final Resource apiSpecification) throws IOException {
        final EncodedResource specResource = new EncodedResource(apiSpecification, "UTF-8");
        this.validationInterceptor = new OpenApiValidationInterceptor(specResource);
    }

When I startup the app I get a stack traces indicating that it couldn't read the resource. Tracing the code it looks like it's attempting to use the payload of the resource as the resource url. So it's trying to load a resource named "openapi: 3.0.0\ninfo:\n . title: My Project Title..." which of course doesn't exist:

2019-10-17 18:15:46.504  INFO 86313 --- [           main] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 950 ms
2019-10-17 18:15:46.598  WARN 86313 --- [           main] io.swagger.v3.parser.OpenAPIV3Parser     : Exception while reading:

java.lang.RuntimeException: Could not find openapi: 3.0.0
info:
  title: My Project Title
...

But what's even more interesting is that despite the exception it appears to work. The application starts up successfully and the interceptor is validating the requests, etc.

Although response validation isn't working as expected - it's failing valid responses - but maybe that is related to the exception thrown?

Comments (3)

  1. James Navin

    That looks like a known issue. The way spec loading works via that ctor is it first attempts to load it as file/url, then falls back to reading it as an inline spec. The exception comes from the underlying parser lib and isn’t easy to silence from the swagger-request-validator lib.

    Two options:

    1. Change you logging config to turn off that logger; or
    2. (Recommended) There are now (as of v2.6.0) new methods on OpenApiInteractionValidator to create specifically from a file/url or an inline spec. If you use those you should get rid of the errors. It will require you to use the alternate ctor on OpenApiValidationInterceptor that takes a pre-configured OpenApiInteractionValidator instance.

    As for the validation problems - that seems like a separate issue. Perhaps raise a separate ticket for that?

  2. Sven Döring

    Yeah. I second that.

    Please raise an separate issue for the false positive response validation - incl. a rough example - and I will have a look at it.

  3. Log in to comment