我正在尝试为SecurityDefinition构建Swagger设置,以便在openapi.json中获得以下结果:
"securityDefinitions": { "password": { "type": "oauth2", "tokenUrl": "http://example.com/oauth/token", "flow": "password", "scopes": { "write": "allows modifying resources", "read": "allows reading resources" } } }, "security": [{ "password": ["read", "write"] }]
在我的settings.py中,我添加了以下swagger设置:
# Swagger settings SWAGGER_SETTINGS = { "SECURITY_DEFINITIONS": { "password": { "type": "oauth2", "tokenUrl": "http://example.com/oauth/token", "flow": "password", "scopes": { "write": "allows modifying resources", "read": "allows reading resources" } } }, "SECURITY": [{ "password": ["read", "write"] }] }
问题是在Swagger生成的openapi.json中没有security
dict,我也不知道它是如何生成的.
下面,介绍了生成的openapi.json:
{ "info": { "title": "Example Service API", "version": "" }, "host": "http://example.com", "swagger": "2.0", "securityDefinitions": { "password": { "type": "oauth2", "scopes": { "write": "allows modifying resources", "read": "allows reading resources" }, "tokenUrl": "http://example.com/oauth/token", "flow": "password" } }, "paths": {...} }
有没有更好的方法在我的Swagger设置中描述这个概念?或者你能描述一下这个过程以及它是如何工作以生成openapi.json文件的吗?