我有从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,它的值用于将操作ID形成为Azure资源。您在UI上看到的是操作标题。使用operationId作为标题是错误的,因为Open API规范说:
用于标识操作的唯一字符串。 id必须在API中描述的所有操作中是唯一的。工具和库可以使用operationId来唯一标识操作,因此,建议遵循常见的编程命名约定。
人们不希望遵循具有操作标题的通用编程命名约定。因此,“摘要”字段用于操作标题。