SpringBoot jar项目+ swaggerUI +厨师+动态变量 [英] SpringBoot jar project + swaggerUI + chef + dynamic variables

查看:144
本文介绍了SpringBoot jar项目+ swaggerUI +厨师+动态变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个SpringBoot应用程序,使用Swagger的API文档和Swagger-UI进行渲染。



在使用swagger-ui中的任何端点之前需要检索一个承载令牌,为此使用clientID和授权端点。



我有两个不同的环境,其中clientID和授权端点都不同。



我正在使用厨师来处理我的应用程序的部署(这是一个以java -jar myapi.jar开头的JAR),它为每个应用程序构建了一个不同的application.properties环境,但是因为clientID和auth url在swagger-ui的index.html中,并且您的文件在jar内部,我不知道如何使用厨师在部署时替换这些值。



有没有办法我可以通过这些价值观?或者唯一的解决方案是没有一个JAR,但是一个爆炸的jar?



TLDR:我想要能够替换index.html中的值,具体取决于环境p>

解决方案

我没有意识到springboot / swagger中的任何东西可以让你传递值到静态文件(也称为$ {clientId} from你的index.html)



你可以做什么,但是有一个包含


$ b $的厨师模板(一个简单的json文件就足够了) b

  {
clientID:..
authUrl:..
}
/ pre>

你将厨师写在同一个index.html的目录下,在你的index.html中写一些javascript来加载该文件。 >

I have a SpringBoot application that uses Swagger for the API doc and Swagger-UI for rendering it.

Before using the any of the endpoints from swagger-ui I need to retrieve a bearer token and for this a clientID and an authorize endpoint are used

I have 2 different environment where both the clientID and the authorize endpoint are different.

I'm using chef to handle the deployment of my app (which is a JAR started as java -jar myapi.jar) which builds a different application.properties for each environment but because the clientID and auth url are in the swagger-ui's index.html and that thee files are INSIDE the jar I don't know how to use chef to replace these values at deploy time.

Is there a way I can passed these values somehow? Or the only solution is to not have a JAR but an exploded jar ?

TLDR: I want to be able replace values in the index.html depending on the environement

解决方案

I;m not aware of anything in springboot/swagger that let you pass values to the static files (aka ${clientId} from your index.html)

What you could do though is having chef template (a simple json file can be enough) containing

{
 "clientID":..
 "authUrl: ..
}

That you make chef write in the same directory where your index.html is. And in your index.html write some javascript to load that file.

这篇关于SpringBoot jar项目+ swaggerUI +厨师+动态变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