在Ubuntu上调用Swagger API通常涉及以下几个步骤:
sudo apt update
sudo apt install -y nodejs npm
sudo npm install -g swagger-ui
git clone https://github.com/swagger-api/swagger-ui.git
cd swagger-ui
npm install
node dist/index.js
wget https://github.com/swagger-api/swagger-ui/archive/refs/tags/v4.12.0.zip
unzip v4.12.0.zip
cd swagger-ui-4.12.0
npm install
node dist/index.js
swagger.yaml
或swagger.json
):openapi: 3.0.0
info:
title: My API
version: 1.0.0
description: API documentation with Swagger
servers:
- url: http://localhost:3000
paths:
/users:
get:
summary: Get a list of all users
operationId: getAllUsers
responses:
200:
description: A list of users
400:
description: Invalid input
docker pull swaggerapi/swagger-editor
docker run -p 8080:8080 swaggerapi/swagger-editor
在Swagger Editor中编辑并保存为JSON或YAML格式,然后导入到你的项目中。
node dist/index.js
index.js
文件存在并正确配置。http://localhost:3000/api-docs
(或你配置的其他端口)。通过以上步骤,你应该能够在Ubuntu上成功调用Swagger API并进行测试。如果有任何问题,可以参考Swagger官方文档或相关社区资源。