【发布时间】:2015-04-23 08:04:27
【问题描述】:
【问题讨论】:
-
@suresh2 这会起作用,但正在寻找是否可以将其作为安全方案的答案。据我所知,这只是一个必需的参数。这可能有效,如果可能的话,只想使用安全方案。
标签: swagger
【问题讨论】:
标签: swagger
是的,OpenAPI (Swagger) 2.0 和 3.0 允许您定义多个安全定义并将一个操作标记为需要多个安全性,例如一对 API 密钥。
在下面的示例中,我定义了两个 API 密钥,Key 和 SecretKey,这两个密钥都应该出现在每个请求的标头中才能通过身份验证。
swagger: '2.0'
info:
version: 0.0.0
title: Simple API
securityDefinitions:
key:
type: apiKey
in: header
name: Key
secret_key:
type: apiKey
in: header
name: SecretKey
# Or if you use OpenAPI 3.0:
# components:
# securitySchemes:
# key:
# type: apiKey
# in: header
# name: Key
# secret_key:
# type: apiKey
# in: header
# name: SecretKey
paths:
/:
get:
# Both 'Key' and 'SecretKey' must be used together
security:
- key: []
secret_key: []
responses:
200:
description: OK
请注意,这与
不同 security:
- key: []
- secret_key: [] # <-- Note the leading dash here
这意味着端点需要Key 或SecretKey,但不能同时使用两者。
【讨论】:
can have multiple security schemes 以及规范中的实际含义。
swagger-ui.html 文件中,您的API URL 旁边的标题栏中会出现一个按钮,名称为“授权”。单击该按钮以使用您的 API 密钥登录,并从现在开始使用该密钥发送请求。