Ubuntu下Swagger测试方法
一 环境准备与快速启动
二 交互式测试步骤
三 自动化与CI测试
四 常见问题与排查
五 附 最小可用示例
openapi: 3.0.0
info:
title: Sample API
version: 1.0.0
paths:
/hello:
get:
summary: 返回问候语
responses:
'200':
description: OK
content:
application/json:
schema:
type: object
properties:
message:
type: string
servers:
- url: http://localhost:3000
const express = require('express');
const swaggerUi = require('swagger-ui-express');
const YAML = require('yamljs');
const app = express();
const swaggerDocument = YAML.load('./swagger.yaml');
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument));
app.get('/hello', (req, res) => res.json({ message: 'Hello, World!' }));
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => console.log(`Server on http://localhost:${PORT}/api-docs`));