azure - 使用 Api 管理服务发布 Azure 函数应用程序 - 无法更新 Azure 中的 API(状态代码 : BadRequest))

标签 azure visual-studio azure-functions azure-api-management

我有一个使用本地运行的 API 管理服务的 Azure 函数应用程序。我使用 Visual Studio 2022 创建了它。但是当我尝试发布它时,一切看起来都很好,直到出现此错误。

========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
========== Publish: 1 succeeded, 0 failed, 0 skipped ==========
Waiting for function app to be ready...
Finished waiting for function app to be ready
Starting to update your API
Failed to update your API in Azure (Status code: BadRequest).

应用程序是在资源组下创建的,而不是在 api 管理服务下创建的。并生成分析文件。

Microsoft.WebTools.Shared.Exceptions.WebToolsException: Failed to update your API in Azure (Status code: BadRequest).

   at Microsoft.WebTools.Azure.Publish.ApiMApi.BaseApiMApiUpdater.EmitTerminatingError(String bucketName, String displayedErrorMessage, String loggedErrorMessage)
   at Microsoft.WebTools.Azure.Publish.ApiMApi.BaseApiMApiUpdater.<UpdateApiMApiInAzureAsync>d__10.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.WebTools.Azure.Publish.ApiMApi.FunctionAppApiMApiPublishHandler.FunctionApiMApiUpdater.<ImportSwaggerLinkToApiMAppAsync>d__8.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.WebTools.Azure.Publish.ApiMApi.FunctionAppApiMApiPublishHandler.FunctionApiMApiUpdater.<RunUpdateAsync>d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.WebTools.Azure.Publish.ApiMApi.BaseApiMApiUpdater.<RunUpdateWithTelemetryAsync>d__9.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.WebTools.Azure.Publish.ApiMApi.FunctionAppApiMApiPublishHandler.<UpdateApiMApiAsync>d__7.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.WebTools.Azure.Functions.PublishProviders.AzureFunctionProfileVisual.<FunctionsAfterPostPublishAsync>d__42.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Publish.Framework.Nexus.PublishProfilesServiceImpl.ServerProjectProfilesManager.
<RunPublishTaskAsync>d__56.MoveNext()

=================== 

我还尝试删除所有内容并重试,这次是在发布时创建 api 管理服务。应用程序已像以前一样创建,但 api 管理服务未创建。

最佳答案

如果您使用的是 Azure Function OpenAPI 模板,则需要确保每个 Function 在 OpenApiOperation 属性中具有唯一的 operationId。

默认情况下,新函数的操作 ID 设置为“运行”,将其更改为唯一值修复了发布时的错误请求

[OpenApiOperation(operationId: "UniqueOperationId", tags: new[] { "name" })]

您可以通过查看 Azure 门户中的日志来验证导致错误请求的原因

导航到资源组 --> 事件日志。从这里您应该能够看到创建 API 或更新 API 的失败尝试。

Resource Group Activity Log

选择失败的尝试并查看打开的面板中的 JSON 选项卡,底部附近应该是错误请求的原因

例如:

BadRequest OpenApi operationId

关于azure - 使用 Api 管理服务发布 Azure 函数应用程序 - 无法更新 Azure 中的 API(状态代码 : BadRequest)),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71021740/

相关文章:

azure - 使用 Azure API 管理模拟故障转移

visual-studio - VS.net 在一个解决方案中为多个项目设置版本

Azure Function V2 JWT - AD 身份验证

azure - 部署 Azure 函数应用程序应用程序设置的最佳方法

azure - 使用 Terraform 的同一 VNet 中的多个子网

.net - 如何使用预编译的 Azure Functions 解决“"can' t be invoked from Azure WebJobs SDK”错误?

Azure - 通过对等 VNet 路由流量

c# - 事件发生后表格会自行缩小

visual-studio - Visual Studio 解决方案和项目

Azure函数: how to bind query string parameters of http trigger function to SQL query of Cosmos DB