首页 > 解决方案 > 如何在 OpenAPI 中指定将用户添加到组?

问题描述

我正在尝试为 MS Flow\Logic Apps 创建一个自定义连接器,该连接器使用一些属于 microsoft graph 的 REST 端点,但在理解如何在 OpenAPI 2.0 规范中记录 API 时遇到了麻烦

质谱文档

https://docs.microsoft.com/en-us/graph/api/group-post-owners?view=graph-rest-1.0#example

说包括

"@odata.id": "https://graph.microsoft.com/v1.0/users/{id}"

作为请求正文的一部分的 $ref 参数

但是如何在 OpenAPI 2.0 规范中记录这一点?

这是我到目前为止所得到的......

'/groups/{team-id}/owners':
    post:
      tags:
        - teams.team
      summary: Add a new owner to the team
      operationId: teams.AddOwner
      consumes:
        - application/json
      parameters:
        - name: team-id
          in: path
          required: true
          type: string
          description: Id of the MS team
          x-ms-summary: Team Id
          x-ms-visibility: important
        - name: body
          in: body
          required: true
          schema:
            type: object
            properties:
              userId:
                type: string
                description: Id of the user to be added as an owner to the team
                x-ms-summary: User Id
                x-ms-visibility: important
              '@odata.id':
                default: https://graph.microsoft.com/v1.0/users/{userId}
      responses:
        '204':
          description: Success
        default:
          $ref: '#/responses/error'
      x-ms-docs-operation-type: operation

当我提交上述内容以创建自定义连接器时,出现以下错误

指定的文件与 OpenAPI 2.0 规范不匹配:'JSON 对来自 'oneOf' 的无模式有效。路径'paths./groups/{team-id}/owners.post.parameters[1]'。

编辑

我已将 OpenAPI 更新为如下所示

这意味着我可以导入和使用它……但我必须在工作流程中手动构造 @odata.id 参数的 URL!

"@odata.id": "https://graph.microsoft.com/v1.0/users/{id}"
'/groups/{team-id}/owners/$ref':
    post:
      tags:
        - teams.team
      summary: Add a new owner to the team
      operationId: teams.AddOwner
      consumes:
        - application/json
      parameters:
        - name: team-id
          in: path
          required: true
          type: string
          description: Id of the MS team
          x-ms-summary: Team Id
          x-ms-visibility: important
        - name: body
          in: body
          required: true
          schema:
            type: object
            properties:
              '@odata.id':
                title: User Id
                type: string
                x-ms-summary: User Id
                x-ms-visibility: important
      responses:
        '204':
          description: Success
        default:
          $ref: '#/responses/error'
      x-ms-docs-operation-type: operation

编辑

我应该如何指定它来获取userId

如何正确指定 body 参数?

有没有关于如何做到这一点的文档\示例?

任何帮助将非常感激

提前致谢

皮特

标签: microsoft-graph-apiopenapipowerappspower-automateoffice365connectors

解决方案


我发现创建 PowerApps 自定义连接器的最简单方法之一是:

  1. 使用 Postman 制作工作请求

  2. 从空白构建自定义连接器

  3. 在自定义连接器“测试”区域进行测试

然后,如果需要,您可以下载 Swagger 文件。基本上,让 PowerApps 为您构建 Swagger 文件,而不是相反。

这是我喜欢使用的方法的 YouTube 视频。

https://m.youtube.com/watch?v=-wQljWG35zM


推荐阅读