Relative $refs not being loaded when running as a jar?

Issue #231 resolved
Alex Stevens created an issue

Hi all,

I've having difficulty getting my OpenAPI spec file to load into my API. I've wrapped the code from the request / response validation example in a framework jar - which is Pom-ed into my API and consumed by adding an OpenApiValidatorConfiguration and some configuration in the resources/application.properties file (the filename).

In this library, the following code executes to read the OpenAPI spec:

  LevelResolver resolver = SpringMVCLevelResolverFactory.create();
  Builder openApiInterationValidatorBuilder = OpenApiInteractionValidator
          .createFor(configuration.filename)
          .withLevelResolver(resolver);

In this instance configuration.filename is set to api.yaml and has a $ref: getCustomer-schema.json in it. However, when this runs, it seems to be able to load the main spec file from the classpath, however relative references fail.

So, my class path is C:/Users/stevensa/Documents/git/myApi/target/myApplication-1.0-SNAPSHOT.jar (as it is complied into a .jar and is being run as java -jar myApplication-1.0-SNAPSHOT) and it seems to be loading the spec file from within the jar OK - but not the relative references, as they fail:

2019-08-16 16:19:21.378  WARN 10740 --- [ost-startStop-1] io.swagger.v3.parser.OpenAPIV3Parser
: Exception while reading:

java.lang.RuntimeException: Unable to load RELATIVE ref: ./getCustomer-schema.json path: C:\Users\stevensa\Documents\git\myApplication
        at io.swagger.v3.parser.util.RefUtils.readExternalRef(RefUtils.java:212) ~[swagger-parser-v3-2.0.13.jar!/:2.0.13]

It looks like the relative path resolution is looking for the referenced paths on the jar’s path, not being discovered from inside the compiled jar like the initial spec file is…

It doesn’t help either if I move the specs into the resources

Any help as this is blocking an important project..

Comments (6)

  1. Sven Döring

    There is no release with that fix.

    Could you try it at your project by using the current swagger-parser snapshot?

    io.swagger.parser.v3:swagger-parser:2.0.14-SNAPSHOT

  2. Inaie Ignacio

    Sven we tried that but the new version has some breaking changes that doesnt work with swagger-request-validator

    The 2.0.14 has being released now, can we upgrade it on swagger-request-validator ?

  3. James Navin

    The latest version of swagger-request-validator now uses v2.0.20 of the parser. Please re-open this issue if the problem is still present.

  4. Log in to comment