针对单独生成api创建数据字典 & fix request json 注解字段和response逻辑保持一致

This commit is contained in:
ganluting 2020-05-15 13:56:59 +08:00
parent e81bdf71c8
commit d9e983f54a
6 changed files with 43 additions and 16 deletions

View File

@ -71,6 +71,7 @@ public class AdocDocBuilder {
} else { } else {
builderTemplate.buildApiDoc(apiDocList, config, API_DOC_ADOC_TPL, API_EXTENSION); builderTemplate.buildApiDoc(apiDocList, config, API_DOC_ADOC_TPL, API_EXTENSION);
builderTemplate.buildErrorCodeDoc(config, ERROR_CODE_LIST_ADOC_TPL, ERROR_CODE_LIST_ADOC); builderTemplate.buildErrorCodeDoc(config, ERROR_CODE_LIST_ADOC_TPL, ERROR_CODE_LIST_ADOC);
builderTemplate.buildDirectoryDataDoc(config, javaProjectBuilder, DICT_LIST_ADOC_TPL, DICT_LIST_ADOC);
} }
} }

View File

@ -71,6 +71,7 @@ public class ApiDocBuilder {
} else { } else {
builderTemplate.buildApiDoc(apiDocList, config, API_DOC_MD_TPL, API_EXTENSION); builderTemplate.buildApiDoc(apiDocList, config, API_DOC_MD_TPL, API_EXTENSION);
builderTemplate.buildErrorCodeDoc(config, ERROR_CODE_LIST_MD_TPL, ERROR_CODE_LIST_MD); builderTemplate.buildErrorCodeDoc(config, ERROR_CODE_LIST_MD_TPL, ERROR_CODE_LIST_MD);
builderTemplate.buildDirectoryDataDoc(config, javaProjectBuilder, DICT_LIST_MD_TPL, DICT_LIST_MD);
} }
} }

View File

