diff --git a/src/main/java/com/power/doc/builder/AdocDocBuilder.java b/src/main/java/com/power/doc/builder/AdocDocBuilder.java index 4b1bde7..1a3d971 100644 --- a/src/main/java/com/power/doc/builder/AdocDocBuilder.java +++ b/src/main/java/com/power/doc/builder/AdocDocBuilder.java @@ -71,6 +71,7 @@ public class AdocDocBuilder { } else { builderTemplate.buildApiDoc(apiDocList, config, API_DOC_ADOC_TPL, API_EXTENSION); builderTemplate.buildErrorCodeDoc(config, ERROR_CODE_LIST_ADOC_TPL, ERROR_CODE_LIST_ADOC); + builderTemplate.buildDirectoryDataDoc(config, javaProjectBuilder, DICT_LIST_ADOC_TPL, DICT_LIST_ADOC); } } diff --git a/src/main/java/com/power/doc/builder/ApiDocBuilder.java b/src/main/java/com/power/doc/builder/ApiDocBuilder.java index c188a06..bf3dc57 100644 --- a/src/main/java/com/power/doc/builder/ApiDocBuilder.java +++ b/src/main/java/com/power/doc/builder/ApiDocBuilder.java @@ -71,6 +71,7 @@ public class ApiDocBuilder { } else { builderTemplate.buildApiDoc(apiDocList, config, API_DOC_MD_TPL, API_EXTENSION); builderTemplate.buildErrorCodeDoc(config, ERROR_CODE_LIST_MD_TPL, ERROR_CODE_LIST_MD); + builderTemplate.buildDirectoryDataDoc(config, javaProjectBuilder, DICT_LIST_MD_TPL, DICT_LIST_MD); } } diff --git a/src/main/java/com/power/doc/builder/DocBuilderTemplate.java b/src/main/java/com/power/doc/builder/DocBuilderTemplate.java index 75b93f1..4777540 100644 --- a/src/main/java/com/power/doc/builder/DocBuilderTemplate.java +++ b/src/main/java/com/power/doc/builder/DocBuilderTemplate.java @@ -143,18 +143,7 @@ public class DocBuilderTemplate { } else { tpl.binding(TemplateVariable.DICT_ORDER.getVariable(), apiDocList.size() + 2); } - if (null != config.getLanguage()) { - 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); - } + setDirectoryLanguageVariable(config, tpl); List apiDocDictList = buildDictionary(config, javaProjectBuilder); tpl.binding(TemplateVariable.DICT_LIST.getVariable(), apiDocDictList); FileUtil.nioWriteFile(tpl.render(), outPath + FILE_SEPARATOR + outPutFileName); @@ -175,6 +164,36 @@ public class DocBuilderTemplate { 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 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 * diff --git a/src/main/java/com/power/doc/constants/DocGlobalConstants.java b/src/main/java/com/power/doc/constants/DocGlobalConstants.java index 69780cc..fa6b62f 100644 --- a/src/main/java/com/power/doc/constants/DocGlobalConstants.java +++ b/src/main/java/com/power/doc/constants/DocGlobalConstants.java @@ -37,8 +37,14 @@ public interface DocGlobalConstants { String ERROR_CODE_LIST_ADOC = "ErrorCodeList.md"; + String DICT_LIST_MD = "Dictionary.md"; + 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_CSS_TPL = "index.css"; diff --git a/src/main/java/com/power/doc/helper/ParamsBuildHelper.java b/src/main/java/com/power/doc/helper/ParamsBuildHelper.java index 8af213d..e7ecb55 100644 --- a/src/main/java/com/power/doc/helper/ParamsBuildHelper.java +++ b/src/main/java/com/power/doc/helper/ParamsBuildHelper.java @@ -124,9 +124,9 @@ public class ParamsBuildHelper { an: for (JavaAnnotation annotation : javaAnnotations) { String simpleAnnotationName = annotation.getType().getValue(); - if (DocAnnotationConstants.SHORT_JSON_IGNORE.equals(simpleAnnotationName) && isResp) { + if (DocAnnotationConstants.SHORT_JSON_IGNORE.equals(simpleAnnotationName)) { 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 (Boolean.FALSE.toString().equals(annotation.getProperty(DocAnnotationConstants.SERIALIZE_PROP).toString())) { continue out; @@ -134,7 +134,7 @@ public class ParamsBuildHelper { } else if (null != annotation.getProperty(DocAnnotationConstants.NAME_PROP)) { 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)) { fieldName = StringUtil.removeQuotes(annotation.getProperty(DocAnnotationConstants.VALUE_PROP).toString()); } diff --git a/src/main/resources/template/Dictionary.btl b/src/main/resources/template/Dictionary.btl index 7160550..276eb12 100644 --- a/src/main/resources/template/Dictionary.btl +++ b/src/main/resources/template/Dictionary.btl @@ -1,5 +1,5 @@ <%if(isNotEmpty(dictList)){%> -# Data Dictionaries +# ${dictListTitle!"Data Dictionaries"} <% for(dict in dictList){ %>