根据micronuat documentation https://micronaut-projects.github.io/micronaut-openapi/latest/guide/index.html#enableendpoints,尝试在最新版本的Micronaut中进行swagger OAuth配置
swagger-ui.oauth2RedirectUrl
swagger-ui.oauth2.clientId
swagger-ui.oauth2.clientSecret
swagger-ui.oauth2.realm
swagger-ui.oauth2.appName
swagger-ui.oauth2.scopeSeparator
swagger-ui.oauth2.scopes
swagger-ui.oauth2.additionalQueryStringParams
swagger-ui.oauth2.useBasicAuthenticationWithAccessCodeGrant
swagger-ui.oauth2.usePkceWithAuthorizationCodeGrant
当设置这些属性时,Micronaut不仅会生成swagger-ui/index.html文件,还会生成swagger-ui/oauth2-redirect.html文件
我可以看到它已经用下面的代码创建了文件oauth2-redirect.html
tasks.withType(JavaCompile).all {
options.forkOptions.jvmArgs << '-Dmicronaut.openapi.views.spec=swagger-ui.enabled=true,swagger-ui.theme=flattop,swagger-ui.oauth2RedirectUrl=http://localhost:8080/swagger-ui/oauth2-redirect.html,swagger-ui.oauth2.clientId=myClientId,swagger-ui.oauth2.scopes=openid,swagger-ui.oauth2.usePkceWithAuthorizationCodeGrant=true'
}
对于oauth2.clientId、oauth2RedirectUrl和oauth2.clientSecret,这些值对于每个环境PROD、TEST、DEV、UAT都是不同的。通过像上面的代码一样设置值,很难为每个环境进行配置。有没有更好的方法来做到这一点?
发布于 2021-11-17 14:36:32
在我的项目中,通过为每个环境创建不同的属性文件并使用参数控制编译,解决了这个问题
tasks.withType(JavaCompile) {
String openapiPropertyFile = 'openapi/openapi-dev.properties'
if(project.hasProperty("openapiPropertyFile")){
openapiPropertyFile = project.property('openapiPropertyFile')
}
options.fork = true
options.forkOptions.jvmArgs << "-Dmicronaut.openapi.config.file=$openapiPropertyFile"
}
然后你可以像这样构建它
$ sh ./gradlew clean jib -PopenapiPropertyFile=openapi/openapi-uat.properties -PimageSuffix=-uat
虽然我想知道如何编译这个帖子,因为在我的例子中,它会强制创建单独的docker镜像,然后在我想要创建一个的地方挂载这些属性。
https://stackoverflow.com/questions/67601800
复制相似问题