openapi-tools / swagger-maven-plugin

Maven plugin to activate the Swagger Core library to generate OpenAPI documentation.
MIT License
70 stars 45 forks source link

Running plugin returns the error "Scanner SubTypesScanner was not configured" #96

Open rujiel opened 2 years ago

rujiel commented 2 years ago

Hello, I'm trying to set up automatic register of resources with this plugin, but having some difficulty getting it to work with Tomcat. When running mvn verify I'm getting the cryptic error "Scanner SubTypesScanner was not configured". It sounds like something is exploding when trying to use reflection.

I am currently trying with version 2.1.6 of the plugin. For version 1 of the plugin and swagger, the plugin ran properly but it outputted a swagger.json that was nearly empty, so I'm trying v2. I'm using JDK 17, here are the important parts of my pom and my classes, am I doing something majorly wrong?

A couple other questions


    <dependency>
        <groupId>io.swagger.core.v3</groupId>
        <artifactId>swagger-jaxrs2</artifactId>
        <version>2.2.0</version>
    </dependency>

  <plugin>
    <groupId>io.openapitools.swagger</groupId>
    <artifactId>swagger-maven-plugin</artifactId>
    <version>2.1.6</version>
    <configuration>
      <resourcePackages>
        <resourcePackage>org.xyz.boundary</resourcePackage>
      </resourcePackages>
      <outputDirectory>${basedir}/target/</outputDirectory>
      <outputFilename>swagger</outputFilename>
      <outputFormats>JSON</outputFormats>
      <prettyPrint>true</prettyPrint>
    </configuration>
    <executions>
      <execution>
        <goals>
          <goal>generate</goal>
        </goals>
      </execution>
    </executions>
  </plugin>

My resource

    @Path("/test")
    @Tag(name = "test", description = "test")
    public class TestResource {
        @GET
        @Operation(summary = "do ting")
        @Produces("application/json")
        public ThingDO getThing() {
            return new ThingDO("testy");
        }
    }

Application config

    @ApplicationPath("/rs")
    public class ApplicationConfig extends Application {
        public ApplicationConfig(@Context ServletConfig config) {
            OpenAPI bc = new OpenAPI();
            Info info = new Info()
                .title("Test")
                .description("better")
                .contact(new Contact().email("hello@hello.com"))
                .version("1.0");
            bc.info(info);
            SwaggerConfiguration oasConfig = new SwaggerConfiguration()
                .openAPI(bc)
                .prettyPrint(true)
                .resourcePackages(Set.of("org.xyz.boundary"));
            try {
                new JaxrsOpenApiContextBuilder()
    //                .servletConfig(servletConfig)
                    .application(this)
                    .openApiConfiguration(oasConfig)
                    .buildContext(true);
            } catch (OpenApiConfigurationException e) {
                throw new RuntimeException(e.getMessage(), e);
            }
        }
    }
amirgalor-gong commented 2 years ago

I'm getting similar issue with the about the same configuration

rujiel commented 2 years ago

FWIW I wound up getting openapi to work by not using the plugin, switching to tomee microprofile and including it:

<dependency>
  <groupId>org.eclipse.microprofile.openapi</groupId>
  <artifactId>microprofile-openapi-api</artifactId>
  <version>3.0</version>
</dependency>

From there, the /openapi endpoint sends back a yaml file, and swagger ui works once I set that address for it.

langecode commented 2 years ago

I’ll tale a look as soon as possible. Sounds like some dependencies needs updating. The purpose of the plug-in is a compile time generation of the OpenAPI specification. If you want to fetch it dynamically at runtime the plug-in won’t do you much good. It is pretty much just a wrapper around the Swagger library to trigger it at build time from Maven.

Kiiv commented 1 year ago

Same problem here, the plugin is not usable for me at the moment.

JonasCir commented 1 year ago

Same here:

<plugin>
    <groupId>io.openapitools.swagger</groupId>
    <artifactId>swagger-maven-plugin</artifactId>
    <version>2.1.6</version>
    <executions>
        <execution>
            <goals>
                <goal>generate</goal>
            </goals>
        </execution>
    </executions>
    <dependencies>
        <dependency>
            <groupId>io.swagger.core.v3</groupId>
            <artifactId>swagger-jaxrs2</artifactId>
            <version>2.1.13</version>
        </dependency>
    </dependencies>
</plugin>

Stacktrace is:

    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:375)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:351)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:215)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:171)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:163)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:294)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:960)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:293)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:196)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:77)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:568)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
Caused by: org.apache.maven.plugin.PluginExecutionException: Execution generate-swagger of goal io.openapitools.swagger:swagger-maven-plugin:2.1.6:generate failed: Scanner SubTypesScanner was not configured
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:148)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:370)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:351)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:215)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:171)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:163)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:294)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:960)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:293)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:196)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:77)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:568)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
Caused by: org.reflections.ReflectionsException: Scanner SubTypesScanner was not configured
    at org.reflections.Store.get (Store.java:39)
    at org.reflections.Store.get (Store.java:61)
    at org.reflections.Store.get (Store.java:46)
    at org.reflections.Store.getAll (Store.java:93)
    at org.reflections.Reflections.getSubTypesOf (Reflections.java:404)
    at io.openapitools.swagger.JaxRSScanner.applicationInstance (JaxRSScanner.java:44)
    at io.openapitools.swagger.GenerateMojo.resolveApplication (GenerateMojo.java:152)
    at io.openapitools.swagger.GenerateMojo.execute (GenerateMojo.java:124)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:370)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:351)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:215)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:171)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:163)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:294)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:960)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:293)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:196)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:77)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:568)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
ashonline commented 1 year ago

I had this exact issue with v2.1.6 of the plugin and resolved it by dropping down to v2.1.5.

CarstenWickner commented 6 months ago

I encountered the same issue here.

This is a known limitation of the reflections library. One could change the way it is being used (just different configuration) or even better: replace the unmaintained reflections library with classgraph. I've created https://github.com/openapi-tools/swagger-maven-plugin/pull/119 to make that change.

With that new version of the plugin, the Swagger generation works like a charm.