2

我有一个托管应用程序,其中包含一个按钮,该按钮调用对底层自定义资源提供程序的 POST 请求。我已经使用订阅中的服务目录部署了这个托管应用程序,它可以工作。但是,当我将托管应用程序发布到 Azure 市场并提交时,它需要通过 github 原始 URI 托管和链接一个 swagger 定义。

我的 json 格式的招摇定义:

    {
    "swagger": "2.0",
    "info": {
        "title": "Azure Functions Open API Extension",
        "version": "2018-09-01-preview"
    },
    "host": "management.azure.com",
    "schemes": [
        "https"
    ],
    "security": [
        {}
    ],
    "securityDefinitions": {},    
    "paths": {
        "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CustomProviders/resourceProviders/{minirpname}/TransitionAccount": {
            "post": {
                "tags": [
                    "PostTransitionAccount"
                ],
                "operationId": "PostTransitionAccount",
                "produces": [
                    "application/json"
                ],
                "parameters": [
                    {
                        "in": "query",
                        "name": "api-version",
                        "description": "api-version is required. Valid versions are 2018-09-01-preview",
                        "required": true,
                        "type": "string"
                    },
                    {
                        "in": "path",
                        "name": "subscriptionId",
                        "description": "This is the Id of the subscription",
                        "required": true,
                        "type": "string"
                    },
                    {
                        "in": "path",
                        "name": "resourceGroupName",
                        "description": "This is the resource group name where the managed app is deployed",
                        "required": true,
                        "type": "string"
                    },
                    {
                        "in": "path",
                        "name": "minirpname",
                        "description": "This is the resource provider name",
                        "required": true,
                        "type": "string"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The OK response",
                        "schema": {}
                    },
                    "500": {
                        "description": "The InternalServerError response",
                        "schema": {}
                    }
                }
            }            
        }
    },
    "parameters": {
        "ApiVersionParameter": {
            "name": "api-version",
            "in": "query",
            "required": true,
            "type": "string",
            "description": "Client Api Version."
        }
    }
}

Marketplace 在发布时采用并验证此招摇定义,但是当我通过 Marketplace 部署托管应用程序并单击按钮时出现错误。

在此处输入图像描述

错误消息显示“请检查 swagger 验证是否为此操作定义了路线。”

这是我的自定义资源提供程序中的路径定义。

{
        "apiVersion": "[variables('customrpApiversion')]",
        "type": "Microsoft.CustomProviders/resourceProviders",
        "name": "[parameters('providerName')]",
        "location": "[parameters('location')]",
        "properties": {
            "actions": [
                {
                    "name": "transitionAccount",
                    "routingType": "Proxy",
                    "endpoint": "[concat('https://', variables('funcname'), '.azurewebsites.net/api/{requestPath}')]"
                }
            ],
            "resourceTypes": [
                {
                    "name": "accountType",
                    "routingType": "Proxy,Cache",
                    "endpoint": "[concat('https://', variables('funcname'), '.azurewebsites.net/api/{requestPath}')]"
                }
            ],
            "Validations" :[
                {
                    "ValidationType": "swagger",
                    "Specification": "https://raw.githubusercontent.com/cleardataeng/azure-shared-image-gallery-syncer/master/metadata/account-type-swagger.json"
                },
                {
                    "ValidationType": "swagger",
                    "Specification": "https://raw.githubusercontent.com/cleardataeng/azure-shared-image-gallery-syncer/master/metadata/transition-account-swagger.json"
                }
            ]
        },
        "dependsOn": [
            "[concat('Microsoft.Web/sites/',variables('funcname'))]"
        ],
        "resources": [
            {
                "type": "accountType",
                "name": "current",
                "apiVersion": "[variables('customrpApiversion')]",
                "location": "[parameters('location')]",
                "properties": {
                    "displayName": "[subscription().displayName]",
                    "tenantId": "[subscription().tenantId]",
                    "subscriptionId": "[subscription().subscriptionId]",
                    "accountType": "Evaluation",
                    "accountTypeStatus": "Pending"
                },
                "dependsOn": [
                    "[concat('Microsoft.CustomProviders/resourceProviders/',parameters('providerName'))]"
                ]
            }
        ]
    }

当我提供了在发布期间验证的 Swagger 定义文档时,为什么在单击 Marketplace 部署的应用程序中的转换帐户按钮时收到错误消息?

编辑:来自活动日志的错误如下。从活动日志中提取的错误如下。{"error":{"code":"MissingSwagger","message":"找不到请求的有效 swagger 定义 '/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/mrg-xxxxxx-managed- appli-20210526184240/providers/Microsoft.CustomProviders/resourceProviders/public/transitionAccount' 方法为 'POST'。请检查 swagger 验证是否有为此操作定义的路线。"}}

4

1 回答 1

0

该问题与招摇比较的大小写敏感性质有关。在使用案例更改更新 swagger 文件后,您需要重新创建自定义 rp。原因是我们在创建自定义提供程序资源期间缓存了 swagger 文件,并且不会知道发生了更新。

不过,目前,我们刚刚完成了一项部署,该部署使 swaggers 对于市场报价是可选的。请在不指定验证部分的情况下重试部署,这应该可以正常工作。

于 2021-06-02T23:06:51.770 回答