azure-api-management - 导入开放 API 规范时 Azure API 管理不遵守 operationId
问题描述
我有从 Swashbuckle 生成的 swagger.json。将开放 API 规范导入 Azure API 管理时,不使用 operationId 作为操作的名称。相反,它使用描述。我附上了产生问题的 JSON 样本。
{
"swagger": "2.0",
"info": {
"version": "v1",
"title": "Route Manager API"
},
"paths": {
"/api/account/Logout": {
"post": {
"tags": [ "Account" ],
"summary": "Logs the current user out of the system.",
"operationId": "ApiAccountLogoutPost",
"consumes": [],
"produces": [],
"parameters": [],
"responses": { "200": { "description": "Logout successfully performed" } }
}
}
}
}
以下示例在导入 Open API 规范时取自 Microsoft 文档,并且似乎使用 OperationId 作为名称 (GetSessions) 确实显示为 API 管理中函数的标题。
"paths": {
"/sessions": {
"get": {
"description": "A list of sessions. Optional parameters work as filters to reduce the listed sessions.",
"operationId": "GetSessions",
"parameters": [
{
"name": "speakername",
"in": "query",
"type": "string"
},
{
"name": "dayno",
"in": "query",
"description": "Format - int32.",
"type": "integer"
},
{
"name": "keyword",
"in": "query",
"type": "string"
}
],
"responses": { "200": { "description": "OK" } },
"produces": [ "application/vnd.collection+json" ]
}
}
解决方案
APIM 确实尊重 operationId,它的值用于将 operation id 形成为 Azure 资源。您在 UI 上看到的是操作标题。使用 operationId 作为标题是错误的,因为 Open API 规范说:
用于标识操作的唯一字符串。在 API 中描述的所有操作中,id 必须是唯一的。工具和库可以使用 operationId 来唯一标识一个操作,因此,建议遵循常见的编程命名约定。
人们不希望使用操作标题遵循常见的编程命名约定。因此,“摘要”字段被用于操作标题。
推荐阅读
- gnuradio-companion - 通过 TCP/LAN 协议将数据从 GNU Radio 伴侣发送到其他软件
- javascript - 更改列表后更改班级
- python - 张量流概率没有给出与 PyMC3 相同的结果
- python - 显示带有线性回归 sklearn 的图
- node.js - Jupyter labextension install @jupyterlab/toc 返回错误:Jupyterlab 构建失败
- javascript - 使用 PIXI JS 在我的画布中未显示图像精灵
- javascript - Lodash 从嵌套对象中提取值
- symfony - 使用 Symfony Monolog 向微软团队发送消息
- api-platform.com - 两台防火墙共用同一个型号
- r - R中的randomForest中使用了哪种决策树算法?