Tôi đang cố gắng để xây dựng các thiết lập Swagger cho SecurityDefinition để có được kết quả sau trong openapi.json:Django REST Swagger: Cách sử dụng phần bảo mật trong cài đặt Swagger?
"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"]
}]
Trong settings.py của tôi, tôi đã addded các thiết lập vênh vang sau:
# 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"]
}]
}
Vấn đề là trong openapi.json được tạo ra bởi Swagger không có số security
dict và tôi không có đầu mối nó được tạo ra như thế nào.
Dưới đây, trình bày openapi.json tạo:
{
"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": {...}
}
Có cách nào tốt hơn để mô tả khái niệm này trong cài đặt Swagger của tôi? Hoặc bạn có thể mô tả tôi là quy trình và cách thức hoạt động của nó để tạo tệp openapi.json không?
Bạn có thể đăng nội dung tệp openapi.json để dễ dàng gỡ lỗi –
Tôi vừa cập nhật câu hỏi! –
Tại sao u xây dựng dict bên trong danh sách để xác định AN NINH? Hãy thử nó với dict đồng bằng. –