swagger-core icon indicating copy to clipboard operation
swagger-core copied to clipboard

OpenAPIExtension's are not loaded by swagger-gradle-plugin

Open aharin opened this issue 5 years ago • 1 comments

swagger-gradle-plugin does not load io.swagger.v3.jaxrs2.ext.OpenAPIExtension classes.

The code in io.swagger.v3.jaxrs2.ext.OpenAPIExtensions uses ServiceLoader.load(OpenAPIExtension.class) to load extensions. The problem is that ServiceLoader uses Thread.currentThread().getContextClassLoader() when a ClassLoader is not specified which cannot see the META-INF\services files from within a gradle plugin.

Using ServiceLoader.load(OpenAPIExtension.class, OpenAPIExtensions.class.getClassLoader()) should load services correctly.

aharin avatar Oct 29 '20 18:10 aharin

bump

guai avatar Feb 25 '22 09:02 guai

I, too, am hitting this particular issue. I am attempting to use the Gradle plugin as a means of auto-generating the spec in order to provide an API diff on PRs. We use an OpenAPIExtension as a means of parsing our custom auth annotations and adding both the associated ApiResponse objects and the security scheme to the operation.

Being unable to generate the spec via the Gradle plugin means that diffing our API spec requires booting our Java application, querying the endpoint, and then generating a diff. Ultimately, it wastes several precious CI minutes on every PR commit's status checks.

thefirstofthe300 avatar Mar 04 '24 20:03 thefirstofthe300