在Ubuntu上查看Swagger API文档,您可以通过以下几种方法:
sudo apt update sudo apt install docker.io docker pull swaggerapi/swagger-ui-express docker run -p 8080:8080 swaggerapi/swagger-ui-express sudo apt update sudo apt install nodejs npm mkdir swagger-ui-project cd swagger-ui-project npm init -y npm install swagger-ui-express app.js 的文件,并添加以下代码:const express = require('express'); const swaggerUi = require('swagger-ui-express'); const YAML = require('yamljs'); // Load Swagger document const swaggerDocument = YAML.load('./swagger.yaml'); const app = express(); // Serve Swagger docs app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument)); const PORT = process.env.PORT || 3000; app.listen(PORT, () => { console.log(`Server is running on port ${PORT}`); }); swagger.yaml 的文件,并添加您的API文档。例如:swagger: '2.0' info: title: Sample API description: A sample API to demonstrate Swagger UI integration version: '1.0.0' paths: /users: get: summary: List all users responses: '200': description: An array of users schema: type: array items: $ref: '#/definitions/User' definitions: User: type: object properties: id: type: integer name: type: string node app.js 希望这些信息能帮助您在Ubuntu上找到并访问Swagger API文档。