@ -143,18 +143,7 @@ public class DocBuilderTemplate {
} else { } else {
tpl.binding(TemplateVariable.DICT_ORDER.getVariable(), apiDocList.size() + 2); tpl.binding(TemplateVariable.DICT_ORDER.getVariable(), apiDocList.size() + 2);
} }
if (null != config.getLanguage()) { setDirectoryLanguageVariable(config, tpl);
if (DocLanguage.CHINESE.code.equals(config.getLanguage().getCode())) {
tpl.binding(TemplateVariable.ERROR_LIST_TITLE.getVariable(), DocGlobalConstants.ERROR_CODE_LIST_CN_TITLE);
tpl.binding(TemplateVariable.DICT_LIST_TITLE.getVariable(), DocGlobalConstants.DICT_CN_TITLE);
} else {
tpl.binding(TemplateVariable.ERROR_LIST_TITLE.getVariable(), DocGlobalConstants.ERROR_CODE_LIST_EN_TITLE);
tpl.binding(TemplateVariable.DICT_LIST_TITLE.getVariable(), DocGlobalConstants.DICT_EN_TITLE);
}
} else {
tpl.binding(TemplateVariable.ERROR_LIST_TITLE.getVariable(), DocGlobalConstants.ERROR_CODE_LIST_CN_TITLE);
tpl.binding(TemplateVariable.DICT_LIST_TITLE.getVariable(), DocGlobalConstants.DICT_CN_TITLE);
}
List<ApiDocDict> apiDocDictList = buildDictionary(config, javaProjectBuilder); List<ApiDocDict> apiDocDictList = buildDictionary(config, javaProjectBuilder);
tpl.binding(TemplateVariable.DICT_LIST.getVariable(), apiDocDictList); tpl.binding(TemplateVariable.DICT_LIST.getVariable(), apiDocDictList);
FileUtil.nioWriteFile(tpl.render(), outPath + FILE_SEPARATOR + outPutFileName); FileUtil.nioWriteFile(tpl.render(), outPath + FILE_SEPARATOR + outPutFileName);
@ -175,6 +164,36 @@ public class DocBuilderTemplate {
FileUtil.nioWriteFile(mapper.render(), config.getOutPath() + FILE_SEPARATOR + outPutFileName); FileUtil.nioWriteFile(mapper.render(), config.getOutPath() + FILE_SEPARATOR + outPutFileName);
} }
/**
* build common_data doc
*
* @param config api config
* @param template template
* @param outPutFileName output file
*/
public void buildDirectoryDataDoc(ApiConfig config, JavaProjectBuilder javaProjectBuilder, String template, String outPutFileName) {
List<ApiDocDict> directoryList = buildDictionary(config, javaProjectBuilder);
Template mapper = BeetlTemplateUtil.getByName(template);
setDirectoryLanguageVariable(config, mapper);
mapper.binding(TemplateVariable.DICT_LIST.getVariable(), directoryList);
FileUtil.nioWriteFile(mapper.render(), config.getOutPath() + FILE_SEPARATOR + outPutFileName);
}
private void setDirectoryLanguageVariable(ApiConfig config, Template mapper) {
if (null != config.getLanguage()) {
if (DocLanguage.CHINESE.code.equals(config.getLanguage().getCode())) {
mapper.binding(TemplateVariable.ERROR_LIST_TITLE.getVariable(), DocGlobalConstants.ERROR_CODE_LIST_CN_TITLE);
mapper.binding(TemplateVariable.DICT_LIST_TITLE.getVariable(), DocGlobalConstants.DICT_CN_TITLE);
} else {
mapper.binding(TemplateVariable.ERROR_LIST_TITLE.getVariable(), DocGlobalConstants.ERROR_CODE_LIST_EN_TITLE);
mapper.binding(TemplateVariable.DICT_LIST_TITLE.getVariable(), DocGlobalConstants.DICT_EN_TITLE);
}
} else {
mapper.binding(TemplateVariable.ERROR_LIST_TITLE.getVariable(), DocGlobalConstants.ERROR_CODE_LIST_CN_TITLE);
mapper.binding(TemplateVariable.DICT_LIST_TITLE.getVariable(), DocGlobalConstants.DICT_CN_TITLE);
}
}
/** /**
* Generate a single controller api document * Generate a single controller api document
* *

View File

@ -37,8 +37,14 @@ public interface DocGlobalConstants {
String ERROR_CODE_LIST_ADOC = "ErrorCodeList.md"; String ERROR_CODE_LIST_ADOC = "ErrorCodeList.md";
String DICT_LIST_MD = "Dictionary.md";
String DICT_LIST_MD_TPL = "Dictionary.btl"; String DICT_LIST_MD_TPL = "Dictionary.btl";
String DICT_LIST_ADOC = "Dictionary.adoc";
String DICT_LIST_ADOC_TPL = "Dictionary.btl";
String INDEX_TPL = "Index.btl"; String INDEX_TPL = "Index.btl";
String INDEX_CSS_TPL = "index.css"; String INDEX_CSS_TPL = "index.css";

View File

@ -124,9 +124,9 @@ public class ParamsBuildHelper {
an: an:
for (JavaAnnotation annotation : javaAnnotations) { for (JavaAnnotation annotation : javaAnnotations) {
String simpleAnnotationName = annotation.getType().getValue(); String simpleAnnotationName = annotation.getType().getValue();
if (DocAnnotationConstants.SHORT_JSON_IGNORE.equals(simpleAnnotationName) && isResp) { if (DocAnnotationConstants.SHORT_JSON_IGNORE.equals(simpleAnnotationName)) {
continue out; continue out;
} else if (DocAnnotationConstants.SHORT_JSON_FIELD.equals(simpleAnnotationName) && isResp) { } else if (DocAnnotationConstants.SHORT_JSON_FIELD.equals(simpleAnnotationName)) {
if (null != annotation.getProperty(DocAnnotationConstants.SERIALIZE_PROP)) { if (null != annotation.getProperty(DocAnnotationConstants.SERIALIZE_PROP)) {
if (Boolean.FALSE.toString().equals(annotation.getProperty(DocAnnotationConstants.SERIALIZE_PROP).toString())) { if (Boolean.FALSE.toString().equals(annotation.getProperty(DocAnnotationConstants.SERIALIZE_PROP).toString())) {
continue out; continue out;
@ -134,7 +134,7 @@ public class ParamsBuildHelper {
} else if (null != annotation.getProperty(DocAnnotationConstants.NAME_PROP)) { } else if (null != annotation.getProperty(DocAnnotationConstants.NAME_PROP)) {
fieldName = StringUtil.removeQuotes(annotation.getProperty(DocAnnotationConstants.NAME_PROP).toString()); fieldName = StringUtil.removeQuotes(annotation.getProperty(DocAnnotationConstants.NAME_PROP).toString());
} }
} else if (DocAnnotationConstants.SHORT_JSON_PROPERTY.equals(simpleAnnotationName) && isResp) { } else if (DocAnnotationConstants.SHORT_JSON_PROPERTY.equals(simpleAnnotationName)) {
if (null != annotation.getProperty(DocAnnotationConstants.VALUE_PROP)) { if (null != annotation.getProperty(DocAnnotationConstants.VALUE_PROP)) {
fieldName = StringUtil.removeQuotes(annotation.getProperty(DocAnnotationConstants.VALUE_PROP).toString()); fieldName = StringUtil.removeQuotes(annotation.getProperty(DocAnnotationConstants.VALUE_PROP).toString());
} }

View File

@ -1,5 +1,5 @@
<%if(isNotEmpty(dictList)){%> <%if(isNotEmpty(dictList)){%>
# Data Dictionaries # ${dictListTitle!"Data Dictionaries"}
<% <%
for(dict in dictList){ for(dict in dictList){
%> %>