在 Linux 环境下“调试 Swagger”通常涉及几种不同场景:
下面按常见场景给你一套可落地的调试思路。
ps -ef | grep swagger
netstat -tunlp | grep 8080
# 或
ss -tunlp | grep 8080
curl http://localhost:8080/swagger-ui.html
curl http://localhost:8080/v3/api-docs
如果是远程服务器:
curl http://<服务器IP>:端口/swagger-ui.html
spring:
mvc:
pathmatch:
matching-strategy: ant_path_matcher
@Override
public void configure(WebSecurity web) {
web.ignoring().antMatchers(
"/swagger-ui.html",
"/swagger-ui/**",
"/v3/api-docs/**",
"/webjars/**"
);
}
location /swagger-ui/ {
proxy_pass http://backend/swagger-ui/;
}
重点看:
/v3/api-docscurl http://localhost:8080/v3/api-docs | jq
如果返回为空 {}:
@RestController / @Operation)@SpringBootApplication
@OpenAPIDefinition(info = @Info(title = "API", version = "1.0"))
public class App {}
journalctl -u your-service
# 或
tail -f logs/app.log
curl -X POST http://localhost:8080/api/login \
-H "Content-Type: application/json" \
-d '{"username":"admin","password":"123456"}'
@RequestParam vs @RequestBody)swagger-codegen generate \
-i api.yaml \
-l java \
-o out/
swagger-codegen validate -i api.yaml
# 1. 看端口
ss -tunlp
# 2. 看接口
curl http://localhost:8080/v3/api-docs
# 3. 看日志
tail -f app.log
# 4. 浏览器 F12
你可以补充:
我可以直接给你对应配置文件和排错命令。