Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When used in a Quarkus project in dev mode, reading spec from a resource url fails because of differing classloaders #1968

Open
mimkorn opened this issue Aug 29, 2023 · 0 comments

Comments

@mimkorn
Copy link

mimkorn commented Aug 29, 2023

Hi!

In our quarkus project we call OpenApiInteractionValidator.createForSpecificationUrl("/META-INF/openapi.yaml")... however, deep down in io.swagger.v3.parser.util.ClasspathHelper there's a call ClasspathHelper.class.getResourceAsStream(file); which gives a null InputStream. However, when debugging on that step and running with Thread.currentThread().getContextClassLoader(); instead, the file is found. I checked the two class loaders and they are different:

  • Quarkus Base Runtime ClassLoader: DEV
  • Quarkus Runtime ClassLoader: DEV restart no:0

In Quarkus documentation

The recommended approach is to get it by calling the Thread.currentThread().getContextClassLoader() method

Current impact is that debugging the application is unavailable, if code execution needs to use this part of your library.

Can we request a change in this library on how the classloader is picked, to make it compatible with Quarkus? Specifically, can we add another if (inputStream == null) and another option like: Thread.currentThread().getContextClassLoader().getResourceAsStream(file)?

Are there any concerns with making this change or any other preferred solutions?

Thank you for your consideration.

mimkorn pushed a commit to mimkorn/swagger-parser that referenced this issue Aug 29, 2023
This commit adds a fallback to `Thread.currentThread().getContextClassLoader().getResourceAsStream(file)` in the `ClasspathHelper` class.

Previously, if the `ClasspathHelper.class.getResourceAsStream(file)` and `ClassLoader.getSystemResourceAsStream(file)` methods returned `null`, no further attempts were made to load the resource, which caused issues in Quarkus applications in dev mode.

This commit adds an additional fallback to `Thread.currentThread().getContextClassLoader().getResourceAsStream(file)` to improve compatibility with the Quarkus class loading model.

Related Issue: swagger-api#1968
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant