在 Ubuntu 上配置 Swagger,通常取决于你用的后端语言/框架。下面我按常见场景给你说明,你可以对号入座。
sudo apt update
sudo apt install openjdk-17-jdk maven -y
以 SpringDoc OpenAPI(推荐) 为例:
pom.xml
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.3.0</version>
</dependency>
mvn spring-boot:run
http://localhost:8080/swagger-ui.html
sudo apt install nodejs npm -y
npm init -y
npm install express swagger-ui-express yamljs
const express = require('express');
const swaggerUi = require('swagger-ui-express');
const YAML = require('yamljs');
const swaggerDocument = YAML.load('./swagger.yaml');
const app = express();
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument));
app.listen(3000, () => {
console.log('Swagger: http://localhost:3000/api-docs');
});
http://localhost:3000/api-docs
pip install fastapi uvicorn
FastAPI 自带 Swagger:
http://localhost:8000/docs
pip install flask flask-restx
docker run -d -p 8080:8080 swaggerapi/swagger-editor
访问:
http://localhost:8080
lsof -i:8080sudo ufw allow 8080
如果你能告诉我:
我可以给你更精确的配置示例。