gpt4 book ai didi

swagger - swagger-ui文档中如何使用本地json文件

转载 作者:行者123 更新时间:2023-12-02 17:05:17 32 4
gpt4 key购买 nike

我正在尝试使用本地 swagger.json 文件在 swagger 文档中显示。

我的 swagger.json 文件位于/home/user1/swagger-ui/dist/swagger.json 下,index.html 位于同一目录下。我修改了index.html如下。

 window.swaggerUi = new SwaggerUi({
spec: ../swagger.json
url: url,
dom_id: "swagger-ui-container",

使用docker run -p 80:8080 swagger-ui-builder启动docker实例后,访问http://192.168.xx.xx/不显示文档。附上屏幕截图以供引用。请帮我解决这个问题。 enter image description here

最佳答案

问题中提供的示例根本无法工作(缺少逗号和 spec 不是 SwaggerUI 属性)。

要显示与 index.html 位于同一文件夹中的 swagger.json 文件,您只需替换 url = "http://petstore .swagger.io/v2/swagger.json" by url = "swagger.json"; in index.html

原始index.html

      var url = window.location.search.match(/url=([^&]+)/);
if (url && url.length > 1) {
url = decodeURIComponent(url[1]);
} else {
url = "http://petstore.swagger.io/v2/swagger.json";
}

[...]

window.swaggerUi = new SwaggerUi({
url: url,
dom_id: "swagger-ui-container",
supportedSubmitMethods: ['get', 'post', 'put', 'delete', 'patch'],
onComplete: function(swaggerApi, swaggerUi){
if(typeof initOAuth == "function") {
initOAuth({
clientId: "your-client-id",
clientSecret: "your-client-secret-if-required",
realm: "your-realms",
appName: "your-app-name",
scopeSeparator: ",",
additionalQueryStringParams: {}
});
}

修改:

      var url = window.location.search.match(/url=([^&]+)/);
if (url && url.length > 1) {
url = decodeURIComponent(url[1]);
} else {
url = "swagger.json";
}

[...]

window.swaggerUi = new SwaggerUi({
url: url,
dom_id: "swagger-ui-container",
supportedSubmitMethods: ['get', 'post', 'put', 'delete', 'patch'],
onComplete: function(swaggerApi, swaggerUi){
if(typeof initOAuth == "function") {
initOAuth({
clientId: "your-client-id",
clientSecret: "your-client-secret-if-required",
realm: "your-realms",
appName: "your-app-name",
scopeSeparator: ",",
additionalQueryStringParams: {}
});
}

关于swagger - swagger-ui文档中如何使用本地json文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38305319/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com