导入开放式API规范时,Azure API Management不遵守operationId

时间:2018-08-28 22:51:49

标签: azure-api-management

我有从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" } }
      }
    }
  }
}

enter image description here

以下示例摘自导入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" ]
      }
    }

enter image description here

1 个答案:

答案 0 :(得分:0)

APIM会遵守operationId,它的值用于将操作ID形成为Azure资源。在UI上看到的是操作标题。使用operationId作为标题是错误的,因为Open API规范说:

  

用于标识操作的唯一字符串。该ID在API中描述的所有操作中必须唯一。工具和库可以使用operationId唯一地标识一个操作,因此,建议遵循通用的编程命名约定。

一个人不想遵循带有操作标题的通用编程命名约定。因此,“摘要”字段代替了操作标题。

此处有更多详细信息:https://blogs.msdn.microsoft.com/apimanagement/2018/04/11/important-changes-to-openapi-import-and-export/