标签:
This plugin enables your Swagger-annotated project to generate Swagger specs and customizable, templated static documents during the maven build phase. Unlike swagger-core, swagger-maven-plugin does not actively serve the spec with the rest of the application; it generates the spec as a build artifact to be used in downstream Swagger tooling.
预知详情,请到官网:
https://github.com/kongchen/swagger-maven-plugin
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-javadoc-plugin</artifactId> <configuration> <charset>UTF-8</charset> <docencoding>UTF-8</docencoding> <failOnError>false</failOnError> </configuration> </plugin> <plugin> <groupId>com.github.kongchen</groupId> <artifactId>swagger-maven-plugin</artifactId> <configuration> <apiSources> <apiSource> <springmvc>false</springmvc> <locations>com.doctor.demo</locations> <schemes>http,https</schemes> <host>petstore.swagger.wordnik.com</host> <basePath>/api</basePath> <info> <title>Swagger Maven Plugin Sample</title> <version>v1</version> <description>This is a sample for swagger-maven-plugin</description> <termsOfService> http://www.github.com/kongchen/swagger-maven-plugin </termsOfService> <contact> <email>kongchen@gmail.com</email> <name>Kong Chen</name> <url>http://kongch.com</url> </contact> <license> <url>http://www.apache.org/licenses/LICENSE-2.0.html</url> <name>Apache 2.0</name> </license> </info> Support classpath or file absolute path here. 1) classpath e.g: "classpath:/markdown.hbs", "classpath:/templates/hello.html" 2) file e.g: "${basedir}/src/main/resources/markdown.hbs", "${basedir}/src/main/resources/template/hello.html" <templatePath>${basedir}/templates/strapdown.html.hbs</templatePath> <outputPath>${basedir}/generated/document.html</outputPath> <swaggerDirectory>generated/swagger-ui</swaggerDirectory> </apiSource> </apiSources> </configuration> <executions> <execution> <phase>compile</phase> <goals> <goal>generate</goal> </goals> </execution> </executions> </plugin> </plugins> </build>
{ "swagger" : "2.0", "info" : { "description" : "This is a sample for swagger-maven-plugin", "version" : "v1", "title" : "Swagger Maven Plugin Sample", "termsOfService" : "http://www.github.com/kongchen/swagger-maven-plugin", "contact" : { "name" : "Kong Chen", "url" : "http://kongch.com", "email" : "kongchen@gmail.com" }, "license" : { "name" : "Apache 2.0", "url" : "http://www.apache.org/licenses/LICENSE-2.0.html" } }, "host" : "petstore.swagger.wordnik.com", "basePath" : "/api", "tags" : [ { "name" : "hello service" } ], "schemes" : [ "http", "https" ], "paths" : { "/hello/w" : { "post" : { "tags" : [ "hello service" ], "summary" : "test hello method", "description" : "note", "operationId" : "hello", "consumes" : [ "application/json" ], "produces" : [ "application/json" ], "parameters" : [ { "in" : "body", "name" : "body", "description" : "welcomDto object", "required" : true, "schema" : { "$ref" : "#/definitions/WelcomeDto" } } ], "responses" : { "200" : { "description" : "successful operation", "schema" : { "$ref" : "#/definitions/WelcomeResponseDto" } } } } } }, "definitions" : { "WelcomeDto" : { "type" : "object", "properties" : { "name" : { "type" : "string" }, "age" : { "type" : "integer", "format" : "int32" } } }, "WelcomeResponseDto" : { "type" : "object", "properties" : { "content" : { "type" : "string" } } } } }
package com.doctor.demo.service; import javax.ws.rs.Consumes; import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import com.doctor.demo.common.dto.WelcomeDto; import com.doctor.demo.common.dto.WelcomeResponseDto; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import io.swagger.annotations.ApiResponse; /** * @author sdcuike * * @time 2016年1月25日 下午11:07:44 */ @Api(value = "hello", tags = "hello service") @Path("hello") public interface HelloRestService { /** * 老接口方式(DTO) * * @param welcomDto * @return */ @ApiOperation(value = "test hello method", notes = "note") @POST @Path("w") @Consumes({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON }) @ApiResponse(message = "ok", code = 200) WelcomeResponseDto hello(@ApiParam(value = "welcomDto object", required = true) WelcomeDto welcomDto); }
利用Swagger Maven Plugin生成Rest API文档
标签:
原文地址:http://blog.csdn.net/doctor_who2004/article/details/50816208