-
Notifications
You must be signed in to change notification settings - Fork 533
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
OpenAPIV3Parser#getExtensions() not finding extensions on OSGi #1003
Comments
Hi, please provide us with a PR and a failing test where we can see what you mean. Thanks |
This test would fail for a v2 swagger.json spec:
Problem is where to place that test. OpenAPIV3ParserTest does not have any loadable extension on its classpath anyway. Are there any tests actually loading extensions? Thanks |
Hi, can you place it at swagger-parser module, and test? what do you mean here: |
In order to the new version to work with OSGi you need to install a bundle providing an OSGi ServiceLoader Mediator implementation. The one that I know is Aries SPI Fly. |
I propose #1068 for your review. The unit test is not great but at least it verifies that both classloaders are given a chance to provide extensions. This was separately tested in an OSGi environment. |
OpenAPIV3Parser#getExtensions() not finding extensions on OSGi #1003
closed by #1068. |
@fmoussallam: I have the feeling there is the exact same issue with swagger-parser/modules/swagger-parser/src/main/java/io/swagger/parser/OpenAPIParser.java Lines 41 to 51 in 0a4ed0b
Can you confirm this? |
Humm, definitely looks like the same issue. I was not aware OpenAPIParser was upward compatible with V3 (which I find a little bit confusing I have to say) |
@fmoussallam: is this also a problem in an OSGi context? Do you want to push a similar patch for that as well? |
Sure will do. I would also want to submit another PR for #997 which is trivial. Is that ok? |
…r-api#1003 (Applying same treatment to OpenAPIParser)
OpenAPIV3Parser#getExtensions() not finding extensions on OSGi #1003. Applying same fix to OpenAPIParser
I am using the swagger-parser-v3 library from within an OSGi bundle.
The issue I am facing is that the ServiceLoader.load(SwaggerParserExtension.class) mechanism uses the current thread's class loader (see https://docs.oracle.com/javase/8/docs/api/java/util/ServiceLoader.html#load-java.lang.Class-).
With that default behavior, getExtensions() does not return anything, and I can't parse v2 specifications.
I can workaround this by forcing the current thread classloader to SwaggerParserExtension.getClass().getClassLoader() but that is ugly.
Would it be possible to add a ParseOption to allow selecting the class loader?
Thank you
The text was updated successfully, but these errors were encountered: