kongchen / swagger-maven-plugin

JAX-RS & SpringMVC supported maven build plugin, helps you generate Swagger JSON and API document in build phase.
http://kongchen.github.io/swagger-maven-plugin/
Apache License 2.0
761 stars 451 forks source link

Cannot generate swagger docs (SpringBoot Project) #864

Open fraballi opened 3 years ago

fraballi commented 3 years ago

Hi, great plugin, whereas one can generate swagger.json without exposing urls!

Does my endpoint requires spring-like annotations such as: RestController or Controller? Or can declare a @Component and the plugin will index @Api like annotations?

pom.xml

        <plugin>
                <groupId>com.github.kongchen</groupId>
                <artifactId>swagger-maven-plugin</artifactId>
                <version>1.8</version>
                <configuration>
                    <apiSources>
                        <apiSource>
                            <springmvc>true</springmvc>
                            <locations>
                                <location>com.fraballi.endpoint.MyEndpoint</location>
                            </locations>
                            <info>
                                <title>Endpoint Test</title>
                                <version>1.0</version>
                            </info>
                            <swaggerFileName>my-swagger</swaggerFileName>
                            <outputPath>${project.build.directory}/swagger/swagger.html</outputPath>
                            <swaggerDirectory>${project.build.directory}/swagger</swaggerDirectory>
                            <attachSwaggerArtifact>true</attachSwaggerArtifact>
                        </apiSource>
                    </apiSources>
                </configuration>
                <executions>
                    <execution>
                        <phase>compile</phase>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                    </execution>
                </executions>
      </plugin>

My endpoint:

@Component
@SvcServerEndpoint(id = "myEndpoint", basePath = "/decrypt")
public class MyEndpoint {
 ...

   @ApiOperation(value = "A message", notes = "Returns a message")
   @ApiResponses(value = { @ApiResponse(code = HttpStatus.SC_OK, message = "A message", response = MyResponse.class) })
   @ResponseBody
   @PostMapping(produces = MediaType.APPLICATION_JSON_VALUE)
   public DeferredResult<ResponseEntity<?>> post(
         @ApiParam(name = "request", type = "MyRequest", required = true) @RequestBody final MyRequest request,
         final HttpServletRequest servletRequest) {

         ...
   }

Got this message:

[INFO] Reflections took 80 ms to scan 261 urls, producing 2 keys and 2 values 

Failed to execute goal com.github.kongchen:swagger-maven-plugin:3.1.8:generate (default) on project swagger-test-project: null
michaelwangwangwang commented 3 years ago

below 3.1.7 maybe work