swagger-maven-plugin自动生成swagge.json(Jersey项目)

来源:互联网 发布:淘宝发错货买家不寄回 编辑:程序博客网 时间:2024/06/18 14:41

1,加入依赖

<!-- Swagger -->
        <dependency>
            <groupId>io.swagger</groupId>
            <artifactId>swagger-jersey2-jaxrs</artifactId>
            <version>1.5.0</version>
        </dependency>


2,加入插件

<!--增加swagger-plugin-->
            <plugin>
                <groupId>com.github.kongchen</groupId>
                <artifactId>swagger-maven-plugin</artifactId>
                <version>3.1.1</version>
                <configuration>
                    <apiSources>
                        <apiSource>
                            <springmvc>false</springmvc>
                            <locations>com.gionee.geip.web</locations>
                            <schemes>http,https</schemes>
                            <host>xxxx</host>
                            <basePath>/api</basePath>
                            <info>
                                <title>Swagger Maven Plugin Sample</title>
                                <version>v1</version>
                                <description>
                                    This is a sample.
                                </description>
                                <termsOfService>
                                    http://www.github.com/kongchen/swagger-maven-plugin
                                </termsOfService>
                                <contact>
                                    <email>xxx</email>
                                    <name>xxx</name>
                                    <url>xxx</url>
                                </contact>
                                <license>
                                    <url>http://www.apache.org/licenses/LICENSE-2.0.html</url>
                                    <name>Apache 2.0</name>
                                </license>
                            </info>
                            <securityDefinitions>
                            </securityDefinitions>
                            <swaggerDirectory>${basedir}/src/main/generated</swaggerDirectory>
                        </apiSource>
                    </apiSources>
                </configuration>
                <executions>
                    <execution>
                        <phase>compile</phase>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                    </execution>
                </executions>
                <dependencies>
                    <dependency>
                        <groupId>io.swagger</groupId>
                        <artifactId>swagger-hibernate-validations</artifactId>
                        <version>1.5.6</version>
                    </dependency>
                </dependencies>
            </plugin>


3,加入注释

@Controller
@Path("/geip")//必须
@Api(value = "/geip", description = "Operations about WebController")//必须
public class WebController {

    @Autowired
    private GeipManager geipManager;

    @GET
    @Path("/test")
    @ApiOperation(value = "test",
            notes = "test"
    )//必须
    public String test() {
        return "test";
    }

}


4,执行mvn compile

原创粉丝点击