【发布时间】:2025-12-30 11:05:10
【问题描述】:
我正在使用 springfox 从 spring 控制器生成 swagger 文档。当访问 http://127.0.0.1:8080/mycontextroot/swagger-ui.html 时,我得到了 有效的招摇 UI!
但是当我尝试打开从http://127.0.0.1:8080/mycontextroot/v2/api-docs 生成的相同yaml(或json)文件但通过https://editor.swagger.io/ 时,我得到了错误:
大摇大摆的例子:
---
swagger: '2.0'
info:
description: Api Documentation
version: '1.0'
title: Api Documentation
termsOfService: urn:tos
contact: {}
license:
name: Apache 2.0
url: http://www.apache.org/licenses/LICENSE-2.0
host: 127.0.0.1:8080
basePath: "/"
paths:
"/mycontextroot/blogs":
get:
summary: blogs
operationId: blogsUsingGET
produces:
- "*/*"
responses:
'200':
description: OK
schema:
"$ref": "#/definitions/Blogs"
'401':
description: Unauthorized
'403':
description: Forbidden
'404':
description: Not Found
security:
- xauth:
- global
deprecated: false
securityDefinitions:
xauth:
type: apiKey
name: my-auth-header
in: header
definitions:
Blog:
type: object
properties:
title:
type: string
title: Blog
Blogs:
type: object
properties:
blogs:
type: array
items:
"$ref": "#/definitions/Blog"
title: Blogs
【问题讨论】:
-
有人解决这个问题吗?
标签: spring spring-boot swagger springfox