Skip to content

Commit 7e7b21c

Browse files
author
gitlab
committed
Merge branch 'api-doc-template-version' into 'master'
<fix>[doc]: use project.version for api doc template See merge request zstackio/zstack!3567
2 parents 7a640fb + fa787be commit 7e7b21c

File tree

1 file changed

+26
-10
lines changed

1 file changed

+26
-10
lines changed

rest/src/main/resources/scripts/RestDocumentationGenerator.groovy

+26-10
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package scripts
22

3+
34
import com.google.common.io.Resources
45
import groovy.json.JsonBuilder
56
import org.apache.commons.io.Charsets
7+
import org.apache.commons.io.FileUtils
68
import org.apache.commons.lang.StringUtils
79
import org.jsoup.Jsoup
810
import org.jsoup.nodes.Document
@@ -12,12 +14,7 @@ import org.jsoup.select.Elements
1214
import org.markdown4j.Markdown4jProcessor
1315
import org.springframework.http.HttpMethod
1416
import org.zstack.core.Platform
15-
import org.zstack.core.config.GlobalConfig
16-
import org.zstack.core.config.GlobalConfigDef
17-
import org.zstack.core.config.GlobalConfigDefinition
18-
import org.zstack.core.config.GlobalConfigException
19-
import org.zstack.core.config.GlobalConfigValidation
20-
import org.zstack.core.config.GlobalConfigValidatorExtensionPoint
17+
import org.zstack.core.config.*
2118
import org.zstack.header.core.NoDoc
2219
import org.zstack.header.errorcode.ErrorCode
2320
import org.zstack.header.exception.CloudRuntimeException
@@ -30,9 +27,9 @@ import org.zstack.header.query.APIQueryMessage
3027
import org.zstack.header.rest.APINoSee
3128
import org.zstack.header.rest.RestRequest
3229
import org.zstack.header.rest.RestResponse
30+
import org.zstack.resourceconfig.BindResourceConfig
3331
import org.zstack.rest.RestConstants
3432
import org.zstack.rest.sdk.DocumentGenerator
35-
import org.zstack.resourceconfig.BindResourceConfig
3633
import org.zstack.utils.*
3734
import org.zstack.utils.data.StringTemplate
3835
import org.zstack.utils.gson.JSONObjectUtil
@@ -51,6 +48,7 @@ import java.nio.file.Paths
5148
import java.util.regex.Matcher
5249
import java.util.regex.Pattern
5350
import java.util.stream.Collectors
51+
5452
/**
5553
* Created by xing5 on 2016/12/21.
5654
*/
@@ -435,6 +433,8 @@ class RestDocumentationGenerator implements DocumentGenerator {
435433

436434
String rootPath
437435

436+
String projectVersion
437+
438438
Map<String, File> sourceFiles = [:]
439439

440440
def MUTUAL_FIELDS = [
@@ -505,9 +505,25 @@ class RestDocumentationGenerator implements DocumentGenerator {
505505
c(emc)
506506
}
507507

508+
void tryInitVersionOfCurrentRepo() {
509+
def f = new File("${rootPath}/VERSION")
510+
if (!f.exists()) {
511+
println("missing version file[path: ${rootPath}/VERSION]")
512+
return
513+
}
514+
515+
def versionNumber = []
516+
FileUtils.readLines(f).each { String line ->
517+
versionNumber.add(line.split("=")[1].trim())
518+
}
519+
520+
projectVersion = versionNumber.join(".")
521+
}
522+
508523
@Override
509524
void generateDocTemplates(String scanPath, DocMode mode) {
510525
rootPath = scanPath
526+
tryInitVersionOfCurrentRepo()
511527
scanJavaSourceFiles()
512528

513529
Set<Class> apiClasses = getRequestRequestApiSet()
@@ -2081,7 +2097,7 @@ ${txt}
20812097
\t\tname "${n}"
20822098
\t\tdesc "${desc == null ? "" : desc}"
20832099
\t\ttype "${type}"
2084-
\t\tsince "0.6"
2100+
\t\tsince "${projectVersion != null ? projectVersion : "0.6"}"
20852101
\t}"""
20862102
}
20872103

@@ -2097,7 +2113,7 @@ ${txt}
20972113
\t\tpath "${path}"
20982114
\t\tdesc "${desc}"${overrideDesc != null ? ",${overrideDesc}" : ""}
20992115
\t\ttype "${type}"
2100-
\t\tsince "0.6"
2116+
\t\tsince "${projectVersion != null ? projectVersion : "0.6"}"
21012117
\t\tclz ${clz.simpleName}.class
21022118
\t}"""
21032119
}
@@ -2273,7 +2289,7 @@ ${fieldStr}
22732289
\t\t\t\t\tlocation "${location}"
22742290
\t\t\t\t\ttype "${af.type.simpleName}"
22752291
\t\t\t\t\toptional ${ap == null ? true : !ap.required()}
2276-
\t\t\t\t\tsince "0.6"
2292+
\t\t\t\t\tsince "${projectVersion != null ? projectVersion : "0.6"}"
22772293
""")
22782294
if (values != null) {
22792295
cols.add("\t\t\t\t\t${values}")

0 commit comments

Comments
 (0)