0
When I hit http://localhost:3001/api-docs loads the swagger json docs.

{
swagger: "2.0",
info: {
version: "1.0.0",
title: "Auth-gateway services",
contact: {
name: "swagger docs",
url: "https://www.google.com"
}
},
host: "127.0.0.1:3001",
basePath: "/",
...
}

しかし、API 用にhttp://petstore.swagger.io/のような UI をロードするにはどうすればよいですか。

4

1 に答える 1

0

swagger-ui を使用して API を表示するには、次のいずれかを実行します。

オプション 1: オンラインの swagger-ui を使用する

  1. これに行きます
  2. ページ上部のダイアログ ボックスで、swagger-json の URL を指定します。あなたの場合、http://petstore.swagger.io/v2/swagger.json (デフォルトで表示されます)の代わりにhttp://localhost:3001/api-docsを挿入し、 Exploreをクリックします。
  3. これで、API 用に生成された swagger-ui を確認できます。

オプション 2: swagger-ui プロジェクトをローカルでセットアップする

swagger-uiを設定する必要があります。以下の手順に従って、プロジェクトのセットアップを複製できます。

Windows Users: Please install Python before follow below guidelines
for node-gyp rebuild to run.

1. npm install
2. npm run build
3. You should see the distribution under the dist folder. Open ./dist/index.html to launch Swagger UI in a browser

Development

Use npm run serve to make a new build, watch for changes, and serve the result at http://localhost:8080/.

これで、 online swagger-uiとまったく同じものが表示されるはずです。

オプション 1 と同じことを実行して、swagger-json の URL を提供し、生成された swagger-ui を確認します。

于 2016-07-16T08:16:51.193 に答える