Azure API 管理导入 API 总是说:具有指定名称的 API 已存在

Azure API Management Import API always says: API with specified name already exists

我正在尝试将我拥有的 API 导入到 Azure API Management using swagger,应该相当简单,但我总是遇到相同的错误:

One or more fields contain incorrect values: API with specified name already exists

我还没有在 Azure API 管理中进行任何设置,非常令人沮丧。

更新

我正在使用 Swashbuckle (https://github.com/domaindrivendev/Swashbuckle) 将 Swagger 添加到我的 WebAPI 项目中。

正在生成 Swagger 2.0 文档。

这是 Swagger 文档的信息元素:

swagger: "2.0",
info: {
version: "v3",
title: "ShopZioAPIv3"
},

无论我将其更改为什么,我仍然总是得到:

One or more fields contain incorrect values: API with specified name already exists

如果您没有指定唯一的 API 前缀,就会出现该错误消息。

我知道您说过 API 中还没有任何设置,但是,如果您可以尝试在此字段中输入一些唯一值:

一个 API 管理服务实例旨在承载多个 API,因此前缀用于通过使用路径的第一部分来区分 API。

URL 的子域部分用于标识服务。例如

http://{servicename}.azure-api.net{/api-prefix}/path/segment?param=value

更新

根据提供的Swagger,问题出在多个操作对象具有相同的OperationId。这是无效的招摇。

通常 Swashbuckle 会在生成具有重复 ID 的操作之前失败。有一个 ResolveConflictingActions 方法允许您使用自己的代码来处理这些情况。在这种情况下,解析代码似乎没有做正确的事情。

Azure API 管理错误,"API with specified name already exists," 可能会产生误导,在这种情况下,它是不准确的。

, invalid Swagger can cause this issue. Although multiple operation objects with the same OperationId is invalid in Swagger 2.0, I think the core issue you are having is that Azure API Management does not yet support Swagger 2.0 中所述(截至 2015 年 12 月 1 日)。

Swashbuckle 5+ 仅生成 Swagger 2.0,因此使用它生成的一些(如果不是全部)定义将失败并出现此错误——即使是 http://editor.swagger.io 验证的格式良好的 Swagger 定义,它似乎也只支持昂首阔步 2.0.

Swashbuckle 4.2 支持生成 Swagger 1.2 定义。

此外,我能够采用我的 Swagger 2.0 定义(由 Swashbuckle 5 生成),并使用 Restlet Studio.

将其转换为 Swagger 1.2

我的情况是 Swagger 文件中的标题 {"info":{"title": "API-NAME",... 与所选 API 的名称不匹配(因为我们创建了多个测试 API)。

只需更改字符串值即可修复它。