APIいくつかの手書き文書の痛みのポイント:
- ドキュメントは、ドキュメントの更新のタイムリーな交換のではないこと、更新する必要があり、再び前にコピーを送信する必要があります。
- インターフェイスは、結果は明らかではない返します
- オンラインテストインタフェースを指示することはできません、通常、郵便配達などのツールを使用する必要があり
- あまりにも多くのインターフェースの文書、経営不振
闊歩が闊歩は確かに完璧になりますと言うことはできません、もちろん、この問題を解決することであり、もちろん、最も明白には比較的強いにコードされ、欠点を有しています。
それ以外は、あなたが闊歩して闊歩は公式サイトに行くことができる、あなたはもちろん、直接闊歩エディタインタフェースのドキュメントを書くことができます知ってほしい、我々はSpringBoot統合Swagger2、インターフェースドキュメントを生成するための直接的な方法を説明するためにここにいます。
依存性の導入
<!-- swagger2 接口文档-->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
闊歩の設定クラス
実際には、すべての後に、特定の十分のために設定することができるもの限り、この設定クラスは、この事は、移動後に一度設定する必要はありません。特に注目すべきは、構成ファイルは、APIコントローラパッケージ、または生成原稿読取インターフェース未満であるパスがあります。
package com.gpdi.lxq.eladmin.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
/**
* @description: 接口文档
* @author: Lxq
* @date: 2020/1/19 9:25
*/
@Configuration
@EnableSwagger2
public class Swagger2Config {
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("com.gpdi.lxq.eladmin.rest"))
.paths(PathSelectors.any())
.build();
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("xxxxxxxxxxxxxx平台 APIs")
.description("xxxxxxxxxxxxxx APIs")
.termsOfServiceUrl("http://www.baidu.com")
.contact(new Contact("developer", "#", ""))
.version("1.0")
.build();
}
}
Swagger2ドキュメント
スタートSpringBootプロジェクト、訪問 のhttp:// localhostを:19099 /エル -admin /威張っ-ui.htm
闊歩コメント
注釈通じ闊歩は、このインタフェースは、インタフェース名、リクエストメソッド、パラメータ、戻り値の情報、および含め、ドキュメントを生成することを示します。
- @Api:クラス全体の変更は、コントローラの役割を説明します
- @ApiOperation:クラスまたはインタフェースの方法を記載しています
- @ApiParam:単一のパラメータ説明
- @ApiModel:オブジェクトパラメータを受信
- @ApiProperty:オブジェクトパラメータを受信すると、オブジェクトのフィールドの説明
- @ApiResponse:HTTPレスポンスが記載されています
- @ApiResponses:HTTPレスポンス全体的な説明
- @ApiIgnore:このコメントを無視するAPIを使用します
- @ApiError:エラーが発生することが返さ
- @ApiImplicitParam:リクエストパラメータ
- @ApiImplicitParams:リクエストパラメータの複数