简体   繁体   English

如何在 swagger-UI 中的 index.html 中设置 url

[英]How to set url in index.html in swagger-UI

I am using Swagger-UI for jax-rs jersey.我正在为 jax-rs jersey 使用 Swagger-UI。

So there is this index.html.于是就有了这个索引。html。 There you have to enter the url for the swagger.json.在那里你必须为 swagger.json 输入 url。

So this is a big problem.所以这是一个大问题。

We are deploying our application to a lot different environments.我们正在将我们的应用程序部署到许多不同的环境中。 And the respective swagger.json will always be on the same environment.并且相应的 swagger.json 将始终处于相同的环境中。 We have Jenkins build jobs and we cannot edit index.html for every environment.我们有 Jenkins 构建作业,我们无法为每个环境编辑 index.html。

    window.onload = function() {
  // Begin Swagger UI call region
  const ui = SwaggerUIBundle({
    url: "**https://petstore.swagger.io/v2/swagger.json**",

Property url I always have to set.属性 url 我总是必须设置。

What should I do?我应该怎么办?

PS附言

In Springfox Swagger-UI there is no physical swagger.json But in jax-rs I have this dist folder and there is always a physical json as far as I understand.在 Springfox Swagger-UI 中没有物理 swagger.json 但在 jax-rs 我有这个 dist 文件夹,据我所知,总是有一个物理 json。 Where should I put this so all different clients can access it.我应该把它放在哪里,以便所有不同的客户都可以访问它。

You can use vanilla JS for that:您可以为此使用香草 JS:

 var currentUrl = window.location.origin;
 var apiBasePath = currentUrl + '/v2';

 window.ui = SwaggerUIBundle({
        url: apiBasePath + "/swagger.json",
...
})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM