1

我正在 Microsoft Flow/Logic Apps 中创建一个自定义连接器,它基于带有 Microsoft 扩展(x-ms-dynamic-schema 和 x-ms-dynamic-values)的 Swagger 文件。

我现在想获取一个对象数组。这些对象中的每一个都具有相同的 JSON 模式。使用 x-ms-dynamic-schema 扩展,可以声明逻辑应用程序/流设计器需要获取响应的 JSON 模式,以便您可以提供对象的属性。

我想要实现的是:

  • 我在我的连接器(“ListEntities”)上有一个操作,它获取我感兴趣的某个实体(= 对象类型)的对象数组。
  • 相同的操作会选取该实体类型的架构并显示响应的属性。

到目前为止我尝试了什么:

获取架构的操作:

    "/api/entitydefinitions/{type}": {
        "get": {
            "summary": "Get Entity Definition Schema",
            "description": "Gets the schema of an entity definition.",
            "operationId": "GetEntitySchemaByDefinition",
            "produces": [
                "application/json"
            ],
            "parameters": [
                {
                    "name": "type",
                    "type": "string",
                    "in": "path",
                    "description": "Select Entity you want to query",
                    "required": true,
                    "x-ms-summary": "Select Entity"
                }
            ],
            "responses": {
                "200": {
                    "description": "OK",
                    "schema": {
                        "type": "object"
                    }
                }
            }
        }
    }

获取实体列表的操作:

        "/api/entitydefinitions/{type-dynamic}/entities": {
        "get": {
            "summary": "List entities",
            "description": "Gets entities",
            "operationId": "ListEntitiesByDefinition",
            "parameters": [
                {
                    "name": "type-dynamic",
                    "type": "string",
                    "in": "path",
                    "description": "Select entity definition",
                    "required": true,
                    "x-ms-summary": "Entity Definition",
                    "x-ms-dynamic-values": {
                        "operationId": "ListEntityDefinitions",
                        "value-path": "name",
                        "value-title": "name",
                    }
                }
            ],
            "responses": {
                "200": {
                    "description": "OK",
                    "schema": {
                        "$ref": "#/definitions/ListEntitiesByDefinitionResponse"
                    }
                }
            }
        }
    }

上述响应的定义

    "ListEntitiesByDefinitionResponse": {
        "type": "object",
        "x-ms-dynamic-schema": {
            "operationId": "GetEntitySchemaByDefinition",
            "parameters": {
                "type": {
                    "parameter": "type-dynamic"
                }
            },
            "value-path": "items"
        }
    },

现在,我的输出示例:

[
{
    "id": 4541,
    "identifier": "123456789",
    "Name": "Name 1",
    "Description": "",
},
{
    "id": 4542,
    "identifier": "987654321",
    "Name": "FromPostman",
    "Description": "",
}
]

我的架构:

{
    "type": "array",
    "items": {
        "title": "Example",
        "type": "object",
        "properties": {
            "id": {
                "type": "integer",
                "x-ms-summary": "id"
            },
            "identifier": {
                "type": "string",
                "x-ms-summary": "identifier"
            },
            "Name": {
                "type": "string",
                "x-ms-summary": "Name"
            },
            "Description": {
                "type": "string",
                "x-ms-summary": "Description"
            }
        },
        "required": []
    }
}

问题是我的流程应用程序确实向我显示了设计模式下的属性:

在此处输入图像描述

但是,我希望插入一个循环(适用于每个循环)

流程本身也不起作用,只是因为它没有循环数组中的对象。

在此处输入图像描述

已经在这方面花费了太多时间并寻求您的帮助。

4

1 回答 1

0

Well.. you can go against Azure Flow design... or you may decide to work with it.

Let's try to replace this output:

[
    {
        "id": 4541,
        "identifier": "123456789",
        "Name": "Name 1",
        "Description": "",
    },
    {
        "id": 4542,
        "identifier": "987654321",
        "Name": "FromPostman",
        "Description": "",
    }
]

With this one:

{
     "values":
     [
        {
            "id": 4541,
            "identifier": "123456789",
            "Name": "Name 1",
            "Description": "",
        },
        {
            "id": 4542,
            "identifier": "987654321",
            "Name": "FromPostman",
            "Description": "",
        }
    ]
}

I know.. it is the "same" output but with different approach. This way, you may use the values field in a new apply to each action and manipulate it from there

BUT, I would've expected a loop (apply to each) to be inserted

As you say - if you want a chance to use that action - first suit your output format to Azure Flow requirements and carry on from there.

In short - try to change your schema definition to:

{
    "type": "object",
    "properties":
    {
         "values":
         {
             "type": "array"
             "items": "..."
         }
    }
}
于 2019-01-16T10:07:29.200 回答