我正在使用 springfox 从 Spring Controller 生成 swagger 文档。访问时http://127.0.0.1:8080/mycontextroot/swagger-ui.html
我有 Swagger 的 UI 作品!
但是当我尝试打开相同的 yaml
(或 json
)从 http://127.0.0.1:8080/mycontextroot/v2/api-docs
生成的文件但通过 https://editor.swagger.io/
我有错误:
Swagger 示例:
---
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
最佳答案
我遇到过同样的问题。无效的原因是:
security:
- xauth:
- global
那需要是:
security:
- xauth: []
如果您通过 Java 生成 swagger,请应用:
private List<SecurityReference> defaultAuth() {
return Lists.newArrayList(new SecurityReference("xauth", new AuthorizationScope[0]));
}
关于spring - 如何修复 springfox 中的 "Security scope definition global could not be resolved"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54648227/