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

swagger.json generate only with tags section #467

Open NogaB opened 7 years ago

NogaB commented 7 years ago

Hi, I get build success, but a very partial json swagger is create. Namely it look like my @ApiOperation annotation is completely missed or ignored. When I compile I see the following print:

--- swagger-maven-plugin:3.1.4:generate (default) @ backend --- [INFO] Reflections took 126 ms to scan 1 urls, producing 9 keys and 12 values [INFO] Reflections took 5 ms to scan 1 urls, producing 9 keys and 12 values [INFO] Reflections took 5 ms to scan 1 urls, producing 9 keys and 12 values [INFO] Reflections took 5 ms to scan 1 urls, producing 9 keys and 12 values

Using

com.github.kongchen swagger-maven-plugin 3.1.4 Swagger annotations, swagger core and springfox io.swagger swagger-annotations 1.5.6 io.swagger swagger-core compile 1.5.6 javax.ws.rs jsr311-api io.springfox springfox-swagger2 2.6.1 And My code: ` @Api(tags = "Greetings", description = "Greeting Resource") @RestController @RequestMapping(value = "api/greetings" , produces = "application/json") public interface GreetingsController { @ApiOperation(value = "Get your greeting here", response = GreetingResource.class) @RequestMapping(value = "" , method = RequestMethod.GET) GreetingResource getGreetings(); } ` when I run my app and check /api-docs - I see the correct full json. Please help
mcicolella commented 7 years ago

Hi, I have a similar problem. We used swagger with this configuration without any problem. Now I updated the plugin to the new version and the doc is not created correctly. Also the json in "api-docs" doesn't contain any API. The code is available here. Any idea?

danieleorler commented 7 years ago

@mcicolella looks like you are using a fairly outdated version (3.0.0), latest is 3.1.5

mcicolella commented 7 years ago

@danieleorler updated to 3.1.5 but the build fails Failed to execute goal com.github.kongchen:swagger-maven-plugin:3.1.5:generate (default) on project restapi-v3: Unable to parse configuration of mojo com.github.kongchen:swagger-maven-plugin:3.1.5:generate for parameter locations: Cannot assign configuration entry 'locations' with value 'com.freedomotic.plugins.devices.restapiv3.resources' of type java.lang.String to property of type java.util.List

danieleorler commented 7 years ago

@mcicolella yeah the location definition has changed a bit:

from:

<locations>com.freedomotic.plugins.devices.restapiv3.resources</locations>

to

<locations>
   <location>com.freedomotic.plugins.devices.restapiv3.resources</location>
</locations>
ShanBai6 commented 7 years ago

We have the same problem. And it does not help by updating to 3.1.5. It simply does not recognize all the annotations I had.

 <plugin>
                <groupId>com.github.kongchen</groupId>
                <artifactId>swagger-maven-plugin</artifactId>
                <version>3.1.5</version>
                <configuration>
                    <apiSources>
                        <apiSource>
                            <info>
                                <title>API for Presto Manager</title>
                                <version>v1</version>
                                <description>Swagger specification for REST API</description>
                            </info>
                            <springmvc>false</springmvc>
                            <basePath>/v1</basePath>
                            <swaggerDirectory>doc/</swaggerDirectory>
                            <locations>
                                <location>presto-manager-agent.src.main.java.com.teradata.prestomanager.agent.api</location>
                                <location>presto-manager-controller.src.main.java.com.teradata.prestomanager.controller.api</location>
                            </locations>
                        </apiSource>
                    </apiSources>
                </configuration>
                <executions>
                    <execution>
                        <phase>compile</phase>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
thlaegler commented 7 years ago

Since it looks like you are using Jax/RS, try instead of @RequestMapping(value = "/")

@RequestMapping(path = "/")

PAX523 commented 7 years ago

Thanks @thlaegler! I'm using Spring Boot and it works when I use value attribute instead of path: @RequestMapping(value = "suggestion/{term}"

nikhil4326 commented 7 years ago

Hi, Even Changing to value its not working, Do u have any working example of spring boot with static doc generation

PAX523 commented 7 years ago

The code is proprietary, so I cannot give you the original one. But I can give you a simplified and modified version. The controller class basically looks like this:

@RestController
@RequestMapping(value = "/{languageTag}")
public class MyService {
...
  @RequestMapping(value = "/{term}", produces = MediaType.APPLICATION_JSON_UTF8_VALUE, method = RequestMethod.GET)
  @ApiOperation(value = "Applies ...", response = MyServiceResult.class)
  @ApiResponses({
    @ApiResponse(code = 400, message = ERROR_CODE_MESSAGE_BAD_REQUEST, response = ApiError.class),
    @ApiResponse(code = 500, message = ERROR_CODE_MESSAGE_INTERNAL_ERROR, response = ApiError.class)
  })
  public HttpEntity<MyServiceResult> serviceMethod(
          @PathVariable
          @ApiParam(value = "The ...",
                    example = "en-US",
                    name = "languageTag")
          final String languageTag,
          @PathVariable
          @ApiParam(value = "The ...",
                    example = "word",
                    name = "term")
          final String term) {
          ...

If this doesn't work for you then estimatedly it's caused by your different Maven dependency configuration or by the Swagger plugin version you use.

nikhil4326 commented 7 years ago

Thanks, that helps