SOP接口文檔
1操软、流程
2靠闭、集成nacos與sop pom.xml配置
<!-- 使用nacos注冊中心 -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
<version>2.2.5.RELEASE</version>
</dependency>
<!-- sop-->
<dependency>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-service-common</artifactId>
<version>4.5.0-SNAPSHOT</version>
</dependency>
<!--swagger-->
<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>
</dependency>
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>swagger-bootstrap-ui</artifactId>
<version>1.9.6</version>
</dependency>
3宣鄙、application.yml配置
spring:
cloud:
nacos:
discovery:
server-addr: 127.0.0.1:8848
4、啟動類上加@EnableDiscoveryClient注解
@EnableDiscoveryClient
public class QrcodeCenterWebApplication {
public static void main(String[] args) {
SpringApplication.run(QrcodeCenterWebApplication.class, args);
}
}
5衙猪、新增一個配置類垂券,繼承AlipayServiceConfiguration.java
,內(nèi)容為空
package com.juliye.center.qrcode.web.swagger;
import com.gitee.sop.servercommon.configuration.AlipayServiceConfiguration;
import org.springframework.context.annotation.Configuration;
@Configuration
public class OpenServiceConfig extends AlipayServiceConfiguration {
}
6执虹、swagger配置
@Configuration
@EnableSwagger2
@EnableSwaggerBootstrapUI
public class SwaggerConfig extends SwaggerSupport {
@Override
protected String getDocTitle() {
return "qrcode-center-web接口文檔";
}
@Override
protected boolean swaggerAccessProtected() {
return false;
}
}
7拓挥、sop @Open注解使用
@Open(value = "recode.redirect", version = "2.0", permission = true, bizCode = {
// 定義業(yè)務(wù)錯誤碼,用于文檔顯示
@BizCode(code = "100001", msg = "姓名錯誤", solution = "填寫正確的姓名"),
@BizCode(code = "100002", msg = "備注錯誤", solution = "填寫正確備注"),
})
/**
* @author tanghc
*/
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface Open {
/**
* 接口名袋励,如:member.user.get
*/
String value();
/**
* 版本號侥啤,默認(rèn)版本號是""<br>
* 改默認(rèn)版本號:<code>ServiceConfig.getInstance().setDefaultVersion("1.0");</code>
*/
String version() default "";
/**
* 忽略驗證,業(yè)務(wù)參數(shù)除外
*/
boolean ignoreValidate() default false;
/**
* 告訴網(wǎng)關(guān)是否對結(jié)果進(jìn)行合并茬故,默認(rèn)合并盖灸。設(shè)置為false,客戶端將直接收到微服務(wù)端的結(jié)果均牢。
*/
boolean mergeResult() default true;
/**
* 指定接口是否需要授權(quán)才能訪問糠雨,可在admin中進(jìn)行修改
*/
boolean permission() default false;
/**
* 是否需要appAuthToken,設(shè)置為true徘跪,網(wǎng)關(guān)端會校驗token是否存在
*/
boolean needToken() default false;
/**
* 定義業(yè)務(wù)錯誤碼甘邀,用于文檔顯示
*/
BizCode[] bizCode() default {};
}