问题描述
在 Azure API Management(APIM)中通过 Create from OpenAPI specification 导入 Swagger/OpenAPI 文件时,出现导入失败,返回类似以下报错:
One or more fields contain incorrect values:
- Parsing error(s): The key '成功响应' in 'responses' of components MUST match the regular expression '^[a-zA-Z0-9\.\-_]+$'. [#/components]
- Parsing error(s): The input OpenAPI file is not valid for the OpenAPI specification https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.1.1.md (schema https://github.com/OAI/OpenAPI-Specification/blob/master/schemas/v3.1/schema.yaml).
报错还指向 components.responses 下的部分字段。文档符合 OpenAPI 规范,是否就意味着 APIM 能导入并保留这些定义?

问题解答
根据 Microsoft Learn 的 OpenAPI 导入限制 (https://learn.microsoft.com/en-us/azure/api-management/api-management-api-import-restrictions),APIM 的版本支持范围如下: 
官方说明,API Management 并未完整支持 OpenAPI 3.1。
平台允许导入 3.1 文档,但大多数 3.1 特有结构不会被处理或强制执行,例如:
- updated JSON Schema
- callbacks
- links
- examples
- requestBodies
- headers 以及其他 components
导入时,不受支持的特性会被忽略、降级为与 3.0 等效的行为,或被移除。
因此,OpenAPI 3.1 应视为 import-compatible only,而不是 feature-compatible。
若要完整保真,官方建议使用 OpenAPI 2.0 或 3.0.x。
components.responses 在 OpenAPI 3.0.x 和 3.1.x 中都不被支持
官方在 OpenAPI version 3.x → Unsupported 中说明,下列字段包含在 OpenAPI 3.0.x 或 OpenAPI 3.1.x 中,但不受 APIM 支持。
Components 一行包括 responses、parameters、examples、requestBodies、headers、securitySchemes、links、callbacks。
导入大小限制
Size limitations 的规定是:
- 以内联方式导入 OpenAPI 规范时,最大为 4 MB。
- 通过 URL 提供到 APIM 服务可访问的位置时,受 Azure Resource Manager API 请求大小限制。
转换为 OpenAPI 3.0.3 后重新导入
更稳妥的处理方式是:将文档转换为 OpenAPI 3.0.x,建议使用 OpenAPI 3.0.3,并按 3.0.x 调整仅属于 3.1 的定义,然后重新导入。
转换后仍需检查 components.responses 等官方明确不支持的字段。
重新导入后,确认是否仍出现 Parsing error(s),以及需要保留的 API 操作定义是否还在。
参考资料
API import restrictions and known issues : https://learn.microsoft.com/en-us/azure/api-management/api-management-api-import-restrictions
API 导入限制和已知问题 : https://learn.microsoft.com/zh-cn/azure/api-management/api-management-api-import-restrictions