要快速学会在 Linux 上使用 Swagger(一般指 OpenAPI + Swagger UI / Swagger Editor / Swagger Codegen),可以按下面这条「最短路径」来学,少走弯路。
不同目的,学法完全不同:
# 用 Docker 最简单
docker run -p 8080:8080 swaggerapi/swagger-ui
浏览器访问:
http://localhost:8080
✅ 你能立刻看到 Swagger 长什么样
新建 swagger.yaml:
openapi: 3.0.0
info:
title: Demo API
version: 1.0.0
paths:
/hello:
get:
summary: say hello
responses:
'200':
description: OK
用 Swagger Editor:
docker run -p 8081:8080 swaggerapi/swagger-editor
访问 http://localhost:8081
✅ 这是 Swagger 的“灵魂”
@SpringBootApplication
@EnableSwagger2
public class App {}
访问:
/swagger-ui.html
swag init
访问:
/swagger/index.html
npm i swagger-ui-express
你现在是 Linux + 哪种语言?