com.gitee.easyopen.doc.ParamMarkdownHtmlBuilder Maven / Gradle / Ivy
package com.gitee.easyopen.doc;
import org.apache.commons.collections.CollectionUtils;
import java.util.List;
/**
* @author tanghc
*/
public class ParamMarkdownHtmlBuilder {
private static final String START_TD = "";
private static final String END_TD = " ";
private static final String START_TR = "";
private static final String END_TR = " ";
private static final String TRUE = "true";
public String buildHtml(ApiDocFieldDefinition definition) {
StringBuilder html = new StringBuilder();
html.append(START_TR)
.append(wrapTD(definition.getName()))
.append("" + definition.getDataType() + END_TD)
.append(wrapTD(this.getRequireHtml(definition)))
.append(wrapTD(buildExample(definition)))
.append(wrapTD(definition.getDescription()));
html.append(END_TR);
return html.toString();
}
private String wrapTD(String content) {
return START_TD + content + END_TD;
}
protected String buildExample(ApiDocFieldDefinition definition) {
StringBuilder html = new StringBuilder();
if (CollectionUtils.isNotEmpty(definition.getElements())) {
html.append("")
.append(START_TR)
.append("名称 ")
.append("类型 ")
.append("是否必须 ")
.append("示例值 ")
.append("描述 ")
.append(END_TR);
List els = definition.getElements();
for (ApiDocFieldDefinition apiDocFieldDefinition : els) {
html.append(START_TR)
.append(wrapTD(apiDocFieldDefinition.getName()))
.append("" + apiDocFieldDefinition.getDataType() + END_TD)
.append(wrapTD(getRequireHtml(apiDocFieldDefinition)))
.append(wrapTD(buildExample(apiDocFieldDefinition)))
.append(wrapTD(apiDocFieldDefinition.getDescription()))
.append(END_TR);
}
html.append("
");
} else {
html.append(buildExampleValue(definition));
}
return html.toString();
}
private String getRequireHtml(ApiDocFieldDefinition definition) {
if (TRUE.equals(definition.getRequired())) {
return "是";
} else {
return "否";
}
}
protected String buildExampleValue(ApiDocFieldDefinition definition) {
return definition.getExample();
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy