【问题标题】:openAPI 3.0 is not showing try it out button for API endpointsopenAPI 3.0 未显示 API 端点的试用按钮
【发布时间】:2020-07-06 23:13:59
【问题描述】:

我已经用 swagger openapi3.0 配置了我的 api,不幸的是,它没有显示我的 API 端点的试用按钮。我是否缺少招摇文件中的任何配置?谁能帮我解决这个错误?

注意:我使用的是swagger open API3.0 这是我使用的配置:


{
  "openapi": "3.0.0",
  "info": {
    "version": "1.0.0",
    "title": "Reinvent-API",
    "description": "Reusable and minimalistic API for Hyperledger-fabric Networks",
    "contact": {
      "name": "Dev",
      "email": "dev@gmail.com",
      "url": "https://dev.github.io/"
    },
    "license": {
      "name": "MIT",
      "url": "https://opensource.org/licenses/MIT"
    }
  },
  "servers": [
    {
      "url": "http://localhost:3000/api"
    }
  ],

  "paths": {
     "/invoke": {
      "post": {
        "tags": [
      "API Explorer"
    ],
        "description": "invoke chaincode function",
        "operationId": "invoke",
        "requestBody": {
          "description": "body parameters should be passed as the order defined in chaincode function. First argument must be function name to call.",
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/invoke"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Chaincode Invoke Succesfull.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/invoke"
                }
              }
            }
          }
        }
      }
    }
  },
   "components": {
    "schemas": {
      "invoke": {
        "properties": {
          "fcn": {
            "type": "string"
          },
          "arg1": {
            "type": "string"
          },
          "arg2": {
            "type": "string"
          }
        }
      }
    }
   }
}

这是我使用的快速配置。

var express = require('express');

var bodyParser = require('body-parser');

var app = express();

app.use(bodyParser.json());

swaggerUi = require('swagger-ui-express')

swaggerDocument = require('./swagger.json');

app.use(bodyParser.urlencoded({ extended: true }));
var options = {
  swaggerOptions: {
    supportedSubmitMethods:["get", "post"]
  }
};

app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument, options));

或者应该把它作为一个 bug 发布到 swagger-ui github 上?

【问题讨论】:

  • 您找到解决方案了吗?看起来需要启用 CORS?
  • 我可以通过将swagger-ui-express npm 模块更新到最新版本来修复它

标签: node.js api swagger swagger-ui openapi


【解决方案1】:

我认为您还需要向服务器添加description。像这样的

"servers": [
 {
  "description": "Local env",
  "url": "http://localhost:3000/api"
 }
]

【讨论】:

  • 试过了 Radu Dita。没有运气。
猜你喜欢
  • 2018-12-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-01-18
  • 1970-01-01
相关资源
最近更新 更多