使用Swashbuckle在Azure APIM中导入Azure Function应用的问题

问题描述

我们正在使用Swashbuckle(v 3.2.2)为Azure Function Apps(v3)生成Swagger(OpenAPI)文档。我们可以使用以下PowerShell脚本在APIM中导入Azure Function App:

$specificationUrl="https://myfunctionapp.azurewebsites.net/api/swagger/json?code=tdkaksas8393dkkfkr04kfkkfkf9933kk9=="

$apiContext = New-AzapimanagementContext -ResourceGroupName "MyResourceGroup"  -ServiceName "MyServiceName"
Import-AzapimanagementApi -Context $apiContext -SpecificationFormat "OpenApi" -SpecificationUrl $specificationUrl -Path apis

问题是未使用API​​M中的正确设置导入Azure函数应用。导入的操作的后端目标类型应为“ Azure资源”,但目标类型将设置为“ HTTP端点”。除此之外,我们甚至没有获得“ Azure资源”作为选项,而是显示了“ Azure Logic App”。当我们手动执行操作时,它将显示正确的后端目标,即“ Azure资源”。请参阅屏幕快照here了解详情。

我们正在使用Swashbuckle版本3.2.2 Swashbuckle,并引用此link来实施Swagger(OpenAPI)for Azure Functions。

解决方法

根据official document,以下是此操作的语法:

$context = New-AzApiManagementContext -ResourceGroupName "Api-Default-WestUS" -ServiceName "contoso"
Import-AzApiManagementApi -Context $context -SpecificationFormat OpenApi -SpecificationUrl https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v3.0/petstore.yaml -Path "petstore30"

ApiId                         : af3f57bab399455aa875d7050654e9d1
Name                          : Swagger Petstore
Description                   :
ServiceUrl                    : http://petstore.swagger.io/v1
Path                          : petstore30
ApiType                       : http
Protocols                     : {Https}
AuthorizationServerId         :
AuthorizationScope            :
OpenidProviderId              :
BearerTokenSendingMethod      : {}
SubscriptionKeyHeaderName     : Ocp-Apim-Subscription-Key
SubscriptionKeyQueryParamName : subscription-key
ApiRevision                   : 1
ApiVersion                    :
IsCurrent                     : True
IsOnline                      : False
SubscriptionRequired          :
ApiRevisionDescription        :
ApiVersionSetDescription      :
ApiVersionSetId               :
Id                            : /subscriptions/subid/resourceGroups/Api-Default-West-US/providers/Microsoft.ApiManagement/service/contoso/apis/af3f57bab399455aa875d7050654e9d1     
ResourceGroupName             : Api-Default-West-US
ServiceName                   : contoso

尝试跟随它。另外,请确保正确配置了Open API文件。