diff --git a/README.md b/README.md index 64fae1c..363cfc3 100644 --- a/README.md +++ b/README.md @@ -134,6 +134,9 @@ When you need to use smart-doc to generate more API document information, you ca "version":"1.0.0" } ], + "apiConstants": [{//Configure your own constant class, smart-doc automatically replaces with a specific value when parsing to a constant + "constantsClassName": "com.power.doc.constants.RequestParamConstant" + }],   "requestHeaders": [// Set global request headers, no need to set     {       "name": "token", diff --git a/README_CN.md b/README_CN.md index b6686a6..54f2e89 100644 --- a/README_CN.md +++ b/README_CN.md @@ -132,7 +132,9 @@ subprojects{ "since": "-" } ], - + "apiConstants": [{//从1.8.9开始配置自己的常量类,smart-doc在解析到常量时自动替换为具体的值 + "constantsClassName": "com.power.doc.constants.RequestParamConstant" + }], "sourceCodePaths": [ //设置代码路径,默认加载src/main/java, 没有需求可以不设置 { "path": "src/main/java", diff --git a/build.gradle b/build.gradle index 600d168..eda38a8 100644 --- a/build.gradle +++ b/build.gradle @@ -15,7 +15,7 @@ plugins { } group 'com.github.shalousun' -version '1.1.0' +version '1.1.1' sourceCompatibility = 1.8 diff --git a/src/main/java/com/smartdoc/gradle/util/GradleUtil.java b/src/main/java/com/smartdoc/gradle/util/GradleUtil.java index 89291d3..5dfb3ea 100644 --- a/src/main/java/com/smartdoc/gradle/util/GradleUtil.java +++ b/src/main/java/com/smartdoc/gradle/util/GradleUtil.java @@ -27,10 +27,7 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.power.common.util.FileUtil; -import com.power.doc.model.ApiConfig; -import com.power.doc.model.ApiDataDictionary; -import com.power.doc.model.ApiErrorCodeDictionary; -import com.power.doc.model.SourceCodePath; +import com.power.doc.model.*; import org.apache.commons.lang3.StringUtils; import java.io.File; @@ -77,6 +74,7 @@ public static ApiConfig buildConfig(File configFile, Project project, Logger log ApiConfig apiConfig = GSON.fromJson(data, ApiConfig.class); List apiDataDictionaries = apiConfig.getDataDictionaries(); List apiErrorCodes = apiConfig.getErrorCodeDictionaries(); + List apiConstants = apiConfig.getApiConstants(); if (apiErrorCodes != null) { apiErrorCodes.forEach( apiErrorCode -> { @@ -93,6 +91,14 @@ public static ApiConfig buildConfig(File configFile, Project project, Logger log } ); } + if (apiConstants != null) { + apiConstants.forEach( + apiConstant -> { + String className = apiConstant.getConstantsClassName(); + apiConstant.setConstantsClass(getClassByClassName(className, classLoader)); + } + ); + } addSourcePaths(project, apiConfig, log); return apiConfig; } catch (FileNotFoundException e) {