OpenAPI 规范 v3.1.0
OpenAPI 规范 v3.1.0
1. OpenAPI 规范
2. 简介
3. 定义
4. 规范
4.1 版本
4.2 格式
4.3 文档结构
4.4 数据类型
4.5 富文本格式化
4.6 URI 中的相对引用
4.7 URL 中的相对引用
4.8 模式
4.8.1 OpenAPI 对象
4.8.2 Info 对象
4.8.3 Contact 对象
4.8.4 License 对象
4.8.5 Server 对象
4.8.6 Server Variable 对象
4.8.7 Components 对象
4.8.8 Paths 对象
4.8.9 Path Item 对象
4.8.10 Operation 对象
4.8.11 External Documentation 对象
4.8.12 Parameter 对象
4.8.13 Request Body 对象
4.8.14 Media Type 对象
4.8.15 Encoding 对象
4.8.16 Responses 对象
4.8.17 Response 对象
4.8.18 Callback 对象
4.8.19 Example 对象
4.8.20 Link 对象
4.8.21 Header 对象
4.8.22 Tag 对象
4.8.23 Reference 对象
4.8.24 Schema 对象
4.8.25 Discriminator 对象
4.8.26 XML 对象
4.8.27 Security Scheme 对象
4.8.28 OAuth Flows 对象
4.8.29 OAuth Flow 对象
4.8.30 Security Requirement 对象
4.9 规范扩展
4.10 安全过滤
4.8.27 Security Scheme 对象
创建时间: 2025-05-29 16:38
定义操作可以使用的一种安全方案。 支持的方案包括HTTP身份验证、API密钥(作为标头、cookie参数或查询参数)、双向TLS(使用客户端证书)、OAuth2的常用流程(隐式、密码、客户端凭据和授权码),如[RFC6749]中所定义,以及OpenID Connect Discovery。请注意,截至2020年,隐式流程即将被OAuth 2.0 Security Best Current Practice弃用。对于大多数用例,建议使用带PKCE的授权码授予流程。
4.8.27.1 固定字段
字段名称 | 类型 | 应用于 | 描述 |
---|---|---|---|
类型 | 字符串 | 任何 | 必需。安全方案的类型。有效值为"apiKey" 、"http" 、"mutualTLS" 、"oauth2" 、"openIdConnect" 。 |
描述 | 字符串 | 任何 | 安全方案的描述。[CommonMark]语法可以用于富文本表示。 |
名称 | 字符串 | apiKey | 必需。要使用的标头、查询或cookie参数的名称。 |
位置 | 字符串 | apiKey | 必需。API密钥的位置。有效值为"query" 、"header" 或"cookie" 。 |
方案 | 字符串 | http | 必需。如[RFC7235] 第5.1节中所定义,在Authorization标头中使用的HTTP授权方案的名称。使用的值应该在IANA身份验证方案注册表中注册。 |
bearer格式 | 字符串 | http ("bearer" ) | 提示客户端识别承载令牌的格式。承载令牌通常由授权服务器生成,因此此信息主要用于文档目的。 |
流程 | OAuth流程对象 | oauth2 | 必需。包含支持的流程类型配置信息的 对象。 |
OpenId Connect URL | 字符串 | openIdConnect | 必需。用于发现OAuth2配置值的OpenId Connect URL。这必须采用URL的形式。OpenID Connect标准要求使用TLS。 |
此对象*可以使用 规范扩展 进行扩展。
4.8.27.2 Security Scheme 对象示例
4.8.27.2.1 基本身份验证示例
{
"type": "http",
"scheme": "basic"
}
type: http
scheme: basic
4.8.27.2.2 API 密钥示例
{
"type": "apiKey",
"name": "api_key",
"in": "header"
}
type: apiKey
name: api_key
in: header
4.8.27.2.3 JWT Bearer 示例
{
"type": "http",
"scheme": "bearer",
"bearerFormat": "JWT",
}
type: http
scheme: bearer
bearerFormat: JWT
4.8.27.2.4 隐式 OAuth2 示例
{
"type": "oauth2",
"flows": {
"implicit": {
"authorizationUrl": "https://example.com/api/oauth/dialog",
"scopes": {
"write:pets": "modify pets in your account",
"read:pets": "read your pets"
}
}
}
}
type: oauth2
flows:
implicit:
authorizationUrl: https://example.com/api/oauth/dialog
scopes:
write:pets: modify pets in your account
read:pets: read your pets
最后更新: -