Errors thrown despite the spec being loaded
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)
-
-
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.
-
- changed status to resolved
Closing due to inactivity. Please feel free to reopen if needed.
- Log in to comment
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:
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 onOpenApiValidationInterceptor
that takes a pre-configuredOpenApiInteractionValidator
instance.As for the validation problems - that seems like a separate issue. Perhaps raise a separate ticket for that?