You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何解决Xcode Cloud中‘OpenAPIGenerator已禁用’错误?

解决Xcode Cloud中OpenAPIGenerator插件禁用的问题

核心解决步骤

1. 对齐依赖版本

swift-openapi-generator与swift-openapi-runtime、swift-openapi-urlsession的版本必须严格匹配,版本不兼容会直接导致插件运行异常。你当前配置中generator使用0.1.0,而runtime和urlsession使用1.0.0,版本差异是关键问题之一。

修改Package.swift中的依赖版本,统一为兼容的稳定版本:

dependencies: [
    .package(url: "https://github.com/apple/swift-openapi-generator", from: "1.0.0"),
    .package(url: "https://github.com/apple/swift-openapi-runtime", from: "1.0.0"),
    .package(url: "https://github.com/apple/swift-openapi-urlsession", from: "1.0.0"),
    //...
],

2. 允许Xcode Cloud执行插件

Xcode Cloud默认会限制未授权的插件运行,需要在构建工作流中开启权限:

  • 打开Xcode的项目设置,进入Package Dependencies,选中swift-openapi-generator,确认Enable Swift Packages Plugins设置为Yes。
  • 进入Xcode Cloud工作流配置(App Store Connect或Xcode的Report Navigator中),在Build阶段添加构建参数:
    • 参数名:OTHER_SWIFT_FLAGS
    • 参数值:-Xplugin-allow-all

3. 明确插件的文件路径配置

确保插件能正确找到OpenAPI规范文件,避免因路径缺失导致插件被禁用。修改OpenAPIClient Target的插件配置,指定输入输出路径:

.target(
    name: "OpenAPIClient",
    dependencies: [openAPIRuntime, openAPIURLSession],
    plugins: [
        .plugin(
            name: "OpenAPIGenerator",
            package: "swift-openapi-generator",
            options: [
                .configurationArgument(input: "Sources/OpenAPIClient/API.yaml"),
                .configurationArgument(output: "Sources/OpenAPIClient/Generated")
            ]
        )
    ]
),

4. 清理构建缓存

  • 本地执行swift package clean后重新构建,验证本地无问题。
  • 在Xcode Cloud工作流中开启Clean选项,确保每次构建使用全新环境,避免缓存引发的异常。

内容的提问来源于stack exchange,提问作者Levan Karanadze

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.25 15:42:41