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
,内容为空
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 = {
// 定义业务错误码,用于文档显示
@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();
/**
* 版本号,默认版本号是""<br>
* 改默认版本号:<code>ServiceConfig.getInstance().setDefaultVersion("1.0");</code>
*/
String version() default "";
/**
* 忽略验证,业务参数除外
*/
boolean ignoreValidate() default false;
/**
* 告诉网关是否对结果进行合并,默认合并。设置为false,客户端将直接收到微服务端的结果。
*/
boolean mergeResult() default true;
/**
* 指定接口是否需要授权才能访问,可在admin中进行修改
*/
boolean permission() default false;
/**
* 是否需要appAuthToken,设置为true,网关端会校验token是否存在
*/
boolean needToken() default false;
/**
* 定义业务错误码,用于文档显示
*/
BizCode[] bizCode() default {};
}