Skip to content

Commit

Permalink
solon.docs 添加注释
Browse files Browse the repository at this point in the history
  • Loading branch information
noear committed Jun 9, 2024
1 parent 54ad287 commit c04acf7
Show file tree
Hide file tree
Showing 3 changed files with 136 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.noear.solon.docs;

/**
* 基础签权
*
* @author noear
* @since 2.3
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,53 +20,73 @@ public class DocDocket {
private String basePath;
private transient Serializer<String> serializer;


//基础鉴权
private Map<String, String> basicAuth = new LinkedHashMap<>();

//全局结果
private Class<?> globalResult;
//全局响应代码描述
private Map<Integer, String> globalResponseCodes = new LinkedHashMap<>();
//全局响应放到data下面
private boolean globalResponseInData = false;
//全局参数
private Set<Object> globalParams = new LinkedHashSet<>();

//接口信息
private ApiInfo info = new ApiInfo();
//接口资源
private List<ApiResource> apis = new ArrayList<>();

/**
* 外部文件
* */
//外部文件
private ApiExternalDocs externalDocs;
/**
* 供应商扩展
* */
//供应商扩展
private Map<String, Object> vendorExtensions = new LinkedHashMap<>();

//安全扩展
private Map<String, Object> securityExtensions = new LinkedHashMap<>();



/**
* 版本号
*/
public String version() {
return version;
}

/**
* 配置版本号
*/
public DocDocket version(String version) {
this.version = version;
return this;
}


/**
* 主机
*/
public String host() {
return host;
}

/**
* 配置主机
*/
public DocDocket host(String host) {
this.host = host;
return this;
}

/**
* 协议架构(http, https)
*/
public List<ApiScheme> schemes() {
return schemes;
}


/**
* 配置协议架构(http, https)
*/
public DocDocket schemes(String... schemes) {
for (String s : schemes) {
ApiScheme scheme = ApiScheme.forValue(s);
Expand All @@ -77,36 +97,55 @@ public DocDocket schemes(String... schemes) {
return this;
}

/**
* 分组名字
*/
public String groupName() {
return groupName;
}

/**
* 配置分组名字
*/
public DocDocket groupName(String groupName) {
this.groupName = groupName;
return this;
}


/**
* 基础路径
*/
public String basePath() {
return basePath;
}

/**
* 格式:admin#123456,user#654321,张三#abc
* 配置基础路径
*/
public DocDocket basePath(String basePath) {
this.basePath = basePath;
return this;
}

/**
* 基础鉴权(格式:admin#123456,user#654321,张三#abc)
*/
public Map<String, String> basicAuth() {
return basicAuth;
}

/**
* 配置基础鉴权
*/
public DocDocket basicAuth(String username, String password) {
this.basicAuth.put(username, password);
return this;
}

/**
* 配置基础鉴权
*/
public DocDocket basicAuth(BasicAuth basicAuth) {
if (basicAuth != null) {
if (basicAuth.isEnable() && Utils.isNotEmpty(basicAuth.getUsername())) {
Expand All @@ -116,44 +155,72 @@ public DocDocket basicAuth(BasicAuth basicAuth) {
return this;
}

/**
* 接口资源
*/
public List<ApiResource> apis() {
return apis;
}

/**
* 配置接口资源
*/
public DocDocket apis(String basePackage) {
this.apis.add(new ApiResource(basePackage));

return this;
}

/**
* 配置接口资源
*/
public DocDocket apis(ApiResource apiResource) {
this.apis.add(apiResource);

return this;
}

/**
* 接口信息
*/
public ApiInfo info() {
return info;
}

/**
* 配置接口信息
*/
public DocDocket info(ApiInfo info) {
this.info = info;
return this;
}

/**
* 全局响应到data下面
*/
public boolean globalResponseInData() {
return globalResponseInData;
}


/**
* 配置全局响应到data下面
*/
public DocDocket globalResponseInData(boolean globalResponseInData) {
this.globalResponseInData = globalResponseInData;
return this;
}

/**
* 全局响应代码描述(401,403...)
*/
public Map<Integer, String> globalResponseCodes() {
return globalResponseCodes;
}

/**
* 配置全局响应代码描述(401,403...)
*/
public DocDocket globalResponseCodes(Map<Integer, String> globalResponseCodes) {
if (globalResponseCodes != null) {
this.globalResponseCodes.putAll(globalResponseCodes);
Expand All @@ -162,61 +229,101 @@ public DocDocket globalResponseCodes(Map<Integer, String> globalResponseCodes) {
}


/**
* 全局结果类
*/
public Class<?> globalResult() {
return globalResult;
}

/**
* 配置全局结果类
*/
public DocDocket globalResult(Class<?> clz) {
globalResult = clz;
return this;
}

public Set<Object> globalParams(){
/**
* 全局参数
*/
public Set<Object> globalParams() {
return globalParams;
}

/**
* 配置全局参数
*/
public DocDocket globalParams(Collection<Object> globalParams) {
if (globalParams != null) {
this.globalParams.addAll(globalParams);
}
return this;
}

/**
* 配置全局参数
*/
public DocDocket globalParams(Object param) {
this.globalParams.add(param);
return this;
}

/**
* 外部文档
*/
public ApiExternalDocs externalDocs() {
return externalDocs;
}


/**
* 配置外部文档
*/
public DocDocket externalDocs(ApiExternalDocs externalDocs) {
this.externalDocs = externalDocs;
return this;
}

/**
* 配置外部文档
*/
public DocDocket externalDocs(String description, String url) {
this.externalDocs = new ApiExternalDocs();
return this;
}

/**
* 供应商扩展
*/
public Map<String, Object> vendorExtensions() {
return vendorExtensions;
}


/**
* 配置供应商扩展
*/
public DocDocket vendorExtensions(Map<String, Object> vendorExtensions) {
if (vendorExtensions != null) {
this.vendorExtensions.putAll(vendorExtensions);
}
return this;
}


/**
* 配置供应商扩展
*/
public DocDocket vendorExtensions(String name, Object value) {
this.vendorExtensions.put(name, value);
return this;
}


/**
* 配置供应商扩展
*/
public DocDocket vendorExtensions(List<ApiVendorExtension> extensions) {
for (ApiVendorExtension ext : extensions) {
this.vendorExtensions.put(ext.getName(), ext.getValue());
Expand All @@ -225,29 +332,41 @@ public DocDocket vendorExtensions(List<ApiVendorExtension> extensions) {
return this;
}

/**
* 安全扩展
*/
public Map<String, Object> securityExtensions() {
return securityExtensions;
}

/**
* 配置安全扩展
*/
public DocDocket securityExtensions(Map<String, Object> securityExtensions) {
if (securityExtensions != null) {
this.securityExtensions.putAll(securityExtensions);
}
return this;
}

/**
* 配置安全扩展
*/
public DocDocket securityExtensions(String name, Object value) {
this.securityExtensions.put(name, value);
return this;
}

/**
* 序列化
* */
*/
public Serializer<String> serializer() {
return serializer;
}

/**
* 配置序列化
*/
public void serializer(Serializer<String> serializer) {
this.serializer = serializer;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ public enum DocType {
this.version = version;
}

/**
* 获取版本号
* */
public String getVersion() {
return version;
}
Expand Down

0 comments on commit c04acf7

Please sign in to comment.