Skip to content
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

swagger.json generate only with tags section #467

Open
NogaB opened this issue Apr 27, 2017 · 10 comments
Open

swagger.json generate only with tags section #467

NogaB opened this issue Apr 27, 2017 · 10 comments

Comments

@NogaB
Copy link

NogaB commented Apr 27, 2017

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
	<dependency>
		<groupId>io.swagger</groupId>
		<artifactId>swagger-core</artifactId>
		<scope>compile</scope>
		<version>1.5.6</version>
		<exclusions>
			<exclusion>
				<groupId>javax.ws.rs</groupId>
				<artifactId>jsr311-api</artifactId>
			</exclusion>
		</exclusions>
	</dependency>

	<dependency>
		<groupId>io.springfox</groupId>
		<artifactId>springfox-swagger2</artifactId>
		<version>2.6.1</version>
	</dependency>

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
Copy link

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
Copy link
Contributor

danieleorler commented Jul 31, 2017

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

@mcicolella
Copy link

@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
Copy link
Contributor

@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
Copy link

ShanBai6 commented Aug 2, 2017

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
Copy link

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

@RequestMapping(path = "/")

@PAX523
Copy link

PAX523 commented Sep 14, 2017

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

@nikhil4326
Copy link

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

@PAX523
Copy link

PAX523 commented Oct 16, 2017

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
Copy link

Thanks, that helps

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants