我正在運行一個 Spring Boot 應用程式,這就是當前代碼的樣子。
swagger {
apiSource {
locations = [ 'com.test.TestControllerV1' ]
schemes = [ 'http', 'https' ]
swaggerDirectory = "${buildDir}/documentation/v1/"
}
apiSource {
locations = [ 'com.test.TestControllerV2' ]
schemes = [ 'http', 'https' ]
swaggerDirectory = "${buildDir}/v2/"
}
apiSource {
locations = [ 'com.test.DummyControllerV1' ]
schemes = [ 'http', 'https' ]
swaggerDirectory = "${buildDir}/v1/"
}
}
apiSource而不是每次我想在回圈中運行它時都重復,就像這樣。(這里的語法不正確)。
swagger {
for(swaggerDetail in details){
apiSource {
locations = [ "$swaggerDetail.path" ]
schemes = [ 'http', 'https' ]
swaggerDirectory = "$swaggerDetail.buildPath"
}
}
}
有什么好的方法可以實作這一目標嗎?我可以在哪里存盤detailshashmap 的值?
uj5u.com熱心網友回復:
Gradle 構建腳本是代碼,因此您可以使用像Maps這樣的 Groovy 語言功能(如果您使用 Kotlin DSL,則可以使用等效的 Kotlin 功能)
您可以創建一個簡單的基于地圖的結構,其中包含apiSource每個 API 版本的主要屬性,并迭代其他此結構以配置swagger擴展;下面是一個非常簡單的例子:
// array containing your different API configs
def apiConfigs = [
[basePath: "/v1", location: "com.test.v1", swaggerDirectory: "${buildDir}/v1/"],
[basePath: "/v2", location: "com.test.v2", swaggerDirectory: "${buildDir}/v2/"]
]
swagger {
apiConfigs.forEach { config ->
apiSource {
// groovy lets you access the config map using notation config["$fieldName"]
locations = [config["location"]]
swaggerDirectory = config["swaggerDirectory"]
basePath = config["basePath"]
springmvc = true
schemes = ['http', 'https']
host = 'www.example.com:8080'
// ...
}
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/528592.html
下一篇:c|如何改進字符檢查
