openAPI 3.0 не показывает кнопку "попробовать его" для конечных точек API - PullRequest
0 голосов
/ 26 марта 2020

Я настроил свой API с помощью swagger openapi3.0, но, к сожалению, он не показывает кнопку попробовать его для моих конечных точек API. мне не хватает какой-либо конфигурации в файле swagger? Может кто-нибудь помочь мне, как решить эту ошибку? here is the link to screenshot

Примечание: я использую 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"
          }
        }
      }
    }
   }
}

Вот конфигурация express, которую я использовал.

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));

Или, может быть, она должна быть опубликована на swagger-ui github как ошибка?

1 Ответ

0 голосов
/ 26 марта 2020

Я думаю, вам также нужно добавить description на сервер. Как то так

"servers": [
 {
  "description": "Local env",
  "url": "http://localhost:3000/api"
 }
]
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...